960_pep695_py312.py 387 B

123456789101112131415161718192021
  1. class Test[T]:
  2. def __init__(self, value: T):
  3. self.value = value
  4. def get_value(self) -> T:
  5. return self.value
  6. def add[T: int|str|float](a: T, b: T) -> T:
  7. return a + b # type: ignore
  8. res = add(1, 2)
  9. assert res == 3
  10. test = Test(1)
  11. assert test.get_value() == 1
  12. # test multiple
  13. class Test2[T: int, U]: pass
  14. class Test3[T: int | str, U: float, R: list]: pass