Skip to content

Commit

Permalink
improve match and cond checking
Browse files Browse the repository at this point in the history
  • Loading branch information
adhami3310 committed Jan 23, 2025
1 parent 0d746bf commit 2ffa698
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
8 changes: 3 additions & 5 deletions reflex/components/core/cond.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down
7 changes: 3 additions & 4 deletions reflex/components/core/match.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""rx.match."""

from typing import Any, cast
from typing import Any, Union, cast

from typing_extensions import Unpack

Expand Down Expand Up @@ -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]
)
)

Expand Down

0 comments on commit 2ffa698

Please sign in to comment.