diff --git a/python_generics/main.py b/python_generics/main.py new file mode 100644 index 0000000..3c01435 --- /dev/null +++ b/python_generics/main.py @@ -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)