Get the parent state. Returns: The parent state. Raises: ValueError: If more than one parent state is found.
(cls)
| 1013 | @classmethod |
| 1014 | @functools.lru_cache |
| 1015 | def get_parent_state(cls) -> type[BaseState] | None: |
| 1016 | """Get the parent state. |
| 1017 | |
| 1018 | Returns: |
| 1019 | The parent state. |
| 1020 | |
| 1021 | Raises: |
| 1022 | ValueError: If more than one parent state is found. |
| 1023 | """ |
| 1024 | parent_states = [ |
| 1025 | base |
| 1026 | for base in cls.__bases__ |
| 1027 | if issubclass(base, BaseState) and base is not BaseState and not base._mixin |
| 1028 | ] |
| 1029 | if len(parent_states) >= 2: |
| 1030 | msg = f"Only one parent state of is allowed. Found {parent_states} parents of {cls}." |
| 1031 | raise ValueError(msg) |
| 1032 | # The first non-mixin state in the mro is our parent. |
| 1033 | for base in cls.mro()[1:]: |
| 1034 | if not issubclass(base, BaseState) or base._mixin: |
| 1035 | continue |
| 1036 | if base is BaseState: |
| 1037 | break |
| 1038 | return base |
| 1039 | return None # No known parent |
| 1040 | |
| 1041 | @classmethod |
| 1042 | @functools.lru_cache |
no outgoing calls