ann_module3.py 448 B

123456789101112131415161718
  1. """
  2. Correct syntax for variable annotation that should fail at runtime
  3. in a certain manner. More examples are in test_grammar and test_parser.
  4. """
  5. def f_bad_ann():
  6. __annotations__[1] = 2
  7. class C_OK:
  8. def __init__(self, x: int) -> None:
  9. self.x: no_such_name = x # This one is OK as proposed by Guido
  10. class D_bad_ann:
  11. def __init__(self, x: int) -> None:
  12. sfel.y: int = 0
  13. def g_bad_ann():
  14. no_such_name.attr: int = 0