Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion reflex/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ def _handle_local_def(cls):
cls.__module__ = reflex.istate.dynamic.__name__

@classmethod
@functools.cache
def _get_type_hints(cls) -> dict[str, Any]:
"""Get the type hints for this class.

Expand Down Expand Up @@ -898,8 +899,9 @@ def _check_overridden_basevars(cls):
Raises:
ComputedVarShadowsBaseVarsError: When a computed var shadows a base var.
"""
hints = cls._get_type_hints()
for name, computed_var_ in cls._get_computed_vars():
if name in get_type_hints(cls):
if name in hints:
msg = f"The computed var name `{computed_var_._js_expr}` shadows a base var in {cls.__module__}.{cls.__name__}; use a different name instead"
raise ComputedVarShadowsBaseVarsError(msg)

Expand Down
11 changes: 4 additions & 7 deletions reflex/utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
StateVarTypes = (*PrimitiveTypes, Base, type(None))

if TYPE_CHECKING:
from reflex.state import BaseState
from reflex.vars.base import Var

VAR1 = TypeVar("VAR1", bound="Var")
Expand Down Expand Up @@ -902,12 +903,12 @@ def is_valid_var_type(type_: type) -> bool:
)


def is_backend_base_variable(name: str, cls: type) -> bool:
def is_backend_base_variable(name: str, cls: type[BaseState]) -> bool:
"""Check if this variable name correspond to a backend variable.

Args:
name: The name of the variable to check
cls: The class of the variable to check
cls: The class of the variable to check (must be a BaseState subclass)

Returns:
bool: The result of the check
Expand All @@ -924,11 +925,7 @@ def is_backend_base_variable(name: str, cls: type) -> bool:
if name.startswith(f"_{cls.__name__}__"):
return False

# Extract the namespace of the original module if defined (dynamic substates).
if callable(getattr(cls, "_get_type_hints", None)):
hints = cls._get_type_hints()
else:
hints = get_type_hints(cls)
hints = cls._get_type_hints()
if name in hints:
hint = get_origin(hints[name])
if hint == ClassVar:
Expand Down
Loading