Add python generics playground

This commit is contained in:
pro100ton 2025-07-02 19:00:15 +03:00
parent 39f2f0fafc
commit b1e65d2c34

17
python_generics/main.py Normal file
View file

@ -0,0 +1,17 @@
from typing import TypeVar, Generic
MyType = TypeVar("MyType")
class Container(Generic[MyType]):
def __init__(self, value: MyType):
self.value = value
def get(self) -> MyType:
return self.value
print(type(Container("Hello").get()))
print(type(Container(12).get()))
print(type(Container([1,2]).get()))
print(Container)