MCPcopy
hub / github.com/reflex-dev/reflex / get_parent_state

Method get_parent_state

reflex/state.py:1015–1039  ·  view source on GitHub ↗

Get the parent state. Returns: The parent state. Raises: ValueError: If more than one parent state is found.

(cls)

Source from the content-addressed store, hash-verified

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

Callers 14

_register_base_stateMethod · 0.80
__get__Method · 0.80
test_get_parent_stateFunction · 0.80
test_mixin_stateFunction · 0.80
test_child_mixin_stateFunction · 0.80
test_bare_mixin_stateFunction · 0.80
__init_subclass__Method · 0.80
get_root_stateMethod · 0.80
get_full_nameMethod · 0.80
_collect_state_statsFunction · 0.80

Calls

no outgoing calls

Tested by 5

test_get_parent_stateFunction · 0.64
test_mixin_stateFunction · 0.64
test_child_mixin_stateFunction · 0.64
test_bare_mixin_stateFunction · 0.64