Skip to content

Commit

Permalink
Handle bool cast for optional NumberVar (#4010)
Browse files Browse the repository at this point in the history
* Handle bool cast for optional NumberVar

If the _var_type is optional, then also check that the value is not None

* boolify the result of `and_operation`

* flip order to be more semantically pure

---------

Co-authored-by: Khaleel Al-Adhami <[email protected]>
  • Loading branch information
masenf and adhami3310 committed Sep 27, 2024
1 parent 299f842 commit ae0f3f8
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions reflex/vars/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from reflex.constants.base import Dirs
from reflex.utils.exceptions import PrimitiveUnserializableToJSON, VarTypeError
from reflex.utils.imports import ImportDict, ImportVar
from reflex.utils.types import is_optional

from .base import (
CustomVarOperationReturn,
Expand Down Expand Up @@ -524,6 +525,8 @@ def bool(self):
Returns:
The boolean value of the number.
"""
if is_optional(self._var_type):
return boolify((self != None) & (self != 0)) # noqa: E711
return self != 0

def _is_strict_float(self) -> bool:
Expand Down

0 comments on commit ae0f3f8

Please sign in to comment.