reflex 0.7.14a6__py3-none-any.whl → 0.8.0a2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of reflex might be problematic. Click here for more details.
- reflex/.templates/jinja/app/rxconfig.py.jinja2 +4 -1
- reflex/.templates/jinja/web/package.json.jinja2 +1 -1
- reflex/.templates/jinja/web/pages/_app.js.jinja2 +16 -10
- reflex/.templates/jinja/web/pages/_document.js.jinja2 +1 -1
- reflex/.templates/jinja/web/pages/base_page.js.jinja2 +0 -1
- reflex/.templates/jinja/web/pages/stateful_component.js.jinja2 +4 -0
- reflex/.templates/jinja/web/utils/context.js.jinja2 +25 -8
- reflex/.templates/web/app/entry.client.js +8 -0
- reflex/.templates/web/app/routes.js +10 -0
- reflex/.templates/web/components/reflex/radix_themes_color_mode_provider.js +12 -37
- reflex/.templates/web/postcss.config.js +1 -1
- reflex/.templates/web/react-router.config.js +6 -0
- reflex/.templates/web/utils/client_side_routing.js +21 -19
- reflex/.templates/web/utils/react-theme.js +92 -0
- reflex/.templates/web/utils/state.js +160 -67
- reflex/.templates/web/vite.config.js +32 -0
- reflex/__init__.py +1 -6
- reflex/__init__.pyi +0 -4
- reflex/app.py +53 -116
- reflex/base.py +1 -87
- reflex/compiler/compiler.py +41 -8
- reflex/compiler/templates.py +3 -3
- reflex/compiler/utils.py +73 -33
- reflex/components/__init__.py +0 -2
- reflex/components/__init__.pyi +0 -3
- reflex/components/base/__init__.py +1 -5
- reflex/components/base/__init__.pyi +4 -6
- reflex/components/base/app_wrap.pyi +5 -4
- reflex/components/base/body.pyi +5 -4
- reflex/components/base/document.py +18 -14
- reflex/components/base/document.pyi +83 -27
- reflex/components/base/error_boundary.pyi +5 -4
- reflex/components/base/fragment.pyi +5 -4
- reflex/components/base/link.pyi +9 -7
- reflex/components/base/meta.pyi +17 -13
- reflex/components/base/script.py +60 -58
- reflex/components/base/script.pyi +246 -31
- reflex/components/base/strict_mode.pyi +5 -4
- reflex/components/component.py +146 -217
- reflex/components/core/__init__.py +1 -0
- reflex/components/core/__init__.pyi +1 -0
- reflex/components/core/auto_scroll.pyi +5 -4
- reflex/components/core/banner.pyi +25 -19
- reflex/components/core/client_side_routing.py +7 -6
- reflex/components/core/client_side_routing.pyi +6 -56
- reflex/components/core/clipboard.pyi +5 -4
- reflex/components/core/debounce.py +1 -0
- reflex/components/core/debounce.pyi +5 -4
- reflex/components/core/foreach.py +3 -2
- reflex/components/core/helmet.py +14 -0
- reflex/components/{next/base.pyi → core/helmet.pyi} +10 -7
- reflex/components/core/html.pyi +5 -4
- reflex/components/core/sticky.pyi +17 -13
- reflex/components/core/upload.py +2 -1
- reflex/components/core/upload.pyi +21 -16
- reflex/components/datadisplay/code.py +2 -72
- reflex/components/datadisplay/code.pyi +9 -10
- reflex/components/datadisplay/dataeditor.pyi +11 -6
- reflex/components/datadisplay/shiki_code_block.pyi +13 -10
- reflex/components/dynamic.py +5 -5
- reflex/components/el/element.pyi +5 -4
- reflex/components/el/elements/base.pyi +5 -4
- reflex/components/el/elements/forms.pyi +69 -52
- reflex/components/el/elements/inline.pyi +113 -85
- reflex/components/el/elements/media.pyi +105 -79
- reflex/components/el/elements/metadata.pyi +25 -19
- reflex/components/el/elements/other.pyi +29 -22
- reflex/components/el/elements/scripts.pyi +13 -10
- reflex/components/el/elements/sectioning.pyi +61 -46
- reflex/components/el/elements/tables.pyi +41 -31
- reflex/components/el/elements/typography.pyi +61 -46
- reflex/components/field.py +175 -0
- reflex/components/gridjs/datatable.py +2 -2
- reflex/components/gridjs/datatable.pyi +11 -9
- reflex/components/lucide/icon.py +6 -2
- reflex/components/lucide/icon.pyi +15 -10
- reflex/components/markdown/markdown.pyi +5 -4
- reflex/components/moment/moment.pyi +5 -4
- reflex/components/plotly/plotly.pyi +19 -10
- reflex/components/props.py +376 -27
- reflex/components/radix/primitives/accordion.py +8 -1
- reflex/components/radix/primitives/accordion.pyi +29 -22
- reflex/components/radix/primitives/base.pyi +9 -7
- reflex/components/radix/primitives/drawer.pyi +45 -34
- reflex/components/radix/primitives/form.pyi +41 -31
- reflex/components/radix/primitives/progress.pyi +21 -16
- reflex/components/radix/primitives/slider.pyi +21 -16
- reflex/components/radix/themes/base.py +3 -3
- reflex/components/radix/themes/base.pyi +33 -25
- reflex/components/radix/themes/color_mode.pyi +13 -10
- reflex/components/radix/themes/components/alert_dialog.pyi +29 -22
- reflex/components/radix/themes/components/aspect_ratio.pyi +5 -4
- reflex/components/radix/themes/components/avatar.pyi +5 -4
- reflex/components/radix/themes/components/badge.pyi +5 -4
- reflex/components/radix/themes/components/button.pyi +5 -4
- reflex/components/radix/themes/components/callout.pyi +21 -16
- reflex/components/radix/themes/components/card.pyi +5 -4
- reflex/components/radix/themes/components/checkbox.pyi +13 -10
- reflex/components/radix/themes/components/checkbox_cards.pyi +9 -7
- reflex/components/radix/themes/components/checkbox_group.pyi +9 -7
- reflex/components/radix/themes/components/context_menu.pyi +53 -40
- reflex/components/radix/themes/components/data_list.pyi +17 -13
- reflex/components/radix/themes/components/dialog.pyi +29 -22
- reflex/components/radix/themes/components/dropdown_menu.pyi +33 -25
- reflex/components/radix/themes/components/hover_card.pyi +17 -13
- reflex/components/radix/themes/components/icon_button.pyi +5 -4
- reflex/components/radix/themes/components/inset.pyi +5 -4
- reflex/components/radix/themes/components/popover.pyi +17 -13
- reflex/components/radix/themes/components/progress.pyi +5 -4
- reflex/components/radix/themes/components/radio.pyi +5 -4
- reflex/components/radix/themes/components/radio_cards.pyi +9 -7
- reflex/components/radix/themes/components/radio_group.pyi +17 -13
- reflex/components/radix/themes/components/scroll_area.pyi +5 -4
- reflex/components/radix/themes/components/segmented_control.pyi +9 -7
- reflex/components/radix/themes/components/select.pyi +37 -28
- reflex/components/radix/themes/components/separator.pyi +5 -4
- reflex/components/radix/themes/components/skeleton.pyi +5 -4
- reflex/components/radix/themes/components/slider.pyi +5 -4
- reflex/components/radix/themes/components/spinner.pyi +5 -4
- reflex/components/radix/themes/components/switch.pyi +5 -4
- reflex/components/radix/themes/components/table.pyi +29 -22
- reflex/components/radix/themes/components/tabs.pyi +21 -16
- reflex/components/radix/themes/components/text_area.pyi +5 -4
- reflex/components/radix/themes/components/text_field.pyi +13 -10
- reflex/components/radix/themes/components/tooltip.pyi +5 -4
- reflex/components/radix/themes/layout/base.pyi +5 -4
- reflex/components/radix/themes/layout/box.pyi +5 -4
- reflex/components/radix/themes/layout/center.pyi +5 -4
- reflex/components/radix/themes/layout/container.pyi +5 -4
- reflex/components/radix/themes/layout/flex.pyi +5 -4
- reflex/components/radix/themes/layout/grid.pyi +5 -4
- reflex/components/radix/themes/layout/list.pyi +21 -16
- reflex/components/radix/themes/layout/section.pyi +5 -4
- reflex/components/radix/themes/layout/spacer.pyi +5 -4
- reflex/components/radix/themes/layout/stack.pyi +13 -10
- reflex/components/radix/themes/typography/blockquote.pyi +5 -4
- reflex/components/radix/themes/typography/code.pyi +5 -4
- reflex/components/radix/themes/typography/heading.pyi +5 -4
- reflex/components/radix/themes/typography/link.py +46 -11
- reflex/components/radix/themes/typography/link.pyi +311 -6
- reflex/components/radix/themes/typography/text.pyi +29 -22
- reflex/components/react_player/audio.pyi +5 -4
- reflex/components/react_player/react_player.pyi +5 -4
- reflex/components/react_player/video.pyi +5 -4
- reflex/components/recharts/cartesian.py +2 -1
- reflex/components/recharts/cartesian.pyi +65 -46
- reflex/components/recharts/charts.py +4 -2
- reflex/components/recharts/charts.pyi +36 -24
- reflex/components/recharts/general.pyi +24 -18
- reflex/components/recharts/polar.py +8 -4
- reflex/components/recharts/polar.pyi +16 -10
- reflex/components/recharts/recharts.pyi +9 -7
- reflex/components/sonner/toast.py +2 -2
- reflex/components/sonner/toast.pyi +10 -8
- reflex/config.py +3 -77
- reflex/constants/__init__.py +2 -2
- reflex/constants/base.py +28 -11
- reflex/constants/compiler.py +5 -3
- reflex/constants/event.py +1 -0
- reflex/constants/installer.py +22 -16
- reflex/constants/route.py +19 -7
- reflex/constants/state.py +2 -0
- reflex/custom_components/custom_components.py +0 -14
- reflex/environment.py +1 -1
- reflex/event.py +178 -81
- reflex/experimental/__init__.py +0 -30
- reflex/istate/proxy.py +5 -3
- reflex/page.py +0 -27
- reflex/plugins/__init__.py +3 -2
- reflex/plugins/base.py +5 -1
- reflex/plugins/shared_tailwind.py +158 -0
- reflex/plugins/sitemap.py +206 -0
- reflex/plugins/tailwind_v3.py +13 -106
- reflex/plugins/tailwind_v4.py +15 -108
- reflex/reflex.py +1 -0
- reflex/route.py +15 -21
- reflex/state.py +134 -140
- reflex/testing.py +58 -10
- reflex/utils/build.py +38 -82
- reflex/utils/exec.py +59 -161
- reflex/utils/export.py +2 -2
- reflex/utils/imports.py +0 -4
- reflex/utils/misc.py +28 -0
- reflex/utils/prerequisites.py +65 -62
- reflex/utils/processes.py +8 -7
- reflex/utils/pyi_generator.py +21 -9
- reflex/utils/serializers.py +14 -1
- reflex/utils/types.py +196 -61
- reflex/vars/__init__.py +2 -0
- reflex/vars/base.py +367 -134
- {reflex-0.7.14a6.dist-info → reflex-0.8.0a2.dist-info}/METADATA +12 -5
- {reflex-0.7.14a6.dist-info → reflex-0.8.0a2.dist-info}/RECORD +195 -202
- reflex/.templates/web/next.config.js +0 -7
- reflex/components/base/head.py +0 -20
- reflex/components/base/head.pyi +0 -116
- reflex/components/next/__init__.py +0 -10
- reflex/components/next/base.py +0 -7
- reflex/components/next/image.py +0 -117
- reflex/components/next/image.pyi +0 -94
- reflex/components/next/link.py +0 -20
- reflex/components/next/link.pyi +0 -67
- reflex/components/next/video.py +0 -38
- reflex/components/next/video.pyi +0 -68
- reflex/components/suneditor/__init__.py +0 -5
- reflex/components/suneditor/editor.py +0 -269
- reflex/components/suneditor/editor.pyi +0 -199
- reflex/experimental/layout.py +0 -254
- reflex/experimental/layout.pyi +0 -814
- {reflex-0.7.14a6.dist-info → reflex-0.8.0a2.dist-info}/WHEEL +0 -0
- {reflex-0.7.14a6.dist-info → reflex-0.8.0a2.dist-info}/entry_points.txt +0 -0
- {reflex-0.7.14a6.dist-info → reflex-0.8.0a2.dist-info}/licenses/LICENSE +0 -0
reflex/event.py
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
"""Define event classes to connect the frontend and backend."""
|
|
2
2
|
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
3
|
import dataclasses
|
|
6
4
|
import inspect
|
|
7
5
|
import types
|
|
8
6
|
import urllib.parse
|
|
9
7
|
from base64 import b64encode
|
|
10
|
-
from collections.abc import Callable, Sequence
|
|
11
|
-
from functools import partial
|
|
8
|
+
from collections.abc import Callable, Mapping, Sequence
|
|
9
|
+
from functools import lru_cache, partial
|
|
12
10
|
from typing import (
|
|
13
11
|
TYPE_CHECKING,
|
|
14
12
|
Annotated,
|
|
@@ -16,7 +14,6 @@ from typing import (
|
|
|
16
14
|
Generic,
|
|
17
15
|
NoReturn,
|
|
18
16
|
Protocol,
|
|
19
|
-
TypedDict,
|
|
20
17
|
TypeVar,
|
|
21
18
|
get_args,
|
|
22
19
|
get_origin,
|
|
@@ -24,12 +21,12 @@ from typing import (
|
|
|
24
21
|
overload,
|
|
25
22
|
)
|
|
26
23
|
|
|
27
|
-
from typing_extensions import Self, TypeAliasType, TypeVarTuple, Unpack
|
|
24
|
+
from typing_extensions import Self, TypeAliasType, TypedDict, TypeVarTuple, Unpack
|
|
28
25
|
|
|
29
26
|
from reflex import constants
|
|
30
27
|
from reflex.constants.compiler import CompileVars, Hooks, Imports
|
|
31
28
|
from reflex.constants.state import FRONTEND_EVENT_STATE
|
|
32
|
-
from reflex.utils import
|
|
29
|
+
from reflex.utils import format
|
|
33
30
|
from reflex.utils.decorator import once
|
|
34
31
|
from reflex.utils.exceptions import (
|
|
35
32
|
EventFnArgMismatchError,
|
|
@@ -95,6 +92,7 @@ BACKGROUND_TASK_MARKER = "_reflex_background_task"
|
|
|
95
92
|
@dataclasses.dataclass(
|
|
96
93
|
init=True,
|
|
97
94
|
frozen=True,
|
|
95
|
+
kw_only=True,
|
|
98
96
|
)
|
|
99
97
|
class EventActionsMixin:
|
|
100
98
|
"""Mixin for DOM event actions."""
|
|
@@ -170,6 +168,7 @@ class EventActionsMixin:
|
|
|
170
168
|
@dataclasses.dataclass(
|
|
171
169
|
init=True,
|
|
172
170
|
frozen=True,
|
|
171
|
+
kw_only=True,
|
|
173
172
|
)
|
|
174
173
|
class EventHandler(EventActionsMixin):
|
|
175
174
|
"""An event handler responds to an event to update the state."""
|
|
@@ -181,6 +180,36 @@ class EventHandler(EventActionsMixin):
|
|
|
181
180
|
# Empty string means this event handler is a server side event.
|
|
182
181
|
state_full_name: str = dataclasses.field(default="")
|
|
183
182
|
|
|
183
|
+
def __hash__(self):
|
|
184
|
+
"""Get the hash of the event handler.
|
|
185
|
+
|
|
186
|
+
Returns:
|
|
187
|
+
The hash of the event handler.
|
|
188
|
+
"""
|
|
189
|
+
return hash((tuple(self.event_actions.items()), self.fn, self.state_full_name))
|
|
190
|
+
|
|
191
|
+
def get_parameters(self) -> Mapping[str, inspect.Parameter]:
|
|
192
|
+
"""Get the parameters of the function.
|
|
193
|
+
|
|
194
|
+
Returns:
|
|
195
|
+
The parameters of the function.
|
|
196
|
+
"""
|
|
197
|
+
if self.fn is None:
|
|
198
|
+
return {}
|
|
199
|
+
return inspect.signature(self.fn).parameters
|
|
200
|
+
|
|
201
|
+
@property
|
|
202
|
+
def _parameters(self) -> Mapping[str, inspect.Parameter]:
|
|
203
|
+
"""Get the parameters of the function.
|
|
204
|
+
|
|
205
|
+
Returns:
|
|
206
|
+
The parameters of the function.
|
|
207
|
+
"""
|
|
208
|
+
if (parameters := getattr(self, "__parameters", None)) is None:
|
|
209
|
+
parameters = {**self.get_parameters()}
|
|
210
|
+
object.__setattr__(self, "__parameters", parameters)
|
|
211
|
+
return parameters
|
|
212
|
+
|
|
184
213
|
@classmethod
|
|
185
214
|
def __class_getitem__(cls, args_spec: str) -> Annotated:
|
|
186
215
|
"""Get a typed EventHandler.
|
|
@@ -202,7 +231,7 @@ class EventHandler(EventActionsMixin):
|
|
|
202
231
|
"""
|
|
203
232
|
return getattr(self.fn, BACKGROUND_TASK_MARKER, False)
|
|
204
233
|
|
|
205
|
-
def __call__(self, *args: Any, **kwargs: Any) -> EventSpec:
|
|
234
|
+
def __call__(self, *args: Any, **kwargs: Any) -> "EventSpec":
|
|
206
235
|
"""Pass arguments to the handler to get an event spec.
|
|
207
236
|
|
|
208
237
|
This method configures event handlers that take in arguments.
|
|
@@ -220,7 +249,7 @@ class EventHandler(EventActionsMixin):
|
|
|
220
249
|
from reflex.utils.exceptions import EventHandlerTypeError
|
|
221
250
|
|
|
222
251
|
# Get the function args.
|
|
223
|
-
fn_args = list(
|
|
252
|
+
fn_args = list(self._parameters)[1:]
|
|
224
253
|
|
|
225
254
|
if not isinstance(
|
|
226
255
|
repeated_arg := next(
|
|
@@ -270,6 +299,7 @@ class EventHandler(EventActionsMixin):
|
|
|
270
299
|
@dataclasses.dataclass(
|
|
271
300
|
init=True,
|
|
272
301
|
frozen=True,
|
|
302
|
+
kw_only=True,
|
|
273
303
|
)
|
|
274
304
|
class EventSpec(EventActionsMixin):
|
|
275
305
|
"""An event specification.
|
|
@@ -309,7 +339,7 @@ class EventSpec(EventActionsMixin):
|
|
|
309
339
|
object.__setattr__(self, "client_handler_name", client_handler_name)
|
|
310
340
|
object.__setattr__(self, "args", args or ())
|
|
311
341
|
|
|
312
|
-
def with_args(self, args: tuple[tuple[Var, Var], ...]) -> EventSpec:
|
|
342
|
+
def with_args(self, args: tuple[tuple[Var, Var], ...]) -> "EventSpec":
|
|
313
343
|
"""Copy the event spec, with updated args.
|
|
314
344
|
|
|
315
345
|
Args:
|
|
@@ -325,7 +355,7 @@ class EventSpec(EventActionsMixin):
|
|
|
325
355
|
event_actions=self.event_actions.copy(),
|
|
326
356
|
)
|
|
327
357
|
|
|
328
|
-
def add_args(self, *args: Var) -> EventSpec:
|
|
358
|
+
def add_args(self, *args: Var) -> "EventSpec":
|
|
329
359
|
"""Add arguments to the event spec.
|
|
330
360
|
|
|
331
361
|
Args:
|
|
@@ -340,9 +370,7 @@ class EventSpec(EventActionsMixin):
|
|
|
340
370
|
from reflex.utils.exceptions import EventHandlerTypeError
|
|
341
371
|
|
|
342
372
|
# Get the remaining unfilled function args.
|
|
343
|
-
fn_args = list(
|
|
344
|
-
1 + len(self.args) :
|
|
345
|
-
]
|
|
373
|
+
fn_args = list(self.handler._parameters)[1 + len(self.args) :]
|
|
346
374
|
fn_args = (Var(_js_expr=arg) for arg in fn_args)
|
|
347
375
|
|
|
348
376
|
# Construct the payload.
|
|
@@ -418,7 +446,7 @@ class CallableEventSpec(EventSpec):
|
|
|
418
446
|
class EventChain(EventActionsMixin):
|
|
419
447
|
"""Container for a chain of events that will be executed in order."""
|
|
420
448
|
|
|
421
|
-
events: Sequence[EventSpec | EventVar | EventCallback] = dataclasses.field(
|
|
449
|
+
events: Sequence["EventSpec | EventVar | EventCallback"] = dataclasses.field(
|
|
422
450
|
default_factory=list
|
|
423
451
|
)
|
|
424
452
|
|
|
@@ -429,11 +457,11 @@ class EventChain(EventActionsMixin):
|
|
|
429
457
|
@classmethod
|
|
430
458
|
def create(
|
|
431
459
|
cls,
|
|
432
|
-
value: EventType,
|
|
460
|
+
value: "EventType",
|
|
433
461
|
args_spec: ArgsSpec | Sequence[ArgsSpec],
|
|
434
462
|
key: str | None = None,
|
|
435
463
|
**event_chain_kwargs,
|
|
436
|
-
) -> EventChain | Var:
|
|
464
|
+
) -> "EventChain | Var":
|
|
437
465
|
"""Create an event chain from a variety of input types.
|
|
438
466
|
|
|
439
467
|
Args:
|
|
@@ -640,6 +668,74 @@ def key_event(
|
|
|
640
668
|
)
|
|
641
669
|
|
|
642
670
|
|
|
671
|
+
@dataclasses.dataclass(
|
|
672
|
+
init=True,
|
|
673
|
+
frozen=True,
|
|
674
|
+
)
|
|
675
|
+
class JavascriptMouseEvent:
|
|
676
|
+
"""Interface for a Javascript MouseEvent https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent."""
|
|
677
|
+
|
|
678
|
+
button: int = 0
|
|
679
|
+
buttons: list[int] = dataclasses.field(default_factory=list)
|
|
680
|
+
clientX: int = 0 # noqa: N815
|
|
681
|
+
clientY: int = 0 # noqa: N815
|
|
682
|
+
altKey: bool = False # noqa: N815
|
|
683
|
+
ctrlKey: bool = False # noqa: N815
|
|
684
|
+
metaKey: bool = False # noqa: N815
|
|
685
|
+
shiftKey: bool = False # noqa: N815
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
class JavascriptPointerEvent(JavascriptMouseEvent):
|
|
689
|
+
"""Interface for a Javascript PointerEvent https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent.
|
|
690
|
+
|
|
691
|
+
Inherits from JavascriptMouseEvent.
|
|
692
|
+
"""
|
|
693
|
+
|
|
694
|
+
|
|
695
|
+
class MouseEventInfo(TypedDict):
|
|
696
|
+
"""Information about a mouse event."""
|
|
697
|
+
|
|
698
|
+
button: int
|
|
699
|
+
buttons: int
|
|
700
|
+
client_x: int
|
|
701
|
+
client_y: int
|
|
702
|
+
alt_key: bool
|
|
703
|
+
ctrl_key: bool
|
|
704
|
+
meta_key: bool
|
|
705
|
+
shift_key: bool
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
class PointerEventInfo(MouseEventInfo):
|
|
709
|
+
"""Information about a pointer event."""
|
|
710
|
+
|
|
711
|
+
|
|
712
|
+
def pointer_event_spec(
|
|
713
|
+
e: ObjectVar[JavascriptPointerEvent],
|
|
714
|
+
) -> tuple[Var[PointerEventInfo]]:
|
|
715
|
+
"""Get the pointer event information.
|
|
716
|
+
|
|
717
|
+
Args:
|
|
718
|
+
e: The pointer event.
|
|
719
|
+
|
|
720
|
+
Returns:
|
|
721
|
+
The pointer event information.
|
|
722
|
+
"""
|
|
723
|
+
return (
|
|
724
|
+
Var.create(
|
|
725
|
+
{
|
|
726
|
+
"button": e.button,
|
|
727
|
+
"buttons": e.buttons,
|
|
728
|
+
"client_x": e.clientX,
|
|
729
|
+
"client_y": e.clientY,
|
|
730
|
+
"alt_key": e.altKey,
|
|
731
|
+
"ctrl_key": e.ctrlKey,
|
|
732
|
+
"meta_key": e.metaKey,
|
|
733
|
+
"shift_key": e.shiftKey,
|
|
734
|
+
},
|
|
735
|
+
).to(PointerEventInfo),
|
|
736
|
+
)
|
|
737
|
+
|
|
738
|
+
|
|
643
739
|
def no_args_event_spec() -> tuple[()]:
|
|
644
740
|
"""Empty event handler.
|
|
645
741
|
|
|
@@ -1146,7 +1242,7 @@ def _callback_arg_spec(eval_result: Any):
|
|
|
1146
1242
|
|
|
1147
1243
|
def call_script(
|
|
1148
1244
|
javascript_code: str | Var[str],
|
|
1149
|
-
callback: EventType[Any] | None = None,
|
|
1245
|
+
callback: "EventType[Any] | None" = None,
|
|
1150
1246
|
) -> EventSpec:
|
|
1151
1247
|
"""Create an event handler that executes arbitrary javascript code.
|
|
1152
1248
|
|
|
@@ -1187,7 +1283,7 @@ def call_script(
|
|
|
1187
1283
|
|
|
1188
1284
|
def call_function(
|
|
1189
1285
|
javascript_code: str | Var,
|
|
1190
|
-
callback: EventType[Any] | None = None,
|
|
1286
|
+
callback: "EventType[Any] | None" = None,
|
|
1191
1287
|
) -> EventSpec:
|
|
1192
1288
|
"""Create an event handler that executes arbitrary javascript code.
|
|
1193
1289
|
|
|
@@ -1223,7 +1319,7 @@ def call_function(
|
|
|
1223
1319
|
|
|
1224
1320
|
def run_script(
|
|
1225
1321
|
javascript_code: str | Var,
|
|
1226
|
-
callback: EventType[Any] | None = None,
|
|
1322
|
+
callback: "EventType[Any] | None" = None,
|
|
1227
1323
|
) -> EventSpec:
|
|
1228
1324
|
"""Create an event handler that executes arbitrary javascript code.
|
|
1229
1325
|
|
|
@@ -1241,7 +1337,7 @@ def run_script(
|
|
|
1241
1337
|
return call_function(ArgsFunctionOperation.create((), javascript_code), callback)
|
|
1242
1338
|
|
|
1243
1339
|
|
|
1244
|
-
def get_event(state: BaseState, event: str):
|
|
1340
|
+
def get_event(state: "BaseState", event: str):
|
|
1245
1341
|
"""Get the event from the given state.
|
|
1246
1342
|
|
|
1247
1343
|
Args:
|
|
@@ -1254,7 +1350,7 @@ def get_event(state: BaseState, event: str):
|
|
|
1254
1350
|
return f"{state.get_name()}.{event}"
|
|
1255
1351
|
|
|
1256
1352
|
|
|
1257
|
-
def get_hydrate_event(state: BaseState) -> str:
|
|
1353
|
+
def get_hydrate_event(state: "BaseState") -> str:
|
|
1258
1354
|
"""Get the name of the hydrate event for the state.
|
|
1259
1355
|
|
|
1260
1356
|
Args:
|
|
@@ -1266,16 +1362,11 @@ def get_hydrate_event(state: BaseState) -> str:
|
|
|
1266
1362
|
return get_event(state, constants.CompileVars.HYDRATE)
|
|
1267
1363
|
|
|
1268
1364
|
|
|
1269
|
-
def _values_returned_from_event(
|
|
1270
|
-
event_spec: ArgsSpec | Sequence[ArgsSpec],
|
|
1271
|
-
) -> list[Any]:
|
|
1365
|
+
def _values_returned_from_event(event_spec_annotations: list[Any]) -> list[Any]:
|
|
1272
1366
|
return [
|
|
1273
1367
|
event_spec_return_type
|
|
1274
|
-
for
|
|
1275
|
-
|
|
1276
|
-
)
|
|
1277
|
-
if (event_spec_return_type := get_type_hints(arg_spec).get("return", None))
|
|
1278
|
-
is not None
|
|
1368
|
+
for event_spec_annotation in event_spec_annotations
|
|
1369
|
+
if (event_spec_return_type := event_spec_annotation.get("return")) is not None
|
|
1279
1370
|
and get_origin(event_spec_return_type) is tuple
|
|
1280
1371
|
]
|
|
1281
1372
|
|
|
@@ -1303,6 +1394,8 @@ def _check_event_args_subclass_of_callback(
|
|
|
1303
1394
|
# noqa: DAR401 delayed_exceptions[]
|
|
1304
1395
|
# noqa: DAR402 EventHandlerArgTypeMismatchError
|
|
1305
1396
|
"""
|
|
1397
|
+
from reflex.utils import console
|
|
1398
|
+
|
|
1306
1399
|
type_match_found: dict[str, bool] = {}
|
|
1307
1400
|
delayed_exceptions: list[EventHandlerArgTypeMismatchError] = []
|
|
1308
1401
|
|
|
@@ -1395,22 +1488,23 @@ def call_event_handler(
|
|
|
1395
1488
|
Returns:
|
|
1396
1489
|
The event spec from calling the event handler.
|
|
1397
1490
|
"""
|
|
1398
|
-
event_spec_args = parse_args_spec(event_spec)
|
|
1491
|
+
event_spec_args, event_annotations = parse_args_spec(event_spec)
|
|
1399
1492
|
|
|
1400
|
-
event_spec_return_types = _values_returned_from_event(
|
|
1493
|
+
event_spec_return_types = _values_returned_from_event(event_annotations)
|
|
1401
1494
|
|
|
1402
1495
|
if isinstance(event_callback, EventSpec):
|
|
1496
|
+
parameters = event_callback.handler._parameters
|
|
1497
|
+
|
|
1403
1498
|
check_fn_match_arg_spec(
|
|
1404
1499
|
event_callback.handler.fn,
|
|
1405
|
-
|
|
1500
|
+
parameters,
|
|
1501
|
+
event_spec_args,
|
|
1406
1502
|
key,
|
|
1407
1503
|
bool(event_callback.handler.state_full_name) + len(event_callback.args),
|
|
1408
1504
|
event_callback.handler.fn.__qualname__,
|
|
1409
1505
|
)
|
|
1410
1506
|
|
|
1411
|
-
event_callback_spec_args = list(
|
|
1412
|
-
inspect.signature(event_callback.handler.fn).parameters.keys()
|
|
1413
|
-
)
|
|
1507
|
+
event_callback_spec_args = list(parameters)
|
|
1414
1508
|
|
|
1415
1509
|
try:
|
|
1416
1510
|
type_hints_of_provided_callback = get_type_hints(event_callback.handler.fn)
|
|
@@ -1436,18 +1530,19 @@ def call_event_handler(
|
|
|
1436
1530
|
# Handle partial application of EventSpec args
|
|
1437
1531
|
return event_callback.add_args(*event_spec_args)
|
|
1438
1532
|
|
|
1533
|
+
parameters = event_callback._parameters
|
|
1534
|
+
|
|
1439
1535
|
check_fn_match_arg_spec(
|
|
1440
1536
|
event_callback.fn,
|
|
1441
|
-
|
|
1537
|
+
parameters,
|
|
1538
|
+
event_spec_args,
|
|
1442
1539
|
key,
|
|
1443
1540
|
bool(event_callback.state_full_name),
|
|
1444
1541
|
event_callback.fn.__qualname__,
|
|
1445
1542
|
)
|
|
1446
1543
|
|
|
1447
1544
|
if event_spec_return_types:
|
|
1448
|
-
event_callback_spec_args = list(
|
|
1449
|
-
inspect.signature(event_callback.fn).parameters.keys()
|
|
1450
|
-
)
|
|
1545
|
+
event_callback_spec_args = list(parameters)
|
|
1451
1546
|
|
|
1452
1547
|
try:
|
|
1453
1548
|
type_hints_of_provided_callback = get_type_hints(event_callback.fn)
|
|
@@ -1501,6 +1596,7 @@ def resolve_annotation(annotations: dict[str, Any], arg_name: str, spec: ArgsSpe
|
|
|
1501
1596
|
return annotation
|
|
1502
1597
|
|
|
1503
1598
|
|
|
1599
|
+
@lru_cache
|
|
1504
1600
|
def parse_args_spec(arg_spec: ArgsSpec | Sequence[ArgsSpec]):
|
|
1505
1601
|
"""Parse the args provided in the ArgsSpec of an event trigger.
|
|
1506
1602
|
|
|
@@ -1511,31 +1607,32 @@ def parse_args_spec(arg_spec: ArgsSpec | Sequence[ArgsSpec]):
|
|
|
1511
1607
|
The parsed args.
|
|
1512
1608
|
"""
|
|
1513
1609
|
# if there's multiple, the first is the default
|
|
1514
|
-
|
|
1610
|
+
if isinstance(arg_spec, Sequence):
|
|
1611
|
+
annotations = [get_type_hints(one_arg_spec) for one_arg_spec in arg_spec]
|
|
1612
|
+
arg_spec = arg_spec[0]
|
|
1613
|
+
else:
|
|
1614
|
+
annotations = [get_type_hints(arg_spec)]
|
|
1615
|
+
|
|
1515
1616
|
spec = inspect.getfullargspec(arg_spec)
|
|
1516
|
-
annotations = get_type_hints(arg_spec)
|
|
1517
1617
|
|
|
1518
1618
|
return list(
|
|
1519
1619
|
arg_spec(
|
|
1520
1620
|
*[
|
|
1521
1621
|
Var(f"_{l_arg}").to(
|
|
1522
1622
|
unwrap_var_annotation(
|
|
1523
|
-
resolve_annotation(
|
|
1524
|
-
annotations,
|
|
1525
|
-
l_arg,
|
|
1526
|
-
spec=arg_spec,
|
|
1527
|
-
)
|
|
1623
|
+
resolve_annotation(annotations[0], l_arg, spec=arg_spec)
|
|
1528
1624
|
)
|
|
1529
1625
|
)
|
|
1530
1626
|
for l_arg in spec.args
|
|
1531
1627
|
]
|
|
1532
1628
|
)
|
|
1533
|
-
)
|
|
1629
|
+
), annotations
|
|
1534
1630
|
|
|
1535
1631
|
|
|
1536
1632
|
def check_fn_match_arg_spec(
|
|
1537
1633
|
user_func: Callable,
|
|
1538
|
-
|
|
1634
|
+
user_func_parameters: Mapping[str, inspect.Parameter],
|
|
1635
|
+
event_spec_args: Sequence[Var],
|
|
1539
1636
|
key: str | None = None,
|
|
1540
1637
|
number_of_bound_args: int = 0,
|
|
1541
1638
|
func_name: str | None = None,
|
|
@@ -1545,7 +1642,8 @@ def check_fn_match_arg_spec(
|
|
|
1545
1642
|
|
|
1546
1643
|
Args:
|
|
1547
1644
|
user_func: The function to be validated.
|
|
1548
|
-
|
|
1645
|
+
user_func_parameters: The parameters of the function to be validated.
|
|
1646
|
+
event_spec_args: The argument specification for the event trigger.
|
|
1549
1647
|
key: The key of the event trigger.
|
|
1550
1648
|
number_of_bound_args: The number of bound arguments to the function.
|
|
1551
1649
|
func_name: The name of the function to be validated.
|
|
@@ -1553,22 +1651,20 @@ def check_fn_match_arg_spec(
|
|
|
1553
1651
|
Raises:
|
|
1554
1652
|
EventFnArgMismatchError: Raised if the number of mandatory arguments do not match
|
|
1555
1653
|
"""
|
|
1556
|
-
user_args = list(
|
|
1654
|
+
user_args = list(user_func_parameters)
|
|
1557
1655
|
# Drop the first argument if it's a bound method
|
|
1558
1656
|
if inspect.ismethod(user_func) and user_func.__self__ is not None:
|
|
1559
1657
|
user_args = user_args[1:]
|
|
1560
1658
|
|
|
1561
1659
|
user_default_args = [
|
|
1562
1660
|
p.default
|
|
1563
|
-
for p in
|
|
1661
|
+
for p in user_func_parameters.values()
|
|
1564
1662
|
if p.default is not inspect.Parameter.empty
|
|
1565
1663
|
]
|
|
1566
1664
|
number_of_user_args = len(user_args) - number_of_bound_args
|
|
1567
1665
|
number_of_user_default_args = len(user_default_args) if user_default_args else 0
|
|
1568
1666
|
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
number_of_event_args = len(parsed_event_args)
|
|
1667
|
+
number_of_event_args = len(event_spec_args)
|
|
1572
1668
|
|
|
1573
1669
|
if number_of_user_args - number_of_user_default_args > number_of_event_args:
|
|
1574
1670
|
msg = (
|
|
@@ -1605,12 +1701,14 @@ def call_event_fn(
|
|
|
1605
1701
|
from reflex.event import EventHandler, EventSpec
|
|
1606
1702
|
from reflex.utils.exceptions import EventHandlerValueError
|
|
1607
1703
|
|
|
1608
|
-
|
|
1609
|
-
check_fn_match_arg_spec(fn, arg_spec, key=key)
|
|
1704
|
+
parsed_args, event_annotations = parse_args_spec(arg_spec)
|
|
1610
1705
|
|
|
1611
|
-
|
|
1706
|
+
parameters = inspect.signature(fn).parameters
|
|
1612
1707
|
|
|
1613
|
-
|
|
1708
|
+
# Check that fn signature matches arg_spec
|
|
1709
|
+
check_fn_match_arg_spec(fn, parameters, parsed_args, key=key)
|
|
1710
|
+
|
|
1711
|
+
number_of_fn_args = len(parameters)
|
|
1614
1712
|
|
|
1615
1713
|
# Call the function with the parsed args.
|
|
1616
1714
|
out = fn(*[*parsed_args][:number_of_fn_args])
|
|
@@ -1653,7 +1751,7 @@ def get_handler_args(
|
|
|
1653
1751
|
Returns:
|
|
1654
1752
|
The handler args.
|
|
1655
1753
|
"""
|
|
1656
|
-
args =
|
|
1754
|
+
args = event_spec.handler._parameters
|
|
1657
1755
|
|
|
1658
1756
|
return event_spec.args if len(args) > 1 else ()
|
|
1659
1757
|
|
|
@@ -1778,7 +1876,7 @@ class LiteralEventVar(VarOperationCall, LiteralVar, EventVar):
|
|
|
1778
1876
|
cls,
|
|
1779
1877
|
value: EventSpec | EventHandler,
|
|
1780
1878
|
_var_data: VarData | None = None,
|
|
1781
|
-
) -> LiteralEventVar:
|
|
1879
|
+
) -> "LiteralEventVar":
|
|
1782
1880
|
"""Create a new LiteralEventVar instance.
|
|
1783
1881
|
|
|
1784
1882
|
Args:
|
|
@@ -1865,7 +1963,7 @@ class LiteralEventChainVar(ArgsFunctionOperationBuilder, LiteralVar, EventChainV
|
|
|
1865
1963
|
cls,
|
|
1866
1964
|
value: EventChain,
|
|
1867
1965
|
_var_data: VarData | None = None,
|
|
1868
|
-
) -> LiteralEventChainVar:
|
|
1966
|
+
) -> "LiteralEventChainVar":
|
|
1869
1967
|
"""Create a new LiteralEventChainVar instance.
|
|
1870
1968
|
|
|
1871
1969
|
Args:
|
|
@@ -1924,7 +2022,6 @@ class LiteralEventChainVar(ArgsFunctionOperationBuilder, LiteralVar, EventChainV
|
|
|
1924
2022
|
|
|
1925
2023
|
P = TypeVarTuple("P")
|
|
1926
2024
|
Q = TypeVarTuple("Q")
|
|
1927
|
-
T = TypeVar("T")
|
|
1928
2025
|
V = TypeVar("V")
|
|
1929
2026
|
V2 = TypeVar("V2")
|
|
1930
2027
|
V3 = TypeVar("V3")
|
|
@@ -1945,39 +2042,39 @@ class EventCallback(Generic[Unpack[P]], EventActionsMixin):
|
|
|
1945
2042
|
|
|
1946
2043
|
@overload
|
|
1947
2044
|
def __call__(
|
|
1948
|
-
self: EventCallback[Unpack[Q]],
|
|
1949
|
-
) -> EventCallback[Unpack[Q]]: ...
|
|
2045
|
+
self: "EventCallback[Unpack[Q]]",
|
|
2046
|
+
) -> "EventCallback[Unpack[Q]]": ...
|
|
1950
2047
|
|
|
1951
2048
|
@overload
|
|
1952
2049
|
def __call__(
|
|
1953
|
-
self: EventCallback[V, Unpack[Q]], value: V | Var[V]
|
|
1954
|
-
) -> EventCallback[Unpack[Q]]: ...
|
|
2050
|
+
self: "EventCallback[V, Unpack[Q]]", value: V | Var[V]
|
|
2051
|
+
) -> "EventCallback[Unpack[Q]]": ...
|
|
1955
2052
|
|
|
1956
2053
|
@overload
|
|
1957
2054
|
def __call__(
|
|
1958
|
-
self: EventCallback[V, V2, Unpack[Q]],
|
|
2055
|
+
self: "EventCallback[V, V2, Unpack[Q]]",
|
|
1959
2056
|
value: V | Var[V],
|
|
1960
2057
|
value2: V2 | Var[V2],
|
|
1961
|
-
) -> EventCallback[Unpack[Q]]: ...
|
|
2058
|
+
) -> "EventCallback[Unpack[Q]]": ...
|
|
1962
2059
|
|
|
1963
2060
|
@overload
|
|
1964
2061
|
def __call__(
|
|
1965
|
-
self: EventCallback[V, V2, V3, Unpack[Q]],
|
|
2062
|
+
self: "EventCallback[V, V2, V3, Unpack[Q]]",
|
|
1966
2063
|
value: V | Var[V],
|
|
1967
2064
|
value2: V2 | Var[V2],
|
|
1968
2065
|
value3: V3 | Var[V3],
|
|
1969
|
-
) -> EventCallback[Unpack[Q]]: ...
|
|
2066
|
+
) -> "EventCallback[Unpack[Q]]": ...
|
|
1970
2067
|
|
|
1971
2068
|
@overload
|
|
1972
2069
|
def __call__(
|
|
1973
|
-
self: EventCallback[V, V2, V3, V4, Unpack[Q]],
|
|
2070
|
+
self: "EventCallback[V, V2, V3, V4, Unpack[Q]]",
|
|
1974
2071
|
value: V | Var[V],
|
|
1975
2072
|
value2: V2 | Var[V2],
|
|
1976
2073
|
value3: V3 | Var[V3],
|
|
1977
2074
|
value4: V4 | Var[V4],
|
|
1978
|
-
) -> EventCallback[Unpack[Q]]: ...
|
|
2075
|
+
) -> "EventCallback[Unpack[Q]]": ...
|
|
1979
2076
|
|
|
1980
|
-
def __call__(self, *values) -> EventCallback: # pyright: ignore [reportInconsistentOverload]
|
|
2077
|
+
def __call__(self, *values) -> "EventCallback": # pyright: ignore [reportInconsistentOverload]
|
|
1981
2078
|
"""Call the function with the values.
|
|
1982
2079
|
|
|
1983
2080
|
Args:
|
|
@@ -1990,11 +2087,11 @@ class EventCallback(Generic[Unpack[P]], EventActionsMixin):
|
|
|
1990
2087
|
|
|
1991
2088
|
@overload
|
|
1992
2089
|
def __get__(
|
|
1993
|
-
self: EventCallback[Unpack[P]], instance: None, owner: Any
|
|
1994
|
-
) -> EventCallback[Unpack[P]]: ...
|
|
2090
|
+
self: "EventCallback[Unpack[P]]", instance: None, owner: Any
|
|
2091
|
+
) -> "EventCallback[Unpack[P]]": ...
|
|
1995
2092
|
|
|
1996
2093
|
@overload
|
|
1997
|
-
def __get__(self, instance: Any, owner: Any) -> Callable[[Unpack[P]]]: ...
|
|
2094
|
+
def __get__(self, instance: Any, owner: Any) -> "Callable[[Unpack[P]]]": ...
|
|
1998
2095
|
|
|
1999
2096
|
def __get__(self, instance: Any, owner: Any) -> Callable:
|
|
2000
2097
|
"""Get the function with the instance bound to it.
|
|
@@ -2018,19 +2115,19 @@ class LambdaEventCallback(Protocol[Unpack[P]]):
|
|
|
2018
2115
|
__code__: types.CodeType
|
|
2019
2116
|
|
|
2020
2117
|
@overload
|
|
2021
|
-
def __call__(self: LambdaEventCallback[()]) -> Any: ...
|
|
2118
|
+
def __call__(self: "LambdaEventCallback[()]") -> Any: ...
|
|
2022
2119
|
|
|
2023
2120
|
@overload
|
|
2024
|
-
def __call__(self: LambdaEventCallback[V], value: Var[V], /) -> Any: ...
|
|
2121
|
+
def __call__(self: "LambdaEventCallback[V]", value: "Var[V]", /) -> Any: ...
|
|
2025
2122
|
|
|
2026
2123
|
@overload
|
|
2027
2124
|
def __call__(
|
|
2028
|
-
self: LambdaEventCallback[V, V2], value: Var[V], value2: Var[V2], /
|
|
2125
|
+
self: "LambdaEventCallback[V, V2]", value: Var[V], value2: Var[V2], /
|
|
2029
2126
|
) -> Any: ...
|
|
2030
2127
|
|
|
2031
2128
|
@overload
|
|
2032
2129
|
def __call__(
|
|
2033
|
-
self: LambdaEventCallback[V, V2, V3],
|
|
2130
|
+
self: "LambdaEventCallback[V, V2, V3]",
|
|
2034
2131
|
value: Var[V],
|
|
2035
2132
|
value2: Var[V2],
|
|
2036
2133
|
value3: Var[V3],
|
reflex/experimental/__init__.py
CHANGED
|
@@ -3,15 +3,11 @@
|
|
|
3
3
|
from types import SimpleNamespace
|
|
4
4
|
|
|
5
5
|
from reflex.components.datadisplay.shiki_code_block import code_block as code_block
|
|
6
|
-
from reflex.components.props import PropsBase
|
|
7
|
-
from reflex.components.radix.themes.components.progress import progress as progress
|
|
8
|
-
from reflex.components.sonner.toast import toast as toast
|
|
9
6
|
from reflex.utils.console import warn
|
|
10
7
|
from reflex.utils.misc import run_in_thread
|
|
11
8
|
|
|
12
9
|
from . import hooks as hooks
|
|
13
10
|
from .client_state import ClientStateVar as ClientStateVar
|
|
14
|
-
from .layout import layout as layout
|
|
15
11
|
|
|
16
12
|
|
|
17
13
|
class ExperimentalNamespace(SimpleNamespace):
|
|
@@ -32,30 +28,6 @@ class ExperimentalNamespace(SimpleNamespace):
|
|
|
32
28
|
)
|
|
33
29
|
return super().__getattribute__(item)
|
|
34
30
|
|
|
35
|
-
@property
|
|
36
|
-
def toast(self):
|
|
37
|
-
"""Temporary property returning the toast namespace.
|
|
38
|
-
|
|
39
|
-
Remove this property when toast is fully promoted.
|
|
40
|
-
|
|
41
|
-
Returns:
|
|
42
|
-
The toast namespace.
|
|
43
|
-
"""
|
|
44
|
-
self.register_component_warning("toast")
|
|
45
|
-
return toast
|
|
46
|
-
|
|
47
|
-
@property
|
|
48
|
-
def progress(self):
|
|
49
|
-
"""Temporary property returning the progress component.
|
|
50
|
-
|
|
51
|
-
Remove this property when progress is fully promoted.
|
|
52
|
-
|
|
53
|
-
Returns:
|
|
54
|
-
The progress component.
|
|
55
|
-
"""
|
|
56
|
-
self.register_component_warning("progress")
|
|
57
|
-
return progress
|
|
58
|
-
|
|
59
31
|
@property
|
|
60
32
|
def run_in_thread(self):
|
|
61
33
|
"""Temporary property returning the run_in_thread helper function.
|
|
@@ -85,7 +57,5 @@ class ExperimentalNamespace(SimpleNamespace):
|
|
|
85
57
|
_x = ExperimentalNamespace(
|
|
86
58
|
client_state=ClientStateVar.create,
|
|
87
59
|
hooks=hooks,
|
|
88
|
-
layout=layout,
|
|
89
|
-
PropsBase=PropsBase,
|
|
90
60
|
code_block=code_block,
|
|
91
61
|
)
|
reflex/istate/proxy.py
CHANGED
|
@@ -10,7 +10,7 @@ import inspect
|
|
|
10
10
|
import json
|
|
11
11
|
from collections.abc import Callable, Sequence
|
|
12
12
|
from types import MethodType
|
|
13
|
-
from typing import TYPE_CHECKING, Any, SupportsIndex
|
|
13
|
+
from typing import TYPE_CHECKING, Any, SupportsIndex, TypeVar
|
|
14
14
|
|
|
15
15
|
import pydantic
|
|
16
16
|
import wrapt
|
|
@@ -27,6 +27,8 @@ from reflex.vars.base import Var
|
|
|
27
27
|
if TYPE_CHECKING:
|
|
28
28
|
from reflex.state import BaseState, StateUpdate
|
|
29
29
|
|
|
30
|
+
T_STATE = TypeVar("T_STATE", bound="BaseState")
|
|
31
|
+
|
|
30
32
|
|
|
31
33
|
class StateProxy(wrapt.ObjectProxy):
|
|
32
34
|
"""Proxy of a state instance to control mutability of vars for a background task.
|
|
@@ -269,7 +271,7 @@ class StateProxy(wrapt.ObjectProxy):
|
|
|
269
271
|
raise ImmutableStateError(msg)
|
|
270
272
|
return self.__wrapped__.get_substate(path)
|
|
271
273
|
|
|
272
|
-
async def get_state(self, state_cls: type[
|
|
274
|
+
async def get_state(self, state_cls: type[T_STATE]) -> T_STATE:
|
|
273
275
|
"""Get an instance of the state associated with this token.
|
|
274
276
|
|
|
275
277
|
Args:
|
|
@@ -289,7 +291,7 @@ class StateProxy(wrapt.ObjectProxy):
|
|
|
289
291
|
raise ImmutableStateError(msg)
|
|
290
292
|
return type(self)(
|
|
291
293
|
await self.__wrapped__.get_state(state_cls), parent_state_proxy=self
|
|
292
|
-
)
|
|
294
|
+
) # pyright: ignore [reportReturnType]
|
|
293
295
|
|
|
294
296
|
async def _as_state_update(self, *args, **kwargs) -> StateUpdate:
|
|
295
297
|
"""Temporarily allow mutability to access parent_state.
|