Skip to content

Commit a420b17

Browse files
authored
error when var is given something not a str (#5164)
1 parent 3bcf01d commit a420b17

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

pyi_hashes.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"reflex/components/radix/primitives/slider.pyi": "10196fb967c9cde3860a930a526b6c51",
5858
"reflex/components/radix/themes/__init__.pyi": "a15f9464ad99f248249ffa8e6deea4cf",
5959
"reflex/components/radix/themes/base.pyi": "a3c3c3b72fd3d8f1e38990e5c461b682",
60-
"reflex/components/radix/themes/color_mode.pyi": "435a51382eab6111aae1b26e79e9a473",
60+
"reflex/components/radix/themes/color_mode.pyi": "e18fe42952d10f5733f3baf4789c4bb5",
6161
"reflex/components/radix/themes/components/__init__.pyi": "87bb9ffff641928562da1622d2ca5993",
6262
"reflex/components/radix/themes/components/alert_dialog.pyi": "8e1dde62450296310a116ed066bd51e3",
6363
"reflex/components/radix/themes/components/aspect_ratio.pyi": "1845813a034adfc1f5db8e0f6ffc1118",

reflex/components/radix/themes/color_mode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,5 +205,5 @@ class ColorModeNamespace(Var):
205205
color_mode = color_mode_var_and_namespace = ColorModeNamespace(
206206
_js_expr=color_mode._js_expr,
207207
_var_type=color_mode._var_type,
208-
_var_data=color_mode._get_default_value(),
208+
_var_data=color_mode._get_all_var_data(),
209209
)

reflex/vars/base.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,21 @@ class ToVarOperation(ToOperation, cls):
483483
_var_subclasses.append(VarSubclassEntry(cls, ToVarOperation, python_types))
484484

485485
def __post_init__(self):
486-
"""Post-initialize the var."""
486+
"""Post-initialize the var.
487+
488+
Raises:
489+
TypeError: If _js_expr is not a string.
490+
"""
491+
if not isinstance(self._js_expr, str):
492+
raise TypeError(
493+
f"Expected _js_expr to be a string, got value {self._js_expr!r} of type {type(self._js_expr).__name__}"
494+
)
495+
496+
if self._var_data is not None and not isinstance(self._var_data, VarData):
497+
raise TypeError(
498+
f"Expected _var_data to be a VarData, got value {self._var_data!r} of type {type(self._var_data).__name__}"
499+
)
500+
487501
# Decode any inline Var markup and apply it to the instance
488502
_var_data, _js_expr = _decode_var_immutable(self._js_expr)
489503

0 commit comments

Comments
 (0)