mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-19 19:10:17 +00:00
22 lines
387 B
Python
22 lines
387 B
Python
|
|
class Test[T]:
|
|
def __init__(self, value: T):
|
|
self.value = value
|
|
|
|
def get_value(self) -> T:
|
|
return self.value
|
|
|
|
|
|
def add[T: int|str|float](a: T, b: T) -> T:
|
|
return a + b # type: ignore
|
|
|
|
res = add(1, 2)
|
|
assert res == 3
|
|
|
|
test = Test(1)
|
|
assert test.get_value() == 1
|
|
|
|
# test multiple
|
|
class Test2[T: int, U]: pass
|
|
class Test3[T: int | str, U: float, R: list]: pass
|