Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ jobs:
working-directory: ./reflex-web
run: |
uv pip compile pyproject.toml --no-annotate --no-header --no-deps --output-file requirements.txt
grep -ivE "reflex " requirements.txt > requirements.txt.tmp && mv requirements.txt.tmp requirements.txt
grep -ivE "reflex(-docgen)? " requirements.txt > requirements.txt.tmp && mv requirements.txt.tmp requirements.txt
- name: Install Requirements for reflex-web
working-directory: ./reflex-web
run: uv pip install -r requirements.txt
Expand Down
72 changes: 35 additions & 37 deletions reflex/event.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Define event classes to connect the frontend and backend."""

from __future__ import annotations

import dataclasses
import inspect
import sys
Expand Down Expand Up @@ -101,7 +99,7 @@ def substate_token(self) -> str:
UPLOAD_FILES_CLIENT_HANDLER = "uploadFiles"


def _handler_name(handler: EventHandler) -> str:
def _handler_name(handler: "EventHandler") -> str:
"""Get a stable fully qualified handler name for errors.

Args:
Expand All @@ -115,7 +113,7 @@ def _handler_name(handler: EventHandler) -> str:
return handler.fn.__qualname__


def resolve_upload_handler_param(handler: EventHandler) -> tuple[str, Any]:
def resolve_upload_handler_param(handler: "EventHandler") -> tuple[str, Any]:
"""Validate and resolve the UploadFile list parameter for a handler.

Args:
Expand Down Expand Up @@ -154,7 +152,7 @@ def resolve_upload_handler_param(handler: EventHandler) -> tuple[str, Any]:
raise UploadValueError(msg)


def resolve_upload_chunk_handler_param(handler: EventHandler) -> tuple[str, type]:
def resolve_upload_chunk_handler_param(handler: "EventHandler") -> tuple[str, type]:
"""Validate and resolve the UploadChunkIterator parameter for a handler.

Args:
Expand Down Expand Up @@ -336,7 +334,7 @@ def is_background(self) -> bool:
"""
return getattr(self.fn, BACKGROUND_TASK_MARKER, False)

def __call__(self, *args: Any, **kwargs: Any) -> EventSpec:
def __call__(self, *args: Any, **kwargs: Any) -> "EventSpec":
"""Pass arguments to the handler to get an event spec.

This method configures event handlers that take in arguments.
Expand Down Expand Up @@ -446,7 +444,7 @@ def __init__(
object.__setattr__(self, "client_handler_name", client_handler_name)
object.__setattr__(self, "args", args or ())

def with_args(self, args: tuple[tuple[Var, Var], ...]) -> EventSpec:
def with_args(self, args: tuple[tuple[Var, Var], ...]) -> "EventSpec":
"""Copy the event spec, with updated args.

Args:
Expand All @@ -462,7 +460,7 @@ def with_args(self, args: tuple[tuple[Var, Var], ...]) -> EventSpec:
event_actions=self.event_actions.copy(),
)

def add_args(self, *args: Var) -> EventSpec:
def add_args(self, *args: Var) -> "EventSpec":
"""Add arguments to the event spec.

Args:
Expand Down Expand Up @@ -553,7 +551,7 @@ def __call__(self, *args, **kwargs) -> EventSpec:
class EventChain(EventActionsMixin):
"""Container for a chain of events that will be executed in order."""

events: Sequence[EventSpec | EventVar | FunctionVar | EventCallback] = (
events: "Sequence[EventSpec | EventVar | FunctionVar | EventCallback]" = (
dataclasses.field(default_factory=list)
)

Expand All @@ -564,11 +562,11 @@ class EventChain(EventActionsMixin):
@classmethod
def create(
cls,
value: EventType,
value: "EventType",
args_spec: ArgsSpec | Sequence[ArgsSpec],
key: str | None = None,
**event_chain_kwargs,
) -> EventChain | Var:
) -> "EventChain | Var":
"""Create an event chain from a variety of input types.

Args:
Expand Down Expand Up @@ -1483,7 +1481,7 @@ def download(

def call_script(
javascript_code: str | Var[str],
callback: EventType[Any] | None = None,
callback: "EventType[Any] | None" = None,
) -> EventSpec:
"""Create an event handler that executes arbitrary javascript code.

Expand Down Expand Up @@ -1524,7 +1522,7 @@ def call_script(

def call_function(
javascript_code: str | Var,
callback: EventType[Any] | None = None,
callback: "EventType[Any] | None" = None,
) -> EventSpec:
"""Create an event handler that executes arbitrary javascript code.

Expand Down Expand Up @@ -1560,7 +1558,7 @@ def call_function(

def run_script(
javascript_code: str | Var,
callback: EventType[Any] | None = None,
callback: "EventType[Any] | None" = None,
) -> EventSpec:
"""Create an event handler that executes arbitrary javascript code.

Expand All @@ -1578,7 +1576,7 @@ def run_script(
return call_function(ArgsFunctionOperation.create((), javascript_code), callback)


def get_event(state: BaseState, event: str):
def get_event(state: "BaseState", event: str):
"""Get the event from the given state.

Args:
Expand All @@ -1591,7 +1589,7 @@ def get_event(state: BaseState, event: str):
return f"{state.get_name()}.{event}"


def get_hydrate_event(state: BaseState) -> str:
def get_hydrate_event(state: "BaseState") -> str:
"""Get the name of the hydrate event for the state.

Args:
Expand Down Expand Up @@ -1944,7 +1942,7 @@ def call_event_fn(
fn: Callable,
arg_spec: ArgsSpec | Sequence[ArgsSpec],
key: str | None = None,
) -> list[EventSpec | FunctionVar | EventVar]:
) -> "list[EventSpec | FunctionVar | EventVar]":
"""Call a function to a list of event specs.

The function should return a single event-like value or a heterogeneous
Expand Down Expand Up @@ -2151,7 +2149,7 @@ def create(
cls,
value: EventSpec | EventHandler,
_var_data: VarData | None = None,
) -> LiteralEventVar:
) -> "LiteralEventVar":
"""Create a new LiteralEventVar instance.

Args:
Expand Down Expand Up @@ -2238,7 +2236,7 @@ def create(
cls,
value: EventChain,
_var_data: VarData | None = None,
) -> LiteralEventChainVar:
) -> "LiteralEventChainVar":
"""Create a new LiteralEventChainVar instance.

Args:
Expand Down Expand Up @@ -2361,39 +2359,39 @@ def __init__(self, func: Callable[[Any, Unpack[P]], Any]):

@overload
def __call__(
self: EventCallback[Unpack[Q]],
) -> EventCallback[Unpack[Q]]: ...
self: "EventCallback[Unpack[Q]]",
) -> "EventCallback[Unpack[Q]]": ...

@overload
def __call__(
self: EventCallback[V, Unpack[Q]], value: V | Var[V]
) -> EventCallback[Unpack[Q]]: ...
self: "EventCallback[V, Unpack[Q]]", value: V | Var[V]
) -> "EventCallback[Unpack[Q]]": ...

@overload
def __call__(
self: EventCallback[V, V2, Unpack[Q]],
self: "EventCallback[V, V2, Unpack[Q]]",
value: V | Var[V],
value2: V2 | Var[V2],
) -> EventCallback[Unpack[Q]]: ...
) -> "EventCallback[Unpack[Q]]": ...

@overload
def __call__(
self: EventCallback[V, V2, V3, Unpack[Q]],
self: "EventCallback[V, V2, V3, Unpack[Q]]",
value: V | Var[V],
value2: V2 | Var[V2],
value3: V3 | Var[V3],
) -> EventCallback[Unpack[Q]]: ...
) -> "EventCallback[Unpack[Q]]": ...

@overload
def __call__(
self: EventCallback[V, V2, V3, V4, Unpack[Q]],
self: "EventCallback[V, V2, V3, V4, Unpack[Q]]",
value: V | Var[V],
value2: V2 | Var[V2],
value3: V3 | Var[V3],
value4: V4 | Var[V4],
) -> EventCallback[Unpack[Q]]: ...
) -> "EventCallback[Unpack[Q]]": ...

def __call__(self, *values) -> EventCallback: # pyright: ignore [reportInconsistentOverload]
def __call__(self, *values) -> "EventCallback": # pyright: ignore [reportInconsistentOverload]
"""Call the function with the values.

Args:
Expand All @@ -2406,11 +2404,11 @@ def __call__(self, *values) -> EventCallback: # pyright: ignore [reportInconsis

@overload
def __get__(
self: EventCallback[Unpack[P]], instance: None, owner: Any
) -> EventCallback[Unpack[P]]: ...
self: "EventCallback[Unpack[P]]", instance: None, owner: Any
) -> "EventCallback[Unpack[P]]": ...

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

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

@overload
def __call__(self: LambdaEventCallback[()]) -> Any: ...
def __call__(self: "LambdaEventCallback[()]") -> Any: ...

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

@overload
def __call__(
self: LambdaEventCallback[V, V2], value: Var[V], value2: Var[V2], /
self: "LambdaEventCallback[V, V2]", value: Var[V], value2: Var[V2], /
) -> Any: ...

@overload
def __call__(
self: LambdaEventCallback[V, V2, V3],
self: "LambdaEventCallback[V, V2, V3]",
value: Var[V],
value2: Var[V2],
value3: Var[V3],
Expand Down
Loading