Skip to content

Commit

Permalink
add Classes in typing
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyguitar committed Aug 13, 2018
1 parent 3c211c9 commit 25c4959
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions docs/notes/python-typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ Basic types
# without initializing
x: int
# any type
y: Any
y = 1
y = "1"
# built-in
var_int: int = 1
var_str: str = "Hello Typing"
Expand Down Expand Up @@ -152,6 +157,32 @@ Functions
# lambda
f: Callable[[int], int] = lambda x: x * 2
Classes
--------
.. code-block:: python
from typing import ClassVar, Dict, List
class Foo:
x: int = 1 # instance variable. default = 1
y: ClassVar[str] = "class var" # class variable
def __init__(self) -> None:
self.i: List[int] = [0]
def foo(self, a: int, b: str) -> Dict[int, str]:
return {a: b}
foo = Foo()
foo.x = 123
print(foo.x)
print(foo.i)
print(Foo.y)
print(foo.foo(1, "abc"))
Generator
----------
Expand Down

0 comments on commit 25c4959

Please sign in to comment.