Код: Выделить всё
from typing import Generic, TypeVar
class X:
pass
class Y(X):
pass
T = TypeVar("T", bound=X)
class A(Generic[T]):
def __init__(self, param: T):
self.param = param
class B(A[T]):
pass
S = TypeVar("S", bound=A[X])
def foo(bar: S) -> S:
return bar
foo(B(Y())) # Type "B[Y]" cannot be assigned to type "A[X]"
Подробнее здесь: https://stackoverflow.com/questions/713 ... parameters
Мобильная версия