diff --git a/reflex/components/core/cond.py b/reflex/components/core/cond.py index 153953668..09f2ab213 100644 --- a/reflex/components/core/cond.py +++ b/reflex/components/core/cond.py @@ -2,13 +2,12 @@ from __future__ import annotations -from typing import Any, overload +from typing import Any, Union, overload from reflex.components.base.fragment import Fragment from reflex.components.component import BaseComponent, Component from reflex.style import LIGHT_COLOR_MODE, resolved_color_mode from reflex.utils import types -from reflex.utils.types import safe_issubclass from reflex.vars.base import LiteralVar, Var from reflex.vars.number import ternary_operation @@ -41,9 +40,8 @@ def cond(condition: Any, c1: Any, c2: Any = None) -> Component | Var: # If the first component is a component, create a Fragment if the second component is not set. if isinstance(c1, BaseComponent) or ( isinstance(c1, Var) - and ( - safe_issubclass(c1._var_type, BaseComponent) - or types.safe_typehint_issubclass(c1._var_type, list[BaseComponent]) + and types.safe_typehint_issubclass( + c1._var_type, Union[BaseComponent, list[BaseComponent]] ) ): c2 = c2 if c2 is not None else Fragment.create() diff --git a/reflex/components/core/match.py b/reflex/components/core/match.py index a9e7e10c5..1b32c3033 100644 --- a/reflex/components/core/match.py +++ b/reflex/components/core/match.py @@ -1,6 +1,6 @@ """rx.match.""" -from typing import Any, cast +from typing import Any, Union, cast from typing_extensions import Unpack @@ -49,9 +49,8 @@ def _validate_return_types(match_cases: tuple[CASE_TYPE[VAR_TYPE], ...]) -> None def is_component_or_component_var(obj: Any) -> bool: return types._isinstance(obj, BaseComponent) or ( isinstance(obj, Var) - and ( - types.safe_typehint_issubclass(obj._var_type, BaseComponent) - or types.safe_typehint_issubclass(obj._var_type, list[BaseComponent]) + and types.safe_typehint_issubclass( + obj._var_type, Union[list[BaseComponent], BaseComponent] ) )