11"""Define event classes to connect the frontend and backend."""
22
3- from __future__ import annotations
4-
53import dataclasses
64import inspect
75import sys
@@ -101,7 +99,7 @@ def substate_token(self) -> str:
10199UPLOAD_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:
@@ -155,7 +153,7 @@ def resolve_upload_handler_param(handler: EventHandler) -> tuple[str, Any]:
155153 raise UploadValueError (msg )
156154
157155
158- def resolve_upload_chunk_handler_param (handler : EventHandler ) -> tuple [str , type ]:
156+ def resolve_upload_chunk_handler_param (handler : " EventHandler" ) -> tuple [str , type ]:
159157 """Validate and resolve the UploadChunkIterator parameter for a handler.
160158
161159 Args:
@@ -338,7 +336,7 @@ def is_background(self) -> bool:
338336 """
339337 return getattr (self .fn , BACKGROUND_TASK_MARKER , False )
340338
341- def __call__ (self , * args : Any , ** kwargs : Any ) -> EventSpec :
339+ def __call__ (self , * args : Any , ** kwargs : Any ) -> " EventSpec" :
342340 """Pass arguments to the handler to get an event spec.
343341
344342 This method configures event handlers that take in arguments.
@@ -448,7 +446,7 @@ def __init__(
448446 object .__setattr__ (self , "client_handler_name" , client_handler_name )
449447 object .__setattr__ (self , "args" , args or ())
450448
451- def with_args (self , args : tuple [tuple [Var , Var ], ...]) -> EventSpec :
449+ def with_args (self , args : tuple [tuple [Var , Var ], ...]) -> " EventSpec" :
452450 """Copy the event spec, with updated args.
453451
454452 Args:
@@ -464,7 +462,7 @@ def with_args(self, args: tuple[tuple[Var, Var], ...]) -> EventSpec:
464462 event_actions = self .event_actions .copy (),
465463 )
466464
467- def add_args (self , * args : Var ) -> EventSpec :
465+ def add_args (self , * args : Var ) -> " EventSpec" :
468466 """Add arguments to the event spec.
469467
470468 Args:
@@ -555,7 +553,7 @@ def __call__(self, *args, **kwargs) -> EventSpec:
555553class EventChain (EventActionsMixin ):
556554 """Container for a chain of events that will be executed in order."""
557555
558- events : Sequence [EventSpec | EventVar | FunctionVar | EventCallback ] = (
556+ events : Sequence [" EventSpec | EventVar | FunctionVar | EventCallback" ] = (
559557 dataclasses .field (default_factory = list )
560558 )
561559
@@ -566,11 +564,11 @@ class EventChain(EventActionsMixin):
566564 @classmethod
567565 def create (
568566 cls ,
569- value : EventType ,
567+ value : " EventType" ,
570568 args_spec : ArgsSpec | Sequence [ArgsSpec ],
571569 key : str | None = None ,
572570 ** event_chain_kwargs ,
573- ) -> EventChain | Var :
571+ ) -> " EventChain | Var" :
574572 """Create an event chain from a variety of input types.
575573
576574 Args:
@@ -1485,7 +1483,7 @@ def download(
14851483
14861484def call_script (
14871485 javascript_code : str | Var [str ],
1488- callback : EventType [Any ] | None = None ,
1486+ callback : " EventType[Any] | None" = None ,
14891487) -> EventSpec :
14901488 """Create an event handler that executes arbitrary javascript code.
14911489
@@ -1526,7 +1524,7 @@ def call_script(
15261524
15271525def call_function (
15281526 javascript_code : str | Var ,
1529- callback : EventType [Any ] | None = None ,
1527+ callback : " EventType[Any] | None" = None ,
15301528) -> EventSpec :
15311529 """Create an event handler that executes arbitrary javascript code.
15321530
@@ -1562,7 +1560,7 @@ def call_function(
15621560
15631561def run_script (
15641562 javascript_code : str | Var ,
1565- callback : EventType [Any ] | None = None ,
1563+ callback : " EventType[Any] | None" = None ,
15661564) -> EventSpec :
15671565 """Create an event handler that executes arbitrary javascript code.
15681566
@@ -1580,7 +1578,7 @@ def run_script(
15801578 return call_function (ArgsFunctionOperation .create ((), javascript_code ), callback )
15811579
15821580
1583- def get_event (state : BaseState , event : str ):
1581+ def get_event (state : " BaseState" , event : str ):
15841582 """Get the event from the given state.
15851583
15861584 Args:
@@ -1593,7 +1591,7 @@ def get_event(state: BaseState, event: str):
15931591 return f"{ state .get_name ()} .{ event } "
15941592
15951593
1596- def get_hydrate_event (state : BaseState ) -> str :
1594+ def get_hydrate_event (state : " BaseState" ) -> str :
15971595 """Get the name of the hydrate event for the state.
15981596
15991597 Args:
@@ -1946,7 +1944,7 @@ def call_event_fn(
19461944 fn : Callable ,
19471945 arg_spec : ArgsSpec | Sequence [ArgsSpec ],
19481946 key : str | None = None ,
1949- ) -> list [EventSpec | FunctionVar | EventVar ]:
1947+ ) -> list [" EventSpec | FunctionVar | EventVar" ]:
19501948 """Call a function to a list of event specs.
19511949
19521950 The function should return a single event-like value or a heterogeneous
@@ -2153,7 +2151,7 @@ def create(
21532151 cls ,
21542152 value : EventSpec | EventHandler ,
21552153 _var_data : VarData | None = None ,
2156- ) -> LiteralEventVar :
2154+ ) -> " LiteralEventVar" :
21572155 """Create a new LiteralEventVar instance.
21582156
21592157 Args:
@@ -2240,7 +2238,7 @@ def create(
22402238 cls ,
22412239 value : EventChain ,
22422240 _var_data : VarData | None = None ,
2243- ) -> LiteralEventChainVar :
2241+ ) -> " LiteralEventChainVar" :
22442242 """Create a new LiteralEventChainVar instance.
22452243
22462244 Args:
@@ -2363,39 +2361,39 @@ def __init__(self, func: Callable[[Any, Unpack[P]], Any]):
23632361
23642362 @overload
23652363 def __call__ (
2366- self : EventCallback [Unpack [Q ]],
2367- ) -> EventCallback [Unpack [Q ]]: ...
2364+ self : " EventCallback[Unpack[Q]]" ,
2365+ ) -> " EventCallback[Unpack[Q]]" : ...
23682366
23692367 @overload
23702368 def __call__ (
2371- self : EventCallback [V , Unpack [Q ]], value : V | Var [V ]
2372- ) -> EventCallback [Unpack [Q ]]: ...
2369+ self : " EventCallback[V, Unpack[Q]]" , value : V | Var [V ]
2370+ ) -> " EventCallback[Unpack[Q]]" : ...
23732371
23742372 @overload
23752373 def __call__ (
2376- self : EventCallback [V , V2 , Unpack [Q ]],
2374+ self : " EventCallback[V, V2, Unpack[Q]]" ,
23772375 value : V | Var [V ],
23782376 value2 : V2 | Var [V2 ],
2379- ) -> EventCallback [Unpack [Q ]]: ...
2377+ ) -> " EventCallback[Unpack[Q]]" : ...
23802378
23812379 @overload
23822380 def __call__ (
2383- self : EventCallback [V , V2 , V3 , Unpack [Q ]],
2381+ self : " EventCallback[V, V2, V3, Unpack[Q]]" ,
23842382 value : V | Var [V ],
23852383 value2 : V2 | Var [V2 ],
23862384 value3 : V3 | Var [V3 ],
2387- ) -> EventCallback [Unpack [Q ]]: ...
2385+ ) -> " EventCallback[Unpack[Q]]" : ...
23882386
23892387 @overload
23902388 def __call__ (
2391- self : EventCallback [V , V2 , V3 , V4 , Unpack [Q ]],
2389+ self : " EventCallback[V, V2, V3, V4, Unpack[Q]]" ,
23922390 value : V | Var [V ],
23932391 value2 : V2 | Var [V2 ],
23942392 value3 : V3 | Var [V3 ],
23952393 value4 : V4 | Var [V4 ],
2396- ) -> EventCallback [Unpack [Q ]]: ...
2394+ ) -> " EventCallback[Unpack[Q]]" : ...
23972395
2398- def __call__ (self , * values ) -> EventCallback : # pyright: ignore [reportInconsistentOverload]
2396+ def __call__ (self , * values ) -> " EventCallback" : # pyright: ignore [reportInconsistentOverload]
23992397 """Call the function with the values.
24002398
24012399 Args:
@@ -2408,8 +2406,8 @@ def __call__(self, *values) -> EventCallback: # pyright: ignore [reportInconsis
24082406
24092407 @overload
24102408 def __get__ (
2411- self : EventCallback [Unpack [P ]], instance : None , owner : Any
2412- ) -> EventCallback [Unpack [P ]]: ...
2409+ self : " EventCallback[Unpack[P]]" , instance : None , owner : Any
2410+ ) -> " EventCallback[Unpack[P]]" : ...
24132411
24142412 @overload
24152413 def __get__ (self , instance : Any , owner : Any ) -> Callable [[Unpack [P ]]]: ...
@@ -2436,19 +2434,19 @@ class LambdaEventCallback(Protocol[Unpack[P]]):
24362434 __code__ : types .CodeType
24372435
24382436 @overload
2439- def __call__ (self : LambdaEventCallback [()]) -> Any : ...
2437+ def __call__ (self : " LambdaEventCallback[()]" ) -> Any : ...
24402438
24412439 @overload
2442- def __call__ (self : LambdaEventCallback [V ], value : Var [V ], / ) -> Any : ...
2440+ def __call__ (self : " LambdaEventCallback[V]" , value : Var [V ], / ) -> Any : ...
24432441
24442442 @overload
24452443 def __call__ (
2446- self : LambdaEventCallback [V , V2 ], value : Var [V ], value2 : Var [V2 ], /
2444+ self : " LambdaEventCallback[V, V2]" , value : Var [V ], value2 : Var [V2 ], /
24472445 ) -> Any : ...
24482446
24492447 @overload
24502448 def __call__ (
2451- self : LambdaEventCallback [V , V2 , V3 ],
2449+ self : " LambdaEventCallback[V, V2, V3]" ,
24522450 value : Var [V ],
24532451 value2 : Var [V2 ],
24542452 value3 : Var [V3 ],
0 commit comments