1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
"""Example module
This is a description
"""
from typing import ClassVar, Dict, Iterable, List, Union
max_rating = 10 # type: int
ratings = [0, 1, 2, 3, 4, 5] # type: List[int]
rating_names = {0: "zero", 1: "one"} # type: Dict[int, str]
def f(
start, # type: int
end, # type: int
): # type: (...) -> Iterable[int]
i = start
while i < end:
yield i
i += 1
mixed_list = [1, "two", 3] # type: List[Union[str, int]]
def f2(not_yet_a):
# type: (A) -> int
pass
class A:
is_an_a = True # type: ClassVar[bool]
def __init__(self):
self.instance_var = True # type: bool
"""This is an instance_var."""
global_a = A() # type: A
def f3(first_arg, **kwargs):
# type: (first_arg, Any) -> None
"""Annotation incorrectly leaves out `**`."""
class B:
"""Annotation keeps self/cls and shift all arg types"""
def __init__(self, a):
# type: (str) -> None
pass
def method(self, b):
# type: (list) -> None
pass
@classmethod
def class_method(cls, c):
# type: (int) -> None
pass
@staticmethod
def static_method(d):
# type: (float) -> Union[str,None]
pass
|