Skip to content

Commit 60c96e8

Browse files
committed
reflex.event: revert future annotation changes
Go back to string-based annotations, to unbreak reflex-web
1 parent 23d9a09 commit 60c96e8

1 file changed

Lines changed: 35 additions & 37 deletions

File tree

reflex/event.py

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Define event classes to connect the frontend and backend."""
22

3-
from __future__ import annotations
4-
53
import dataclasses
64
import inspect
75
import sys
@@ -101,7 +99,7 @@ def substate_token(self) -> str:
10199
UPLOAD_FILES_CLIENT_HANDLER = "uploadFiles"
102100

103101

104-
def _handler_name(handler: EventHandler) -> str:
102+
def _handler_name(handler: "EventHandler") -> str:
105103
"""Get a stable fully qualified handler name for errors.
106104
107105
Args:
@@ -115,7 +113,7 @@ def _handler_name(handler: EventHandler) -> str:
115113
return handler.fn.__qualname__
116114

117115

118-
def resolve_upload_handler_param(handler: EventHandler) -> tuple[str, Any]:
116+
def resolve_upload_handler_param(handler: "EventHandler") -> tuple[str, Any]:
119117
"""Validate and resolve the UploadFile list parameter for a handler.
120118
121119
Args:
@@ -154,7 +152,7 @@ def resolve_upload_handler_param(handler: EventHandler) -> tuple[str, Any]:
154152
raise UploadValueError(msg)
155153

156154

157-
def resolve_upload_chunk_handler_param(handler: EventHandler) -> tuple[str, type]:
155+
def resolve_upload_chunk_handler_param(handler: "EventHandler") -> tuple[str, type]:
158156
"""Validate and resolve the UploadChunkIterator parameter for a handler.
159157
160158
Args:
@@ -336,7 +334,7 @@ def is_background(self) -> bool:
336334
"""
337335
return getattr(self.fn, BACKGROUND_TASK_MARKER, False)
338336

339-
def __call__(self, *args: Any, **kwargs: Any) -> EventSpec:
337+
def __call__(self, *args: Any, **kwargs: Any) -> "EventSpec":
340338
"""Pass arguments to the handler to get an event spec.
341339
342340
This method configures event handlers that take in arguments.
@@ -446,7 +444,7 @@ def __init__(
446444
object.__setattr__(self, "client_handler_name", client_handler_name)
447445
object.__setattr__(self, "args", args or ())
448446

449-
def with_args(self, args: tuple[tuple[Var, Var], ...]) -> EventSpec:
447+
def with_args(self, args: tuple[tuple[Var, Var], ...]) -> "EventSpec":
450448
"""Copy the event spec, with updated args.
451449
452450
Args:
@@ -462,7 +460,7 @@ def with_args(self, args: tuple[tuple[Var, Var], ...]) -> EventSpec:
462460
event_actions=self.event_actions.copy(),
463461
)
464462

465-
def add_args(self, *args: Var) -> EventSpec:
463+
def add_args(self, *args: Var) -> "EventSpec":
466464
"""Add arguments to the event spec.
467465
468466
Args:
@@ -553,7 +551,7 @@ def __call__(self, *args, **kwargs) -> EventSpec:
553551
class EventChain(EventActionsMixin):
554552
"""Container for a chain of events that will be executed in order."""
555553

556-
events: Sequence[EventSpec | EventVar | FunctionVar | EventCallback] = (
554+
events: "Sequence[EventSpec | EventVar | FunctionVar | EventCallback]" = (
557555
dataclasses.field(default_factory=list)
558556
)
559557

@@ -564,11 +562,11 @@ class EventChain(EventActionsMixin):
564562
@classmethod
565563
def create(
566564
cls,
567-
value: EventType,
565+
value: "EventType",
568566
args_spec: ArgsSpec | Sequence[ArgsSpec],
569567
key: str | None = None,
570568
**event_chain_kwargs,
571-
) -> EventChain | Var:
569+
) -> "EventChain | Var":
572570
"""Create an event chain from a variety of input types.
573571
574572
Args:
@@ -1483,7 +1481,7 @@ def download(
14831481

14841482
def call_script(
14851483
javascript_code: str | Var[str],
1486-
callback: EventType[Any] | None = None,
1484+
callback: "EventType[Any] | None" = None,
14871485
) -> EventSpec:
14881486
"""Create an event handler that executes arbitrary javascript code.
14891487
@@ -1524,7 +1522,7 @@ def call_script(
15241522

15251523
def call_function(
15261524
javascript_code: str | Var,
1527-
callback: EventType[Any] | None = None,
1525+
callback: "EventType[Any] | None" = None,
15281526
) -> EventSpec:
15291527
"""Create an event handler that executes arbitrary javascript code.
15301528
@@ -1560,7 +1558,7 @@ def call_function(
15601558

15611559
def run_script(
15621560
javascript_code: str | Var,
1563-
callback: EventType[Any] | None = None,
1561+
callback: "EventType[Any] | None" = None,
15641562
) -> EventSpec:
15651563
"""Create an event handler that executes arbitrary javascript code.
15661564
@@ -1578,7 +1576,7 @@ def run_script(
15781576
return call_function(ArgsFunctionOperation.create((), javascript_code), callback)
15791577

15801578

1581-
def get_event(state: BaseState, event: str):
1579+
def get_event(state: "BaseState", event: str):
15821580
"""Get the event from the given state.
15831581
15841582
Args:
@@ -1591,7 +1589,7 @@ def get_event(state: BaseState, event: str):
15911589
return f"{state.get_name()}.{event}"
15921590

15931591

1594-
def get_hydrate_event(state: BaseState) -> str:
1592+
def get_hydrate_event(state: "BaseState") -> str:
15951593
"""Get the name of the hydrate event for the state.
15961594
15971595
Args:
@@ -1944,7 +1942,7 @@ def call_event_fn(
19441942
fn: Callable,
19451943
arg_spec: ArgsSpec | Sequence[ArgsSpec],
19461944
key: str | None = None,
1947-
) -> list[EventSpec | FunctionVar | EventVar]:
1945+
) -> "list[EventSpec | FunctionVar | EventVar]":
19481946
"""Call a function to a list of event specs.
19491947
19501948
The function should return a single event-like value or a heterogeneous
@@ -2151,7 +2149,7 @@ def create(
21512149
cls,
21522150
value: EventSpec | EventHandler,
21532151
_var_data: VarData | None = None,
2154-
) -> LiteralEventVar:
2152+
) -> "LiteralEventVar":
21552153
"""Create a new LiteralEventVar instance.
21562154
21572155
Args:
@@ -2238,7 +2236,7 @@ def create(
22382236
cls,
22392237
value: EventChain,
22402238
_var_data: VarData | None = None,
2241-
) -> LiteralEventChainVar:
2239+
) -> "LiteralEventChainVar":
22422240
"""Create a new LiteralEventChainVar instance.
22432241
22442242
Args:
@@ -2361,39 +2359,39 @@ def __init__(self, func: Callable[[Any, Unpack[P]], Any]):
23612359

23622360
@overload
23632361
def __call__(
2364-
self: EventCallback[Unpack[Q]],
2365-
) -> EventCallback[Unpack[Q]]: ...
2362+
self: "EventCallback[Unpack[Q]]",
2363+
) -> "EventCallback[Unpack[Q]]": ...
23662364

23672365
@overload
23682366
def __call__(
2369-
self: EventCallback[V, Unpack[Q]], value: V | Var[V]
2370-
) -> EventCallback[Unpack[Q]]: ...
2367+
self: "EventCallback[V, Unpack[Q]]", value: V | Var[V]
2368+
) -> "EventCallback[Unpack[Q]]": ...
23712369

23722370
@overload
23732371
def __call__(
2374-
self: EventCallback[V, V2, Unpack[Q]],
2372+
self: "EventCallback[V, V2, Unpack[Q]]",
23752373
value: V | Var[V],
23762374
value2: V2 | Var[V2],
2377-
) -> EventCallback[Unpack[Q]]: ...
2375+
) -> "EventCallback[Unpack[Q]]": ...
23782376

23792377
@overload
23802378
def __call__(
2381-
self: EventCallback[V, V2, V3, Unpack[Q]],
2379+
self: "EventCallback[V, V2, V3, Unpack[Q]]",
23822380
value: V | Var[V],
23832381
value2: V2 | Var[V2],
23842382
value3: V3 | Var[V3],
2385-
) -> EventCallback[Unpack[Q]]: ...
2383+
) -> "EventCallback[Unpack[Q]]": ...
23862384

23872385
@overload
23882386
def __call__(
2389-
self: EventCallback[V, V2, V3, V4, Unpack[Q]],
2387+
self: "EventCallback[V, V2, V3, V4, Unpack[Q]]",
23902388
value: V | Var[V],
23912389
value2: V2 | Var[V2],
23922390
value3: V3 | Var[V3],
23932391
value4: V4 | Var[V4],
2394-
) -> EventCallback[Unpack[Q]]: ...
2392+
) -> "EventCallback[Unpack[Q]]": ...
23952393

2396-
def __call__(self, *values) -> EventCallback: # pyright: ignore [reportInconsistentOverload]
2394+
def __call__(self, *values) -> "EventCallback": # pyright: ignore [reportInconsistentOverload]
23972395
"""Call the function with the values.
23982396
23992397
Args:
@@ -2406,11 +2404,11 @@ def __call__(self, *values) -> EventCallback: # pyright: ignore [reportInconsis
24062404

24072405
@overload
24082406
def __get__(
2409-
self: EventCallback[Unpack[P]], instance: None, owner: Any
2410-
) -> EventCallback[Unpack[P]]: ...
2407+
self: "EventCallback[Unpack[P]]", instance: None, owner: Any
2408+
) -> "EventCallback[Unpack[P]]": ...
24112409

24122410
@overload
2413-
def __get__(self, instance: Any, owner: Any) -> Callable[[Unpack[P]]]: ...
2411+
def __get__(self, instance: Any, owner: Any) -> "Callable[[Unpack[P]]]": ...
24142412

24152413
def __get__(self, instance: Any, owner: Any) -> Callable:
24162414
"""Get the function with the instance bound to it.
@@ -2434,19 +2432,19 @@ class LambdaEventCallback(Protocol[Unpack[P]]):
24342432
__code__: types.CodeType
24352433

24362434
@overload
2437-
def __call__(self: LambdaEventCallback[()]) -> Any: ...
2435+
def __call__(self: "LambdaEventCallback[()]") -> Any: ...
24382436

24392437
@overload
2440-
def __call__(self: LambdaEventCallback[V], value: Var[V], /) -> Any: ...
2438+
def __call__(self: "LambdaEventCallback[V]", value: "Var[V]", /) -> Any: ...
24412439

24422440
@overload
24432441
def __call__(
2444-
self: LambdaEventCallback[V, V2], value: Var[V], value2: Var[V2], /
2442+
self: "LambdaEventCallback[V, V2]", value: Var[V], value2: Var[V2], /
24452443
) -> Any: ...
24462444

24472445
@overload
24482446
def __call__(
2449-
self: LambdaEventCallback[V, V2, V3],
2447+
self: "LambdaEventCallback[V, V2, V3]",
24502448
value: Var[V],
24512449
value2: Var[V2],
24522450
value3: Var[V3],

0 commit comments

Comments
 (0)