ann_module2.py 519 B

123456789101112131415161718192021222324252627282930313233343536
  1. """
  2. Some correct syntax for variable annotation here.
  3. More examples are in test_grammar and test_parser.
  4. """
  5. from typing import no_type_check, ClassVar
  6. i: int = 1
  7. j: int
  8. x: float = i/10
  9. def f():
  10. class C: ...
  11. return C()
  12. f().new_attr: object = object()
  13. class C:
  14. def __init__(self, x: int) -> None:
  15. self.x = x
  16. c = C(5)
  17. c.new_attr: int = 10
  18. __annotations__ = {}
  19. @no_type_check
  20. class NTC:
  21. def meth(self, param: complex) -> None:
  22. ...
  23. class CV:
  24. var: ClassVar['CV']
  25. CV.var = CV()