suggest bool() for wrong values (#3975)

This commit is contained in:
Khaleel Al-Adhami 2024-09-23 18:13:55 -07:00 committed by GitHub
parent 47c9938d95
commit a5ad5203df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -448,8 +448,16 @@ class Component(BaseComponent, ABC):
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: