From 66577e681cbb4815c40120e4269f61d6ad333994 Mon Sep 17 00:00:00 2001 From: Khaleel Al-Adhami Date: Tue, 2 Sep 2025 11:14:03 -0700 Subject: [PATCH 1/2] fix issubclass calls --- reflex/components/component.py | 45 ---------------------------------- reflex/utils/types.py | 4 +++ 2 files changed, 4 insertions(+), 45 deletions(-) diff --git a/reflex/components/component.py b/reflex/components/component.py index 2d5d89da525..4d7021f1c48 100644 --- a/reflex/components/component.py +++ b/reflex/components/component.py @@ -1021,48 +1021,12 @@ def get_initial_props(cls) -> set[str]: """ return set() - @classmethod - def _are_fields_known(cls) -> bool: - """Check if all fields are known at compile time. True for most components. - - Returns: - Whether all fields are known at compile time. - """ - return True - - @classmethod - @functools.cache - def _get_component_prop_names(cls) -> set[str]: - """Get the names of the component props. NOTE: This assumes all fields are known. - - Returns: - The names of the component props. - """ - return { - name - for name in cls.get_fields() - if name in cls.get_props() - and isinstance( - field_type := types.value_inside_optional( - types.get_field_type(cls, name) - ), - type, - ) - and issubclass(field_type, Component) - } - def _get_components_in_props(self) -> Sequence[BaseComponent]: """Get the components in the props. Returns: The components in the props """ - if self._are_fields_known(): - return [ - component - for name in self._get_component_prop_names() - for component in _components_from(getattr(self, name)) - ] return [ component for prop in self.get_props() @@ -2060,15 +2024,6 @@ def get_args_spec(key: str) -> types.ArgsSpec | Sequence[types.ArgsSpec]: self.props[camel_cased_key] = value setattr(self, camel_cased_key, value) - @classmethod - def _are_fields_known(cls) -> bool: - """Check if the fields are known. - - Returns: - Whether the fields are known. - """ - return False - def __eq__(self, other: Any) -> bool: """Check if the component is equal to another. diff --git a/reflex/utils/types.py b/reflex/utils/types.py index 93e253b22c5..e62e9902eb0 100644 --- a/reflex/utils/types.py +++ b/reflex/utils/types.py @@ -857,6 +857,10 @@ def is_valid_var_type(type_: type) -> bool: if is_union(type_): return all(is_valid_var_type(arg) for arg in get_args(type_)) + if is_literal(type_): + types = {type(value) for value in get_args(type_)} + return all(is_valid_var_type(type_) for type_ in types) + type_ = origin if (origin := get_origin(type_)) is not None else type_ return ( From 08885dc9cf7301df997d22919e612e94546bc2c3 Mon Sep 17 00:00:00 2001 From: Khaleel Al-Adhami Date: Tue, 2 Sep 2025 11:53:54 -0700 Subject: [PATCH 2/2] cached property question mark --- reflex/components/component.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/reflex/components/component.py b/reflex/components/component.py index 4d7021f1c48..0bae03ca7ca 100644 --- a/reflex/components/component.py +++ b/reflex/components/component.py @@ -1021,12 +1021,8 @@ def get_initial_props(cls) -> set[str]: """ return set() - def _get_components_in_props(self) -> Sequence[BaseComponent]: - """Get the components in the props. - - Returns: - The components in the props - """ + @functools.cached_property + def _get_component_prop_property(self) -> Sequence[BaseComponent]: return [ component for prop in self.get_props() @@ -1035,6 +1031,14 @@ def _get_components_in_props(self) -> Sequence[BaseComponent]: for component in _components_from(value) ] + def _get_components_in_props(self) -> Sequence[BaseComponent]: + """Get the components in the props. + + Returns: + The components in the props + """ + return self._get_component_prop_property + @classmethod def _validate_children(cls, children: tuple | list): from reflex.utils.exceptions import ChildrenTypeError