'python __init_subclass__ not called for all subclasses

I have an issue with __init_subclass__ which is not called for all subclasses.

Here is my parent class:

@dataclass
class State:
    _STATE_CLASSES: ClassVar[Dict[str, Type]] = {}

    def __init_subclass__(cls, **kwargs):
        State._STATE_CLASSES[cls.__name__] = cls

Then I have multiple classes that extend this one at one or two levels of depth. Some are detected, some others no. And I can't figure out why. What is the rational behind this?

Example: Pass is detected while Fail and Choice are not

# detected
@dataclass
class Pass(State):
    type: str = States.Pass
    parameters: dict = None
    result_path: str = None
    result: str = None
    next: str = None
    end: bool = None

# not detected
@dataclass
class Choice(State):
    type: str = States.Choice
    choices: List[ChoiceRule] = dataclasses.field(default_factory=list)
    default: str = None

@dataclass
class Fail(State):
    type: str = States.Fail
    cause: str = None
    error: str = None

And if there is a cleaner way to get this _STATE_CLASSES dict of classes, please let me know.

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source