Quick Python `typing` question: I have an abstrac...
# random
r
Quick Python
typing
question: I have an abstract base class
Animal
with a class property
siblings
initialised to an empty
list
Copy code
class Animal(metaclass=abc.ABCMeta):
    siblings = []
and I want to use
typing
to infer the element type of
siblings
when sub-classed. Non-working example, but something like:
Copy code
T = TypeVar('T', bound='Animal')

class Animal(Generic[T], metaclass=abc.ABCMeta):
    siblings: List[T] = []

class Cat(Animal[Cat]):    # class X(Y[X]) paradigm seems weird
    pass

class Dog(Animal[Dog]):
    pass

Cat.siblings    # expect type of List[Cat]
Dog.siblings    # expect type of List[Dog]