reflex 0.6.0__py3-none-any.whl → 0.6.0a1__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/custom_components/pyproject.toml.jinja2 +2 -2
- reflex/.templates/jinja/web/pages/_app.js.jinja2 +1 -1
- reflex/.templates/jinja/web/pages/utils.js.jinja2 +2 -2
- reflex/.templates/web/components/reflex/chakra_color_mode_provider.js +36 -0
- reflex/.templates/web/utils/state.js +1 -3
- reflex/__init__.py +2 -8
- reflex/__init__.pyi +1 -2
- reflex/app.py +2 -4
- reflex/app_module_for_backend.py +1 -1
- reflex/base.py +1 -1
- reflex/compiler/compiler.py +2 -2
- reflex/compiler/utils.py +3 -3
- reflex/components/base/app_wrap.py +2 -2
- reflex/components/base/app_wrap.pyi +27 -17
- reflex/components/base/bare.py +5 -4
- reflex/components/base/body.pyi +27 -17
- reflex/components/base/document.pyi +131 -81
- reflex/components/base/error_boundary.py +7 -6
- reflex/components/base/error_boundary.pyi +33 -20
- reflex/components/base/fragment.pyi +27 -17
- reflex/components/base/head.pyi +53 -33
- reflex/components/base/link.py +1 -1
- reflex/components/base/link.pyi +54 -33
- reflex/components/base/meta.pyi +105 -65
- reflex/components/base/script.py +2 -1
- reflex/components/base/script.pyi +38 -21
- reflex/components/component.py +47 -53
- reflex/components/core/banner.py +27 -23
- reflex/components/core/banner.pyi +171 -134
- reflex/components/core/client_side_routing.py +3 -2
- reflex/components/core/client_side_routing.pyi +54 -33
- reflex/components/core/clipboard.py +1 -2
- reflex/components/core/clipboard.pyi +33 -20
- reflex/components/core/cond.py +5 -5
- reflex/components/core/debounce.py +5 -5
- reflex/components/core/debounce.pyi +33 -20
- reflex/components/core/foreach.py +4 -3
- reflex/components/core/html.py +1 -1
- reflex/components/core/html.pyi +46 -35
- reflex/components/core/match.py +17 -17
- reflex/components/core/upload.py +23 -17
- reflex/components/core/upload.pyi +124 -78
- reflex/components/datadisplay/code.py +10 -9
- reflex/components/datadisplay/code.pyi +409 -299
- reflex/components/datadisplay/dataeditor.py +10 -8
- reflex/components/datadisplay/dataeditor.pyi +53 -40
- reflex/components/el/element.pyi +27 -17
- reflex/components/el/elements/base.py +1 -1
- reflex/components/el/elements/base.pyi +45 -34
- reflex/components/el/elements/forms.py +16 -16
- reflex/components/el/elements/forms.pyi +707 -554
- reflex/components/el/elements/inline.py +1 -1
- reflex/components/el/elements/inline.pyi +1218 -937
- reflex/components/el/elements/media.py +1 -1
- reflex/components/el/elements/media.pyi +997 -786
- reflex/components/el/elements/metadata.py +6 -3
- reflex/components/el/elements/metadata.pyi +242 -181
- reflex/components/el/elements/other.py +1 -1
- reflex/components/el/elements/other.pyi +306 -235
- reflex/components/el/elements/scripts.py +1 -1
- reflex/components/el/elements/scripts.pyi +140 -109
- reflex/components/el/elements/sectioning.py +2 -0
- reflex/components/el/elements/sectioning.pyi +647 -496
- reflex/components/el/elements/tables.py +1 -1
- reflex/components/el/elements/tables.pyi +452 -351
- reflex/components/el/elements/typography.py +1 -1
- reflex/components/el/elements/typography.pyi +657 -506
- reflex/components/gridjs/datatable.py +9 -6
- reflex/components/gridjs/datatable.pyi +56 -35
- reflex/components/lucide/icon.py +1 -1
- reflex/components/lucide/icon.pyi +54 -33
- reflex/components/markdown/markdown.py +31 -26
- reflex/components/markdown/markdown.pyi +37 -27
- reflex/components/moment/moment.py +12 -13
- reflex/components/moment/moment.pyi +35 -23
- reflex/components/next/base.pyi +27 -17
- reflex/components/next/image.py +1 -1
- reflex/components/next/image.pyi +37 -22
- reflex/components/next/link.py +1 -1
- reflex/components/next/link.pyi +28 -17
- reflex/components/next/video.py +1 -1
- reflex/components/next/video.pyi +28 -17
- reflex/components/plotly/plotly.py +13 -12
- reflex/components/plotly/plotly.pyi +54 -39
- reflex/components/props.py +1 -1
- reflex/components/radix/__init__.pyi +0 -1
- reflex/components/radix/primitives/__init__.pyi +0 -1
- reflex/components/radix/primitives/accordion.py +4 -4
- reflex/components/radix/primitives/accordion.pyi +495 -424
- reflex/components/radix/primitives/base.py +1 -1
- reflex/components/radix/primitives/base.pyi +54 -33
- reflex/components/radix/primitives/drawer.py +1 -1
- reflex/components/radix/primitives/drawer.pyi +273 -172
- reflex/components/radix/primitives/form.py +1 -1
- reflex/components/radix/primitives/form.pyi +364 -257
- reflex/components/radix/primitives/progress.py +1 -1
- reflex/components/radix/primitives/progress.pyi +282 -231
- reflex/components/radix/primitives/slider.py +1 -1
- reflex/components/radix/primitives/slider.pyi +138 -87
- reflex/components/radix/themes/base.py +24 -3
- reflex/components/radix/themes/base.pyi +250 -178
- reflex/components/radix/themes/color_mode.py +5 -5
- reflex/components/radix/themes/color_mode.pyi +220 -187
- reflex/components/radix/themes/components/alert_dialog.py +1 -1
- reflex/components/radix/themes/components/alert_dialog.pyi +207 -136
- reflex/components/radix/themes/components/aspect_ratio.py +1 -1
- reflex/components/radix/themes/components/aspect_ratio.pyi +28 -17
- reflex/components/radix/themes/components/avatar.py +1 -1
- reflex/components/radix/themes/components/avatar.pyi +81 -70
- reflex/components/radix/themes/components/badge.py +1 -1
- reflex/components/radix/themes/components/badge.pyi +99 -88
- reflex/components/radix/themes/components/button.py +1 -1
- reflex/components/radix/themes/components/button.pyi +109 -98
- reflex/components/radix/themes/components/callout.py +1 -1
- reflex/components/radix/themes/components/callout.pyi +373 -322
- reflex/components/radix/themes/components/card.py +1 -1
- reflex/components/radix/themes/components/card.pyi +49 -38
- reflex/components/radix/themes/components/checkbox.py +2 -1
- reflex/components/radix/themes/components/checkbox.pyi +245 -208
- reflex/components/radix/themes/components/checkbox_cards.py +1 -1
- reflex/components/radix/themes/components/checkbox_cards.pyi +115 -94
- reflex/components/radix/themes/components/checkbox_group.py +1 -1
- reflex/components/radix/themes/components/checkbox_group.pyi +107 -86
- reflex/components/radix/themes/components/context_menu.py +1 -1
- reflex/components/radix/themes/components/context_menu.pyi +319 -238
- reflex/components/radix/themes/components/data_list.py +1 -1
- reflex/components/radix/themes/components/data_list.pyi +171 -130
- reflex/components/radix/themes/components/dialog.py +1 -1
- reflex/components/radix/themes/components/dialog.pyi +210 -139
- reflex/components/radix/themes/components/dropdown_menu.py +1 -1
- reflex/components/radix/themes/components/dropdown_menu.pyi +332 -249
- reflex/components/radix/themes/components/hover_card.py +1 -1
- reflex/components/radix/themes/components/hover_card.pyi +131 -90
- reflex/components/radix/themes/components/icon_button.py +3 -2
- reflex/components/radix/themes/components/icon_button.pyi +109 -98
- reflex/components/radix/themes/components/inset.py +1 -1
- reflex/components/radix/themes/components/inset.pyi +58 -47
- reflex/components/radix/themes/components/popover.py +1 -1
- reflex/components/radix/themes/components/popover.pyi +136 -95
- reflex/components/radix/themes/components/progress.py +1 -1
- reflex/components/radix/themes/components/progress.pyi +82 -71
- reflex/components/radix/themes/components/radio.py +1 -1
- reflex/components/radix/themes/components/radio.pyi +80 -69
- reflex/components/radix/themes/components/radio_cards.py +1 -1
- reflex/components/radix/themes/components/radio_cards.pyi +119 -98
- reflex/components/radix/themes/components/radio_group.py +11 -8
- reflex/components/radix/themes/components/radio_group.pyi +271 -228
- reflex/components/radix/themes/components/scroll_area.py +1 -1
- reflex/components/radix/themes/components/scroll_area.pyi +32 -21
- reflex/components/radix/themes/components/segmented_control.py +1 -1
- reflex/components/radix/themes/components/segmented_control.pyi +113 -90
- reflex/components/radix/themes/components/select.py +3 -2
- reflex/components/radix/themes/components/select.pyi +471 -374
- reflex/components/radix/themes/components/separator.py +2 -1
- reflex/components/radix/themes/components/separator.pyi +80 -69
- reflex/components/radix/themes/components/skeleton.py +1 -1
- reflex/components/radix/themes/components/skeleton.pyi +34 -23
- reflex/components/radix/themes/components/slider.py +3 -2
- reflex/components/radix/themes/components/slider.pyi +88 -75
- reflex/components/radix/themes/components/spinner.py +1 -1
- reflex/components/radix/themes/components/spinner.pyi +30 -19
- reflex/components/radix/themes/components/switch.py +1 -1
- reflex/components/radix/themes/components/switch.pyi +84 -71
- reflex/components/radix/themes/components/table.py +1 -1
- reflex/components/radix/themes/components/table.pyi +332 -261
- reflex/components/radix/themes/components/tabs.py +1 -1
- reflex/components/radix/themes/components/tabs.pyi +194 -139
- reflex/components/radix/themes/components/text_area.py +1 -1
- reflex/components/radix/themes/components/text_area.pyi +111 -96
- reflex/components/radix/themes/components/text_field.py +1 -1
- reflex/components/radix/themes/components/text_field.pyi +286 -247
- reflex/components/radix/themes/components/tooltip.py +1 -1
- reflex/components/radix/themes/components/tooltip.pyi +37 -26
- reflex/components/radix/themes/layout/__init__.pyi +0 -1
- reflex/components/radix/themes/layout/base.py +1 -1
- reflex/components/radix/themes/layout/base.pyi +67 -56
- reflex/components/radix/themes/layout/box.pyi +45 -34
- reflex/components/radix/themes/layout/center.pyi +67 -56
- reflex/components/radix/themes/layout/container.py +2 -1
- reflex/components/radix/themes/layout/container.pyi +47 -36
- reflex/components/radix/themes/layout/flex.py +1 -1
- reflex/components/radix/themes/layout/flex.pyi +67 -56
- reflex/components/radix/themes/layout/grid.py +1 -1
- reflex/components/radix/themes/layout/grid.pyi +75 -64
- reflex/components/radix/themes/layout/list.py +6 -5
- reflex/components/radix/themes/layout/list.pyi +244 -193
- reflex/components/radix/themes/layout/section.py +2 -1
- reflex/components/radix/themes/layout/section.pyi +47 -36
- reflex/components/radix/themes/layout/spacer.pyi +67 -56
- reflex/components/radix/themes/layout/stack.py +1 -1
- reflex/components/radix/themes/layout/stack.pyi +159 -128
- reflex/components/radix/themes/typography/blockquote.py +1 -1
- reflex/components/radix/themes/typography/blockquote.pyi +100 -89
- reflex/components/radix/themes/typography/code.py +1 -1
- reflex/components/radix/themes/typography/code.pyi +101 -90
- reflex/components/radix/themes/typography/heading.py +1 -1
- reflex/components/radix/themes/typography/heading.pyi +107 -96
- reflex/components/radix/themes/typography/link.py +1 -1
- reflex/components/radix/themes/typography/link.pyi +113 -102
- reflex/components/radix/themes/typography/text.py +1 -1
- reflex/components/radix/themes/typography/text.pyi +572 -501
- reflex/components/react_player/audio.pyi +60 -33
- reflex/components/react_player/react_player.py +1 -1
- reflex/components/react_player/react_player.pyi +60 -33
- reflex/components/react_player/video.pyi +60 -33
- reflex/components/recharts/cartesian.py +3 -2
- reflex/components/recharts/cartesian.pyi +861 -678
- reflex/components/recharts/charts.py +5 -4
- reflex/components/recharts/charts.pyi +357 -252
- reflex/components/recharts/general.py +2 -1
- reflex/components/recharts/general.pyi +231 -180
- reflex/components/recharts/polar.py +5 -4
- reflex/components/recharts/polar.pyi +181 -144
- reflex/components/recharts/recharts.pyi +53 -33
- reflex/components/sonner/toast.py +17 -16
- reflex/components/sonner/toast.pyi +47 -36
- reflex/components/suneditor/editor.py +3 -2
- reflex/components/suneditor/editor.pyi +78 -55
- reflex/components/tags/cond_tag.py +4 -6
- reflex/components/tags/iter_tag.py +16 -28
- reflex/components/tags/match_tag.py +4 -6
- reflex/components/tags/tag.py +23 -40
- reflex/custom_components/custom_components.py +1 -3
- reflex/event.py +65 -113
- reflex/experimental/client_state.py +24 -25
- reflex/experimental/hooks.py +16 -16
- reflex/experimental/layout.py +5 -5
- reflex/experimental/layout.pyi +187 -136
- reflex/{vars → ivars}/__init__.py +2 -6
- reflex/{vars → ivars}/base.py +216 -599
- reflex/{vars → ivars}/function.py +19 -15
- reflex/{vars → ivars}/number.py +20 -41
- reflex/{vars → ivars}/object.py +30 -28
- reflex/{vars → ivars}/sequence.py +50 -53
- reflex/middleware/hydrate_middleware.py +0 -2
- reflex/middleware/middleware.py +3 -3
- reflex/state.py +82 -148
- reflex/style.py +22 -21
- reflex/utils/exceptions.py +0 -20
- reflex/utils/format.py +34 -54
- reflex/utils/imports.py +73 -16
- reflex/utils/prerequisites.py +15 -35
- reflex/utils/pyi_generator.py +8 -13
- reflex/utils/serializers.py +22 -12
- reflex/utils/telemetry.py +2 -3
- reflex/utils/types.py +5 -10
- reflex/vars.py +501 -0
- {reflex-0.6.0.dist-info → reflex-0.6.0a1.dist-info}/METADATA +5 -4
- reflex-0.6.0a1.dist-info/RECORD +384 -0
- reflex-0.6.0.dist-info/RECORD +0 -382
- {reflex-0.6.0.dist-info → reflex-0.6.0a1.dist-info}/LICENSE +0 -0
- {reflex-0.6.0.dist-info → reflex-0.6.0a1.dist-info}/WHEEL +0 -0
- {reflex-0.6.0.dist-info → reflex-0.6.0a1.dist-info}/entry_points.txt +0 -0
|
@@ -7,21 +7,21 @@ import sys
|
|
|
7
7
|
from typing import Any, Callable, ClassVar, Optional, Tuple, Type, Union
|
|
8
8
|
|
|
9
9
|
from reflex.utils.types import GenericType
|
|
10
|
+
from reflex.vars import VarData
|
|
10
11
|
|
|
11
12
|
from .base import (
|
|
12
13
|
CachedVarOperation,
|
|
14
|
+
ImmutableVar,
|
|
13
15
|
LiteralVar,
|
|
14
16
|
ToOperation,
|
|
15
|
-
Var,
|
|
16
|
-
VarData,
|
|
17
17
|
cached_property_no_lock,
|
|
18
18
|
)
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
class FunctionVar(
|
|
21
|
+
class FunctionVar(ImmutableVar[Callable]):
|
|
22
22
|
"""Base class for immutable function vars."""
|
|
23
23
|
|
|
24
|
-
def __call__(self, *args:
|
|
24
|
+
def __call__(self, *args: ImmutableVar | Any) -> ArgsFunctionOperation:
|
|
25
25
|
"""Call the function with the given arguments.
|
|
26
26
|
|
|
27
27
|
Args:
|
|
@@ -32,10 +32,10 @@ class FunctionVar(Var[Callable]):
|
|
|
32
32
|
"""
|
|
33
33
|
return ArgsFunctionOperation.create(
|
|
34
34
|
("...args",),
|
|
35
|
-
VarOperationCall.create(self, *args,
|
|
35
|
+
VarOperationCall.create(self, *args, ImmutableVar.create_safe("...args")),
|
|
36
36
|
)
|
|
37
37
|
|
|
38
|
-
def call(self, *args:
|
|
38
|
+
def call(self, *args: ImmutableVar | Any) -> VarOperationCall:
|
|
39
39
|
"""Call the function with the given arguments.
|
|
40
40
|
|
|
41
41
|
Args:
|
|
@@ -67,7 +67,7 @@ class FunctionStringVar(FunctionVar):
|
|
|
67
67
|
The function var.
|
|
68
68
|
"""
|
|
69
69
|
return cls(
|
|
70
|
-
|
|
70
|
+
_var_name=func,
|
|
71
71
|
_var_type=_var_type,
|
|
72
72
|
_var_data=_var_data,
|
|
73
73
|
)
|
|
@@ -78,11 +78,13 @@ class FunctionStringVar(FunctionVar):
|
|
|
78
78
|
frozen=True,
|
|
79
79
|
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
80
80
|
)
|
|
81
|
-
class VarOperationCall(CachedVarOperation,
|
|
81
|
+
class VarOperationCall(CachedVarOperation, ImmutableVar):
|
|
82
82
|
"""Base class for immutable vars that are the result of a function call."""
|
|
83
83
|
|
|
84
84
|
_func: Optional[FunctionVar] = dataclasses.field(default=None)
|
|
85
|
-
_args: Tuple[Union[
|
|
85
|
+
_args: Tuple[Union[ImmutableVar, Any], ...] = dataclasses.field(
|
|
86
|
+
default_factory=tuple
|
|
87
|
+
)
|
|
86
88
|
|
|
87
89
|
@cached_property_no_lock
|
|
88
90
|
def _cached_var_name(self) -> str:
|
|
@@ -110,7 +112,7 @@ class VarOperationCall(CachedVarOperation, Var):
|
|
|
110
112
|
def create(
|
|
111
113
|
cls,
|
|
112
114
|
func: FunctionVar,
|
|
113
|
-
*args:
|
|
115
|
+
*args: ImmutableVar | Any,
|
|
114
116
|
_var_type: GenericType = Any,
|
|
115
117
|
_var_data: VarData | None = None,
|
|
116
118
|
) -> VarOperationCall:
|
|
@@ -125,7 +127,7 @@ class VarOperationCall(CachedVarOperation, Var):
|
|
|
125
127
|
The function call var.
|
|
126
128
|
"""
|
|
127
129
|
return cls(
|
|
128
|
-
|
|
130
|
+
_var_name="",
|
|
129
131
|
_var_type=_var_type,
|
|
130
132
|
_var_data=_var_data,
|
|
131
133
|
_func=func,
|
|
@@ -142,7 +144,7 @@ class ArgsFunctionOperation(CachedVarOperation, FunctionVar):
|
|
|
142
144
|
"""Base class for immutable function defined via arguments and return expression."""
|
|
143
145
|
|
|
144
146
|
_args_names: Tuple[str, ...] = dataclasses.field(default_factory=tuple)
|
|
145
|
-
_return_expr: Union[
|
|
147
|
+
_return_expr: Union[ImmutableVar, Any] = dataclasses.field(default=None)
|
|
146
148
|
|
|
147
149
|
@cached_property_no_lock
|
|
148
150
|
def _cached_var_name(self) -> str:
|
|
@@ -157,7 +159,7 @@ class ArgsFunctionOperation(CachedVarOperation, FunctionVar):
|
|
|
157
159
|
def create(
|
|
158
160
|
cls,
|
|
159
161
|
args_names: Tuple[str, ...],
|
|
160
|
-
return_expr:
|
|
162
|
+
return_expr: ImmutableVar | Any,
|
|
161
163
|
_var_type: GenericType = Callable,
|
|
162
164
|
_var_data: VarData | None = None,
|
|
163
165
|
) -> ArgsFunctionOperation:
|
|
@@ -172,7 +174,7 @@ class ArgsFunctionOperation(CachedVarOperation, FunctionVar):
|
|
|
172
174
|
The function var.
|
|
173
175
|
"""
|
|
174
176
|
return cls(
|
|
175
|
-
|
|
177
|
+
_var_name="",
|
|
176
178
|
_var_type=_var_type,
|
|
177
179
|
_var_data=_var_data,
|
|
178
180
|
_args_names=args_names,
|
|
@@ -188,7 +190,9 @@ class ArgsFunctionOperation(CachedVarOperation, FunctionVar):
|
|
|
188
190
|
class ToFunctionOperation(ToOperation, FunctionVar):
|
|
189
191
|
"""Base class of converting a var to a function."""
|
|
190
192
|
|
|
191
|
-
_original:
|
|
193
|
+
_original: ImmutableVar = dataclasses.field(
|
|
194
|
+
default_factory=lambda: LiteralVar.create(None)
|
|
195
|
+
)
|
|
192
196
|
|
|
193
197
|
_default_var_type: ClassVar[GenericType] = Callable
|
|
194
198
|
|
reflex/{vars → ivars}/number.py
RENAMED
|
@@ -4,7 +4,6 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import dataclasses
|
|
6
6
|
import json
|
|
7
|
-
import math
|
|
8
7
|
import sys
|
|
9
8
|
from typing import (
|
|
10
9
|
TYPE_CHECKING,
|
|
@@ -18,17 +17,15 @@ from typing import (
|
|
|
18
17
|
overload,
|
|
19
18
|
)
|
|
20
19
|
|
|
21
|
-
from reflex.
|
|
22
|
-
from reflex.
|
|
23
|
-
from reflex.utils.imports import ImportDict, ImportVar
|
|
20
|
+
from reflex.utils.exceptions import VarTypeError
|
|
21
|
+
from reflex.vars import Var, VarData
|
|
24
22
|
|
|
25
23
|
from .base import (
|
|
26
24
|
CustomVarOperationReturn,
|
|
25
|
+
ImmutableVar,
|
|
27
26
|
LiteralNoneVar,
|
|
28
27
|
LiteralVar,
|
|
29
28
|
ToOperation,
|
|
30
|
-
Var,
|
|
31
|
-
VarData,
|
|
32
29
|
unionize,
|
|
33
30
|
var_operation,
|
|
34
31
|
var_operation_return,
|
|
@@ -57,7 +54,7 @@ def raise_unsupported_operand_types(
|
|
|
57
54
|
)
|
|
58
55
|
|
|
59
56
|
|
|
60
|
-
class NumberVar(
|
|
57
|
+
class NumberVar(ImmutableVar[NUMBER_T]):
|
|
61
58
|
"""Base class for immutable number vars."""
|
|
62
59
|
|
|
63
60
|
@overload
|
|
@@ -851,8 +848,8 @@ def boolean_to_number_operation(value: BooleanVar):
|
|
|
851
848
|
|
|
852
849
|
|
|
853
850
|
def comparison_operator(
|
|
854
|
-
func: Callable[[
|
|
855
|
-
) -> Callable[[
|
|
851
|
+
func: Callable[[ImmutableVar, ImmutableVar], str],
|
|
852
|
+
) -> Callable[[ImmutableVar | Any, ImmutableVar | Any], BooleanVar]:
|
|
856
853
|
"""Decorator to create a comparison operation.
|
|
857
854
|
|
|
858
855
|
Args:
|
|
@@ -863,13 +860,13 @@ def comparison_operator(
|
|
|
863
860
|
"""
|
|
864
861
|
|
|
865
862
|
@var_operation
|
|
866
|
-
def operation(lhs:
|
|
863
|
+
def operation(lhs: ImmutableVar, rhs: ImmutableVar):
|
|
867
864
|
return var_operation_return(
|
|
868
865
|
js_expression=func(lhs, rhs),
|
|
869
866
|
var_type=bool,
|
|
870
867
|
)
|
|
871
868
|
|
|
872
|
-
def wrapper(lhs:
|
|
869
|
+
def wrapper(lhs: ImmutableVar | Any, rhs: ImmutableVar | Any) -> BooleanVar:
|
|
873
870
|
"""Create the comparison operation.
|
|
874
871
|
|
|
875
872
|
Args:
|
|
@@ -885,7 +882,7 @@ def comparison_operator(
|
|
|
885
882
|
|
|
886
883
|
|
|
887
884
|
@comparison_operator
|
|
888
|
-
def greater_than_operation(lhs:
|
|
885
|
+
def greater_than_operation(lhs: ImmutableVar, rhs: ImmutableVar):
|
|
889
886
|
"""Greater than comparison.
|
|
890
887
|
|
|
891
888
|
Args:
|
|
@@ -899,7 +896,7 @@ def greater_than_operation(lhs: Var, rhs: Var):
|
|
|
899
896
|
|
|
900
897
|
|
|
901
898
|
@comparison_operator
|
|
902
|
-
def greater_than_or_equal_operation(lhs:
|
|
899
|
+
def greater_than_or_equal_operation(lhs: ImmutableVar, rhs: ImmutableVar):
|
|
903
900
|
"""Greater than or equal comparison.
|
|
904
901
|
|
|
905
902
|
Args:
|
|
@@ -913,7 +910,7 @@ def greater_than_or_equal_operation(lhs: Var, rhs: Var):
|
|
|
913
910
|
|
|
914
911
|
|
|
915
912
|
@comparison_operator
|
|
916
|
-
def less_than_operation(lhs:
|
|
913
|
+
def less_than_operation(lhs: ImmutableVar, rhs: ImmutableVar):
|
|
917
914
|
"""Less than comparison.
|
|
918
915
|
|
|
919
916
|
Args:
|
|
@@ -927,7 +924,7 @@ def less_than_operation(lhs: Var, rhs: Var):
|
|
|
927
924
|
|
|
928
925
|
|
|
929
926
|
@comparison_operator
|
|
930
|
-
def less_than_or_equal_operation(lhs:
|
|
927
|
+
def less_than_or_equal_operation(lhs: ImmutableVar, rhs: ImmutableVar):
|
|
931
928
|
"""Less than or equal comparison.
|
|
932
929
|
|
|
933
930
|
Args:
|
|
@@ -941,7 +938,7 @@ def less_than_or_equal_operation(lhs: Var, rhs: Var):
|
|
|
941
938
|
|
|
942
939
|
|
|
943
940
|
@comparison_operator
|
|
944
|
-
def equal_operation(lhs:
|
|
941
|
+
def equal_operation(lhs: ImmutableVar, rhs: ImmutableVar):
|
|
945
942
|
"""Equal comparison.
|
|
946
943
|
|
|
947
944
|
Args:
|
|
@@ -955,7 +952,7 @@ def equal_operation(lhs: Var, rhs: Var):
|
|
|
955
952
|
|
|
956
953
|
|
|
957
954
|
@comparison_operator
|
|
958
|
-
def not_equal_operation(lhs:
|
|
955
|
+
def not_equal_operation(lhs: ImmutableVar, rhs: ImmutableVar):
|
|
959
956
|
"""Not equal comparison.
|
|
960
957
|
|
|
961
958
|
Args:
|
|
@@ -1019,7 +1016,7 @@ class LiteralBooleanVar(LiteralVar, BooleanVar):
|
|
|
1019
1016
|
The boolean var.
|
|
1020
1017
|
"""
|
|
1021
1018
|
return cls(
|
|
1022
|
-
|
|
1019
|
+
_var_name="true" if value else "false",
|
|
1023
1020
|
_var_type=bool,
|
|
1024
1021
|
_var_data=_var_data,
|
|
1025
1022
|
_var_value=value,
|
|
@@ -1041,14 +1038,7 @@ class LiteralNumberVar(LiteralVar, NumberVar):
|
|
|
1041
1038
|
|
|
1042
1039
|
Returns:
|
|
1043
1040
|
The JSON representation of the var.
|
|
1044
|
-
|
|
1045
|
-
Raises:
|
|
1046
|
-
PrimitiveUnserializableToJSON: If the var is unserializable to JSON.
|
|
1047
1041
|
"""
|
|
1048
|
-
if math.isinf(self._var_value) or math.isnan(self._var_value):
|
|
1049
|
-
raise PrimitiveUnserializableToJSON(
|
|
1050
|
-
f"No valid JSON representation for {self}"
|
|
1051
|
-
)
|
|
1052
1042
|
return json.dumps(self._var_value)
|
|
1053
1043
|
|
|
1054
1044
|
def __hash__(self) -> int:
|
|
@@ -1070,15 +1060,8 @@ class LiteralNumberVar(LiteralVar, NumberVar):
|
|
|
1070
1060
|
Returns:
|
|
1071
1061
|
The number var.
|
|
1072
1062
|
"""
|
|
1073
|
-
if math.isinf(value):
|
|
1074
|
-
js_expr = "Infinity" if value > 0 else "-Infinity"
|
|
1075
|
-
elif math.isnan(value):
|
|
1076
|
-
js_expr = "NaN"
|
|
1077
|
-
else:
|
|
1078
|
-
js_expr = str(value)
|
|
1079
|
-
|
|
1080
1063
|
return cls(
|
|
1081
|
-
|
|
1064
|
+
_var_name=str(value),
|
|
1082
1065
|
_var_type=type(value),
|
|
1083
1066
|
_var_data=_var_data,
|
|
1084
1067
|
_var_value=value,
|
|
@@ -1115,11 +1098,6 @@ class ToBooleanVarOperation(ToOperation, BooleanVar):
|
|
|
1115
1098
|
_default_var_type: ClassVar[Type] = bool
|
|
1116
1099
|
|
|
1117
1100
|
|
|
1118
|
-
_IS_TRUE_IMPORT: ImportDict = {
|
|
1119
|
-
f"/{Dirs.STATE_PATH}": [ImportVar(tag="isTrue")],
|
|
1120
|
-
}
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
1101
|
@var_operation
|
|
1124
1102
|
def boolify(value: Var):
|
|
1125
1103
|
"""Convert the value to a boolean.
|
|
@@ -1131,14 +1109,15 @@ def boolify(value: Var):
|
|
|
1131
1109
|
The boolean value.
|
|
1132
1110
|
"""
|
|
1133
1111
|
return var_operation_return(
|
|
1134
|
-
js_expression=f"
|
|
1112
|
+
js_expression=f"Boolean({value})",
|
|
1135
1113
|
var_type=bool,
|
|
1136
|
-
var_data=VarData(imports=_IS_TRUE_IMPORT),
|
|
1137
1114
|
)
|
|
1138
1115
|
|
|
1139
1116
|
|
|
1140
1117
|
@var_operation
|
|
1141
|
-
def ternary_operation(
|
|
1118
|
+
def ternary_operation(
|
|
1119
|
+
condition: BooleanVar, if_true: ImmutableVar, if_false: ImmutableVar
|
|
1120
|
+
):
|
|
1142
1121
|
"""Create a ternary operation.
|
|
1143
1122
|
|
|
1144
1123
|
Args:
|
reflex/{vars → ivars}/object.py
RENAMED
|
@@ -23,13 +23,13 @@ from typing import (
|
|
|
23
23
|
from reflex.utils import types
|
|
24
24
|
from reflex.utils.exceptions import VarAttributeError
|
|
25
25
|
from reflex.utils.types import GenericType, get_attribute_access_type, get_origin
|
|
26
|
+
from reflex.vars import VarData
|
|
26
27
|
|
|
27
28
|
from .base import (
|
|
28
29
|
CachedVarOperation,
|
|
30
|
+
ImmutableVar,
|
|
29
31
|
LiteralVar,
|
|
30
32
|
ToOperation,
|
|
31
|
-
Var,
|
|
32
|
-
VarData,
|
|
33
33
|
cached_property_no_lock,
|
|
34
34
|
figure_out_type,
|
|
35
35
|
var_operation,
|
|
@@ -48,7 +48,7 @@ ARRAY_INNER_TYPE = TypeVar("ARRAY_INNER_TYPE")
|
|
|
48
48
|
OTHER_KEY_TYPE = TypeVar("OTHER_KEY_TYPE")
|
|
49
49
|
|
|
50
50
|
|
|
51
|
-
class ObjectVar(
|
|
51
|
+
class ObjectVar(ImmutableVar[OBJECT_TYPE]):
|
|
52
52
|
"""Base class for immutable object vars."""
|
|
53
53
|
|
|
54
54
|
def _key_type(self) -> Type:
|
|
@@ -134,8 +134,8 @@ class ObjectVar(Var[OBJECT_TYPE]):
|
|
|
134
134
|
@overload
|
|
135
135
|
def __getitem__(
|
|
136
136
|
self: ObjectVar[Dict[KEY_TYPE, NoReturn]],
|
|
137
|
-
key:
|
|
138
|
-
) ->
|
|
137
|
+
key: ImmutableVar | Any,
|
|
138
|
+
) -> ImmutableVar: ...
|
|
139
139
|
|
|
140
140
|
@overload
|
|
141
141
|
def __getitem__(
|
|
@@ -144,40 +144,40 @@ class ObjectVar(Var[OBJECT_TYPE]):
|
|
|
144
144
|
| ObjectVar[Dict[KEY_TYPE, float]]
|
|
145
145
|
| ObjectVar[Dict[KEY_TYPE, int | float]]
|
|
146
146
|
),
|
|
147
|
-
key:
|
|
147
|
+
key: ImmutableVar | Any,
|
|
148
148
|
) -> NumberVar: ...
|
|
149
149
|
|
|
150
150
|
@overload
|
|
151
151
|
def __getitem__(
|
|
152
152
|
self: ObjectVar[Dict[KEY_TYPE, str]],
|
|
153
|
-
key:
|
|
153
|
+
key: ImmutableVar | Any,
|
|
154
154
|
) -> StringVar: ...
|
|
155
155
|
|
|
156
156
|
@overload
|
|
157
157
|
def __getitem__(
|
|
158
158
|
self: ObjectVar[Dict[KEY_TYPE, list[ARRAY_INNER_TYPE]]],
|
|
159
|
-
key:
|
|
159
|
+
key: ImmutableVar | Any,
|
|
160
160
|
) -> ArrayVar[list[ARRAY_INNER_TYPE]]: ...
|
|
161
161
|
|
|
162
162
|
@overload
|
|
163
163
|
def __getitem__(
|
|
164
164
|
self: ObjectVar[Dict[KEY_TYPE, set[ARRAY_INNER_TYPE]]],
|
|
165
|
-
key:
|
|
165
|
+
key: ImmutableVar | Any,
|
|
166
166
|
) -> ArrayVar[set[ARRAY_INNER_TYPE]]: ...
|
|
167
167
|
|
|
168
168
|
@overload
|
|
169
169
|
def __getitem__(
|
|
170
170
|
self: ObjectVar[Dict[KEY_TYPE, tuple[ARRAY_INNER_TYPE, ...]]],
|
|
171
|
-
key:
|
|
171
|
+
key: ImmutableVar | Any,
|
|
172
172
|
) -> ArrayVar[tuple[ARRAY_INNER_TYPE, ...]]: ...
|
|
173
173
|
|
|
174
174
|
@overload
|
|
175
175
|
def __getitem__(
|
|
176
176
|
self: ObjectVar[Dict[KEY_TYPE, dict[OTHER_KEY_TYPE, VALUE_TYPE]]],
|
|
177
|
-
key:
|
|
177
|
+
key: ImmutableVar | Any,
|
|
178
178
|
) -> ObjectVar[dict[OTHER_KEY_TYPE, VALUE_TYPE]]: ...
|
|
179
179
|
|
|
180
|
-
def __getitem__(self, key:
|
|
180
|
+
def __getitem__(self, key: ImmutableVar | Any) -> ImmutableVar:
|
|
181
181
|
"""Get an item from the object.
|
|
182
182
|
|
|
183
183
|
Args:
|
|
@@ -197,7 +197,7 @@ class ObjectVar(Var[OBJECT_TYPE]):
|
|
|
197
197
|
def __getattr__(
|
|
198
198
|
self: ObjectVar[Dict[KEY_TYPE, NoReturn]],
|
|
199
199
|
name: str,
|
|
200
|
-
) ->
|
|
200
|
+
) -> ImmutableVar: ...
|
|
201
201
|
|
|
202
202
|
@overload
|
|
203
203
|
def __getattr__(
|
|
@@ -239,7 +239,7 @@ class ObjectVar(Var[OBJECT_TYPE]):
|
|
|
239
239
|
name: str,
|
|
240
240
|
) -> ObjectVar[dict[OTHER_KEY_TYPE, VALUE_TYPE]]: ...
|
|
241
241
|
|
|
242
|
-
def __getattr__(self, name) ->
|
|
242
|
+
def __getattr__(self, name) -> ImmutableVar:
|
|
243
243
|
"""Get an attribute of the var.
|
|
244
244
|
|
|
245
245
|
Args:
|
|
@@ -271,7 +271,7 @@ class ObjectVar(Var[OBJECT_TYPE]):
|
|
|
271
271
|
else:
|
|
272
272
|
return ObjectItemOperation.create(self, name).guess_type()
|
|
273
273
|
|
|
274
|
-
def contains(self, key:
|
|
274
|
+
def contains(self, key: ImmutableVar | Any) -> BooleanVar:
|
|
275
275
|
"""Check if the object contains a key.
|
|
276
276
|
|
|
277
277
|
Args:
|
|
@@ -291,8 +291,8 @@ class ObjectVar(Var[OBJECT_TYPE]):
|
|
|
291
291
|
class LiteralObjectVar(CachedVarOperation, ObjectVar[OBJECT_TYPE], LiteralVar):
|
|
292
292
|
"""Base class for immutable literal object vars."""
|
|
293
293
|
|
|
294
|
-
_var_value: Dict[Union[
|
|
295
|
-
default_factory=dict
|
|
294
|
+
_var_value: Dict[Union[ImmutableVar, Any], Union[ImmutableVar, Any]] = (
|
|
295
|
+
dataclasses.field(default_factory=dict)
|
|
296
296
|
)
|
|
297
297
|
|
|
298
298
|
def _key_type(self) -> Type:
|
|
@@ -354,7 +354,7 @@ class LiteralObjectVar(CachedVarOperation, ObjectVar[OBJECT_TYPE], LiteralVar):
|
|
|
354
354
|
Returns:
|
|
355
355
|
The hash of the var.
|
|
356
356
|
"""
|
|
357
|
-
return hash((self.__class__.__name__, self.
|
|
357
|
+
return hash((self.__class__.__name__, self._var_name))
|
|
358
358
|
|
|
359
359
|
@cached_property_no_lock
|
|
360
360
|
def _cached_get_all_var_data(self) -> VarData | None:
|
|
@@ -390,7 +390,7 @@ class LiteralObjectVar(CachedVarOperation, ObjectVar[OBJECT_TYPE], LiteralVar):
|
|
|
390
390
|
The literal object var.
|
|
391
391
|
"""
|
|
392
392
|
return LiteralObjectVar(
|
|
393
|
-
|
|
393
|
+
_var_name="",
|
|
394
394
|
_var_type=(figure_out_type(_var_value) if _var_type is None else _var_type),
|
|
395
395
|
_var_data=_var_data,
|
|
396
396
|
_var_value=_var_value,
|
|
@@ -470,13 +470,15 @@ def object_merge_operation(lhs: ObjectVar, rhs: ObjectVar):
|
|
|
470
470
|
frozen=True,
|
|
471
471
|
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
472
472
|
)
|
|
473
|
-
class ObjectItemOperation(CachedVarOperation,
|
|
473
|
+
class ObjectItemOperation(CachedVarOperation, ImmutableVar):
|
|
474
474
|
"""Operation to get an item from an object."""
|
|
475
475
|
|
|
476
476
|
_object: ObjectVar = dataclasses.field(
|
|
477
477
|
default_factory=lambda: LiteralObjectVar.create({})
|
|
478
478
|
)
|
|
479
|
-
_key:
|
|
479
|
+
_key: ImmutableVar | Any = dataclasses.field(
|
|
480
|
+
default_factory=lambda: LiteralVar.create(None)
|
|
481
|
+
)
|
|
480
482
|
|
|
481
483
|
@cached_property_no_lock
|
|
482
484
|
def _cached_var_name(self) -> str:
|
|
@@ -493,7 +495,7 @@ class ObjectItemOperation(CachedVarOperation, Var):
|
|
|
493
495
|
def create(
|
|
494
496
|
cls,
|
|
495
497
|
object: ObjectVar,
|
|
496
|
-
key:
|
|
498
|
+
key: ImmutableVar | Any,
|
|
497
499
|
_var_type: GenericType | None = None,
|
|
498
500
|
_var_data: VarData | None = None,
|
|
499
501
|
) -> ObjectItemOperation:
|
|
@@ -509,11 +511,11 @@ class ObjectItemOperation(CachedVarOperation, Var):
|
|
|
509
511
|
The object item operation.
|
|
510
512
|
"""
|
|
511
513
|
return cls(
|
|
512
|
-
|
|
514
|
+
_var_name="",
|
|
513
515
|
_var_type=object._value_type() if _var_type is None else _var_type,
|
|
514
516
|
_var_data=_var_data,
|
|
515
517
|
_object=object,
|
|
516
|
-
_key=key if isinstance(key,
|
|
518
|
+
_key=key if isinstance(key, ImmutableVar) else LiteralVar.create(key),
|
|
517
519
|
)
|
|
518
520
|
|
|
519
521
|
|
|
@@ -525,7 +527,7 @@ class ObjectItemOperation(CachedVarOperation, Var):
|
|
|
525
527
|
class ToObjectOperation(ToOperation, ObjectVar):
|
|
526
528
|
"""Operation to convert a var to an object."""
|
|
527
529
|
|
|
528
|
-
_original:
|
|
530
|
+
_original: ImmutableVar = dataclasses.field(
|
|
529
531
|
default_factory=lambda: LiteralObjectVar.create({})
|
|
530
532
|
)
|
|
531
533
|
|
|
@@ -540,13 +542,13 @@ class ToObjectOperation(ToOperation, ObjectVar):
|
|
|
540
542
|
Returns:
|
|
541
543
|
The attribute of the var.
|
|
542
544
|
"""
|
|
543
|
-
if name == "
|
|
544
|
-
return self._original.
|
|
545
|
+
if name == "_var_name":
|
|
546
|
+
return self._original._var_name
|
|
545
547
|
return ObjectVar.__getattr__(self, name)
|
|
546
548
|
|
|
547
549
|
|
|
548
550
|
@var_operation
|
|
549
|
-
def object_has_own_property_operation(object: ObjectVar, key:
|
|
551
|
+
def object_has_own_property_operation(object: ObjectVar, key: ImmutableVar):
|
|
550
552
|
"""Check if an object has a key.
|
|
551
553
|
|
|
552
554
|
Args:
|