ann_module.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """
  2. The module for testing variable annotations.
  3. Empty lines above are for good reason (testing for correct line numbers)
  4. """
  5. from typing import Optional
  6. from functools import wraps
  7. __annotations__[1] = 2
  8. class C:
  9. x = 5; y: Optional['C'] = None
  10. from typing import Tuple
  11. x: int = 5; y: str = x; f: Tuple[int, int]
  12. class M(type):
  13. __annotations__['123'] = 123
  14. o: type = object
  15. (pars): bool = True
  16. class D(C):
  17. j: str = 'hi'; k: str= 'bye'
  18. from types import new_class
  19. h_class = new_class('H', (C,))
  20. j_class = new_class('J')
  21. class F():
  22. z: int = 5
  23. def __init__(self, x):
  24. pass
  25. class Y(F):
  26. def __init__(self):
  27. super(F, self).__init__(123)
  28. class Meta(type):
  29. def __new__(meta, name, bases, namespace):
  30. return super().__new__(meta, name, bases, namespace)
  31. class S(metaclass = Meta):
  32. x: str = 'something'
  33. y: str = 'something else'
  34. def foo(x: int = 10):
  35. def bar(y: List[str]):
  36. x: str = 'yes'
  37. bar()
  38. def dec(func):
  39. @wraps(func)
  40. def wrapper(*args, **kwargs):
  41. return func(*args, **kwargs)
  42. return wrapper
  43. u: int | float