Skip to content

Commit 5b36147

Browse files
committed
reflex_core.event: provide BaseState as a namespace property
Avoid other weird circular import issues that occur when the `sys.modules` record for the module is not actually the module namespace.
1 parent 3d60731 commit 5b36147

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

  • packages/reflex-core/src/reflex_core

packages/reflex-core/src/reflex_core/event.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2812,13 +2812,22 @@ def wrapper(
28122812
run_script = staticmethod(run_script)
28132813
__file__ = __file__
28142814

2815+
@property
2816+
def BaseState(self) -> "type[BaseState]": # noqa: N802
2817+
"""Get the BaseState class.
2818+
2819+
A reference to BaseState is needed for doc generation when resolving
2820+
type hints, so add it to the namespace late to avoid circular import
2821+
issues.
2822+
2823+
Returns:
2824+
The BaseState class.
2825+
"""
2826+
from reflex.state import BaseState
2827+
2828+
return BaseState
2829+
28152830

28162831
event = EventNamespace
28172832
event.event = event # pyright: ignore[reportAttributeAccessIssue]
28182833
sys.modules[__name__] = event # pyright: ignore[reportArgumentType]
2819-
2820-
# A reference to BaseState is needed for doc generation when resolving type
2821-
# hints, so add it to the namespace late to avoid circular import issues.
2822-
from reflex.state import BaseState # noqa: E402
2823-
2824-
event.BaseState = BaseState # pyright: ignore[reportAttributeAccessIssue]

0 commit comments

Comments
 (0)