Skip to content

Commit

Permalink
suggest bool() for wrong values (#3975)
Browse files Browse the repository at this point in the history
  • Loading branch information
adhami3310 authored Sep 24, 2024
1 parent 47c9938 commit a5ad520
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions reflex/components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,16 @@ def __init__(self, *args, **kwargs):
and not types._issubclass(passed_type, expected_type, value)
):
value_name = value._js_expr if isinstance(value, Var) else value

additional_info = (
" You can call `.bool()` on the value to convert it to a boolean."
if expected_type is bool and isinstance(value, Var)
else ""
)

raise TypeError(
f"Invalid var passed for prop {type(self).__name__}.{key}, expected type {expected_type}, got value {value_name} of type {passed_type}."
+ additional_info
)
# Check if the key is an event trigger.
if key in component_specific_triggers:
Expand Down

0 comments on commit a5ad520

Please sign in to comment.