Skip to content

Commit ca7f663

Browse files
authored
make event statically type-able (#5135)
1 parent 1898a1c commit ca7f663

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

reflex/event.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,7 +1960,9 @@ def __call__(self, *args: Var) -> Any:
19601960
)
19611961

19621962
EventType = TypeAliasType(
1963-
"EventType", ItemOrList[IndividualEventType[Unpack[ARGS]]], type_params=(ARGS,)
1963+
"EventType",
1964+
ItemOrList[LAMBDA_OR_STATE[Unpack[ARGS]] | BASIC_EVENT_TYPES],
1965+
type_params=(ARGS,),
19641966
)
19651967

19661968

@@ -1972,7 +1974,7 @@ def __call__(self, *args: Var) -> Any:
19721974
BASE_STATE = TypeVar("BASE_STATE")
19731975

19741976

1975-
class EventNamespace(types.SimpleNamespace):
1977+
class EventNamespace:
19761978
"""A namespace for event related classes."""
19771979

19781980
Event = Event
@@ -1988,23 +1990,22 @@ class EventNamespace(types.SimpleNamespace):
19881990
EventCallback = EventCallback
19891991

19901992
@overload
1991-
@staticmethod
1992-
def __call__(
1993-
func: None = None, *, background: bool | None = None
1993+
def __new__(
1994+
cls, func: None = None, *, background: bool | None = None
19941995
) -> Callable[
19951996
[Callable[[BASE_STATE, Unpack[P]], Any]], EventCallback[Unpack[P]] # pyright: ignore [reportInvalidTypeVarUse]
19961997
]: ...
19971998

19981999
@overload
1999-
@staticmethod
2000-
def __call__(
2000+
def __new__(
2001+
cls,
20012002
func: Callable[[BASE_STATE, Unpack[P]], Any],
20022003
*,
20032004
background: bool | None = None,
20042005
) -> EventCallback[Unpack[P]]: ...
20052006

2006-
@staticmethod
2007-
def __call__(
2007+
def __new__(
2008+
cls,
20082009
func: Callable[[BASE_STATE, Unpack[P]], Any] | None = None,
20092010
*,
20102011
background: bool | None = None,
@@ -2076,4 +2077,4 @@ def wrapper(
20762077
run_script = staticmethod(run_script)
20772078

20782079

2079-
event = EventNamespace()
2080+
event = EventNamespace

0 commit comments

Comments
 (0)