diff --git a/reflex/components/component.py b/reflex/components/component.py index f9e0ceaab..e1a398786 100644 --- a/reflex/components/component.py +++ b/reflex/components/component.py @@ -191,7 +191,7 @@ def satisfies_type_hint(obj: Any, type_hint: Any) -> bool: Returns: Whether the object satisfies the type hint. """ - return types._isinstance(obj, type_hint, nested=0) + return types._isinstance(obj, type_hint, nested=1) class Component(BaseComponent, ABC): diff --git a/reflex/utils/types.py b/reflex/utils/types.py index 1dd43f500..6f19bb9ca 100644 --- a/reflex/utils/types.py +++ b/reflex/utils/types.py @@ -567,9 +567,6 @@ def _isinstance(obj: Any, cls: GenericType, nested: int = 0) -> bool: from reflex.vars import LiteralVar, Var - if cls and is_union(cls): - return any(_isinstance(obj, arg, nested=nested) for arg in get_args(cls)) - if cls is Var: return isinstance(obj, Var) if isinstance(obj, LiteralVar): @@ -580,6 +577,9 @@ def _isinstance(obj: Any, cls: GenericType, nested: int = 0) -> bool: if cls is None or cls is type(None): return obj is None + if cls and is_union(cls): + return any(_isinstance(obj, arg, nested=nested) for arg in get_args(cls)) + if is_literal(cls): return obj in get_args(cls)