Add python generics playground
This commit is contained in:
parent
39f2f0fafc
commit
b1e65d2c34
1 changed files with 17 additions and 0 deletions
17
python_generics/main.py
Normal file
17
python_generics/main.py
Normal 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)
|
||||
Loading…
Reference in a new issue