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