File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -36,3 +36,5 @@ Type checking can be done using [mypy](http://mypy-lang.org/index.html).
3636 false positive.
37371 . ` numpy_typing.py ` : illustration of a script using both numpy and
3838 matplotlib with type hints.
39+ 1 . ` classes.py ` : illustration of using type hints with a user-defined
40+ class.
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+
3+ from typing import Any
4+
5+
6+ class MyClass :
7+
8+ def __init__ (self , data : Any ) -> None :
9+ self .data = data
10+
11+ @property
12+ def data (self ) -> int :
13+ return self .data
14+
15+ @data .setter
16+ def data (self , value : Any ) -> None :
17+ self .data = int (value )
18+
19+ def __repr__ (self ) -> str :
20+ return f'data: { self .data } '
21+
22+
23+ def print_data (data : MyClass ) -> None :
24+ print (data )
25+
26+
27+ if __name__ == '__main__' :
28+ data = MyClass ('25' )
29+ print_data (data )
You can’t perform that action at this time.
0 commit comments