LiveDemo
Код: Выделить всё
from typing import Generic, TypeVar
T = TypeVar("T")
class GenericClass(Generic[T]):
def __init__(self):
pass
def perform_validation(self):
T.validate()
class StaticObj:
@classmethod
def validate(cls):
print("Validate called for {StaticObj.name}")
mygeneric = GenericClass[StaticObj]()
mygeneric.perform_validation()
Код: Выделить всё
Program returned: 1
Traceback (most recent call last):
File "/app/output.s", line 21, in
mygeneric.perform_validation()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/app/output.s", line 10, in perform_validation
T.validate()
^^^^^^^^^^
AttributeError: 'typing.TypeVar' object has no attribute 'validate'
Подробнее здесь: https://stackoverflow.com/questions/798 ... -generic-t
Мобильная версия