Skip to content

Commit 2ffa698

Browse files
committed
improve match and cond checking
1 parent 0d746bf commit 2ffa698

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

reflex/components/core/cond.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
from __future__ import annotations
44

5-
from typing import Any, overload
5+
from typing import Any, Union, overload
66

77
from reflex.components.base.fragment import Fragment
88
from reflex.components.component import BaseComponent, Component
99
from reflex.style import LIGHT_COLOR_MODE, resolved_color_mode
1010
from reflex.utils import types
11-
from reflex.utils.types import safe_issubclass
1211
from reflex.vars.base import LiteralVar, Var
1312
from reflex.vars.number import ternary_operation
1413

@@ -41,9 +40,8 @@ def cond(condition: Any, c1: Any, c2: Any = None) -> Component | Var:
4140
# If the first component is a component, create a Fragment if the second component is not set.
4241
if isinstance(c1, BaseComponent) or (
4342
isinstance(c1, Var)
44-
and (
45-
safe_issubclass(c1._var_type, BaseComponent)
46-
or types.safe_typehint_issubclass(c1._var_type, list[BaseComponent])
43+
and types.safe_typehint_issubclass(
44+
c1._var_type, Union[BaseComponent, list[BaseComponent]]
4745
)
4846
):
4947
c2 = c2 if c2 is not None else Fragment.create()

reflex/components/core/match.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""rx.match."""
22

3-
from typing import Any, cast
3+
from typing import Any, Union, cast
44

55
from typing_extensions import Unpack
66

@@ -49,9 +49,8 @@ def _validate_return_types(match_cases: tuple[CASE_TYPE[VAR_TYPE], ...]) -> None
4949
def is_component_or_component_var(obj: Any) -> bool:
5050
return types._isinstance(obj, BaseComponent) or (
5151
isinstance(obj, Var)
52-
and (
53-
types.safe_typehint_issubclass(obj._var_type, BaseComponent)
54-
or types.safe_typehint_issubclass(obj._var_type, list[BaseComponent])
52+
and types.safe_typehint_issubclass(
53+
obj._var_type, Union[list[BaseComponent], BaseComponent]
5554
)
5655
)
5756

0 commit comments

Comments
 (0)