Skip to content

Commit f7e982c

Browse files
committed
add typehint_issubclass for var_type in style (#4946)
1 parent 0312c49 commit f7e982c

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

reflex/style.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
from __future__ import annotations
44

5-
from typing import Any, Literal, Type
5+
from typing import Any, Literal, Mapping, Type
66

77
from reflex import constants
88
from reflex.components.core.breakpoints import Breakpoints, breakpoints_values
99
from reflex.event import EventChain, EventHandler, EventSpec, run_script
1010
from reflex.utils import format
1111
from reflex.utils.exceptions import ReflexError
1212
from reflex.utils.imports import ImportVar
13-
from reflex.utils.types import get_origin
13+
from reflex.utils.types import typehint_issubclass
1414
from reflex.vars import VarData
1515
from reflex.vars.base import LiteralVar, Var
1616
from reflex.vars.function import FunctionVar
@@ -189,7 +189,7 @@ def update_out_dict(
189189
or (isinstance(value, list) and all(not isinstance(v, dict) for v in value))
190190
or (
191191
isinstance(value, ObjectVar)
192-
and not issubclass(get_origin(value._var_type) or value._var_type, dict)
192+
and not typehint_issubclass(value._var_type, Mapping)
193193
)
194194
else (key,)
195195
)

tests/units/test_style.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@
1111
from reflex.vars import VarData
1212
from reflex.vars.base import LiteralVar, Var
1313

14+
style_var = rx.Var.create({"height": "42px"})
15+
1416
test_style = [
1517
({"a": 1}, {"a": 1}),
18+
({"&": style_var}, {"&": {"height": "42px"}}),
19+
(
20+
{"&": rx.cond(style_var, style_var, {})},
21+
{"&": rx.cond(style_var, style_var, {})},
22+
),
1623
({"a": LiteralVar.create("abc")}, {"a": "abc"}),
1724
({"test_case": 1}, {"testCase": 1}),
1825
({"test_case": {"a": 1}}, {"test_case": {"a": 1}}),

0 commit comments

Comments
 (0)