Skip to content

Commit 8934bfb

Browse files
committed
fail on using rxcond on event handlers or event spec
1 parent 26f1a7b commit 8934bfb

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

reflex/event.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
Annotated,
1515
Any,
1616
Generic,
17+
NoReturn,
1718
Protocol,
1819
TypedDict,
1920
TypeVar,
@@ -1683,6 +1684,16 @@ def get_fn_signature(fn: Callable) -> inspect.Signature:
16831684
class EventVar(ObjectVar, python_types=(EventSpec, EventHandler)):
16841685
"""Base class for event vars."""
16851686

1687+
def bool(self) -> NoReturn:
1688+
"""Get the boolean value of the var.
1689+
1690+
Raises:
1691+
TypeError: EventVar cannot be converted to a boolean.
1692+
"""
1693+
raise TypeError(
1694+
f"Cannot convert {self._js_expr} of type {type(self).__name__} to bool."
1695+
)
1696+
16861697

16871698
@dataclasses.dataclass(
16881699
eq=False,
@@ -1759,6 +1770,16 @@ def no_args():
17591770
class EventChainVar(BuilderFunctionVar, python_types=EventChain):
17601771
"""Base class for event chain vars."""
17611772

1773+
def bool(self) -> NoReturn:
1774+
"""Get the boolean value of the var.
1775+
1776+
Raises:
1777+
TypeError: EventChainVar cannot be converted to a boolean.
1778+
"""
1779+
raise TypeError(
1780+
f"Cannot convert {self._js_expr} of type {type(self).__name__} to bool."
1781+
)
1782+
17621783

17631784
@dataclasses.dataclass(
17641785
eq=False,

0 commit comments

Comments
 (0)