Skip to content

Commit

Permalink
add typehint_issubclass for var_type in style (#4946)
Browse files Browse the repository at this point in the history
  • Loading branch information
adhami3310 authored Mar 11, 2025
1 parent 5c8104f commit 32b10f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions reflex/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

from __future__ import annotations

from typing import Any, Literal, Type
from typing import Any, Literal, Mapping, Type

from reflex import constants
from reflex.components.core.breakpoints import Breakpoints, breakpoints_values
from reflex.event import EventChain, EventHandler, EventSpec, run_script
from reflex.utils import format
from reflex.utils.exceptions import ReflexError
from reflex.utils.imports import ImportVar
from reflex.utils.types import get_origin
from reflex.utils.types import typehint_issubclass
from reflex.vars import VarData
from reflex.vars.base import LiteralVar, Var
from reflex.vars.function import FunctionVar
Expand Down Expand Up @@ -189,7 +189,7 @@ def update_out_dict(
or (isinstance(value, list) and all(not isinstance(v, dict) for v in value))
or (
isinstance(value, ObjectVar)
and not issubclass(get_origin(value._var_type) or value._var_type, dict)
and not typehint_issubclass(value._var_type, Mapping)
)
else (key,)
)
Expand Down
7 changes: 7 additions & 0 deletions tests/units/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@
from reflex.vars import VarData
from reflex.vars.base import LiteralVar, Var

style_var = rx.Var.create({"height": "42px"})

test_style = [
({"a": 1}, {"a": 1}),
({"&": style_var}, {"&": {"height": "42px"}}),
(
{"&": rx.cond(style_var, style_var, {})},
{"&": rx.cond(style_var, style_var, {})},
),
({"a": LiteralVar.create("abc")}, {"a": "abc"}),
({"test_case": 1}, {"testCase": 1}),
({"test_case": {"a": 1}}, {"test_case": {"a": 1}}),
Expand Down

0 comments on commit 32b10f2

Please sign in to comment.