Skip to content
Merged
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
61 changes: 10 additions & 51 deletions reflex/components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,48 +1021,8 @@ 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))
]
@functools.cached_property
def _get_component_prop_property(self) -> Sequence[BaseComponent]:
return [
component
for prop in self.get_props()
Expand All @@ -1071,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
Expand Down Expand Up @@ -2060,15 +2028,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.

Expand Down
4 changes: 4 additions & 0 deletions reflex/utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_)}
Comment thread
adhami3310 marked this conversation as resolved.
return all(is_valid_var_type(type_) for type_ in types)
Comment thread
adhami3310 marked this conversation as resolved.

type_ = origin if (origin := get_origin(type_)) is not None else type_

return (
Expand Down
Loading