Например,
Код: Выделить всё
from typing import TypeVar, Type, Generic
T = TypeVar('T')
class Test(Generic[T]):
def hello(self):
my_type = T # this is wrong!
print( "I am {0}".format(my_type) )
Test[int]().hello() # should print "I am int"
Код: Выделить всё
print( str( Test[int].__args__ ) )
Код: Выделить всё
my_type = self.__class__.__args__ # this is also wrong (None)
Спасибо
Подробнее здесь: https://stackoverflow.com/questions/577 ... n-instance
Мобильная версия