File tree Expand file tree Collapse file tree 2 files changed +7
-8
lines changed
Expand file tree Collapse file tree 2 files changed +7
-8
lines changed Original file line number Diff line number Diff line change @@ -796,6 +796,7 @@ def _handle_local_def(cls):
796796 cls .__module__ = reflex .istate .dynamic .__name__
797797
798798 @classmethod
799+ @functools .cache
799800 def _get_type_hints (cls ) -> dict [str , Any ]:
800801 """Get the type hints for this class.
801802
@@ -898,8 +899,9 @@ def _check_overridden_basevars(cls):
898899 Raises:
899900 ComputedVarShadowsBaseVarsError: When a computed var shadows a base var.
900901 """
902+ hints = cls ._get_type_hints ()
901903 for name , computed_var_ in cls ._get_computed_vars ():
902- if name in get_type_hints ( cls ) :
904+ if name in hints :
903905 msg = f"The computed var name `{ computed_var_ ._js_expr } ` shadows a base var in { cls .__module__ } .{ cls .__name__ } ; use a different name instead"
904906 raise ComputedVarShadowsBaseVarsError (msg )
905907
Original file line number Diff line number Diff line change 5757StateVarTypes = (* PrimitiveTypes , Base , type (None ))
5858
5959if TYPE_CHECKING :
60+ from reflex .state import BaseState
6061 from reflex .vars .base import Var
6162
6263VAR1 = TypeVar ("VAR1" , bound = "Var" )
@@ -902,12 +903,12 @@ def is_valid_var_type(type_: type) -> bool:
902903 )
903904
904905
905- def is_backend_base_variable (name : str , cls : type ) -> bool :
906+ def is_backend_base_variable (name : str , cls : type [ BaseState ] ) -> bool :
906907 """Check if this variable name correspond to a backend variable.
907908
908909 Args:
909910 name: The name of the variable to check
910- cls: The class of the variable to check
911+ cls: The class of the variable to check (must be a BaseState subclass)
911912
912913 Returns:
913914 bool: The result of the check
@@ -924,11 +925,7 @@ def is_backend_base_variable(name: str, cls: type) -> bool:
924925 if name .startswith (f"_{ cls .__name__ } __" ):
925926 return False
926927
927- # Extract the namespace of the original module if defined (dynamic substates).
928- if callable (getattr (cls , "_get_type_hints" , None )):
929- hints = cls ._get_type_hints ()
930- else :
931- hints = get_type_hints (cls )
928+ hints = cls ._get_type_hints ()
932929 if name in hints :
933930 hint = get_origin (hints [name ])
934931 if hint == ClassVar :
You can’t perform that action at this time.
0 commit comments