Subclass of Generic fails with AttributeError: object has no attribute '__parameters__' - using Generic when superclass does forward __init_subclass__
19:52 30 Nov 2025

I have a setup like the following

from typing import Generic, TypeVar
T = TypeVar("T")

class ThirdParty:
   def __init_subclass__(cls):
      ...  # does not call super()
  
class Mine(ThirdParty, Generic[T]):
   ...

class Sub(Mine[int]):
   ...

However it fails with the following

Traceback (most recent call last):
  File "", line 1, in 
  File "/home/dsperber/master/repos/SYMPOL/rllib_port/core/stated_flax_model.py", line 27, in 
    class Sub(Mine[ModelType]):
  File "/home/xxxx/miniconda3/envs/python3.10/lib/python3.10/typing.py", line 309, in inner
    return cached(*args, **kwds)
  File "/home/xxxx/miniconda3/envs/python3.10/lib/python3.10/typing.py", line 1342, in __class_getitem__
    if any(isinstance(t, ParamSpec) for t in cls.__parameters__):

AttributeError: type object 'Mine' has no attribute '__parameters__'

I figured out that this is because ThirdParty has a __init_subclass__ function but it does not call super().__init_subclass__, hence Generic.__init_subclass__ is not called. Is there a way around this? Adding __init_subclass__ to Mine does not work or the following fails as well:

def __init_subclass__(cls):
   Generic.__init_subclass__(cls)
   # TypeError: Generic.__init_subclass__() takes 1 positional argument but 2 were given
python generics python-typing subclass attributeerror