reflex 0.7.7a1__py3-none-any.whl → 0.7.8__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/web/utils/state.js +26 -16
- reflex/admin.py +1 -1
- reflex/app.py +6 -17
- reflex/app_mixins/lifespan.py +1 -1
- reflex/base.py +2 -2
- reflex/compiler/compiler.py +8 -7
- reflex/compiler/utils.py +6 -5
- reflex/components/base/app_wrap.pyi +18 -17
- reflex/components/base/bare.py +2 -1
- reflex/components/base/body.pyi +18 -17
- reflex/components/base/document.pyi +82 -81
- reflex/components/base/error_boundary.pyi +19 -18
- reflex/components/base/fragment.pyi +18 -17
- reflex/components/base/head.pyi +34 -33
- reflex/components/base/link.pyi +34 -33
- reflex/components/base/meta.pyi +66 -65
- reflex/components/base/script.pyi +21 -20
- reflex/components/base/strict_mode.pyi +18 -17
- reflex/components/component.py +20 -36
- reflex/components/core/auto_scroll.pyi +18 -17
- reflex/components/core/banner.pyi +98 -97
- reflex/components/core/breakpoints.py +1 -1
- reflex/components/core/client_side_routing.pyi +34 -33
- reflex/components/core/clipboard.py +1 -1
- reflex/components/core/clipboard.pyi +19 -18
- reflex/components/core/cond.py +2 -2
- reflex/components/core/debounce.py +3 -3
- reflex/components/core/debounce.pyi +20 -19
- reflex/components/core/foreach.py +2 -1
- reflex/components/core/html.pyi +18 -17
- reflex/components/core/match.py +2 -2
- reflex/components/core/sticky.pyi +66 -65
- reflex/components/core/upload.py +7 -10
- reflex/components/core/upload.pyi +86 -85
- reflex/components/datadisplay/code.pyi +34 -33
- reflex/components/datadisplay/dataeditor.py +3 -2
- reflex/components/datadisplay/dataeditor.pyi +35 -68
- reflex/components/datadisplay/shiki_code_block.pyi +50 -49
- reflex/components/el/element.pyi +18 -17
- reflex/components/el/elements/base.pyi +18 -17
- reflex/components/el/elements/forms.py +10 -8
- reflex/components/el/elements/forms.pyi +290 -332
- reflex/components/el/elements/inline.pyi +450 -449
- reflex/components/el/elements/media.pyi +402 -401
- reflex/components/el/elements/metadata.pyi +98 -97
- reflex/components/el/elements/other.pyi +114 -113
- reflex/components/el/elements/scripts.pyi +50 -49
- reflex/components/el/elements/sectioning.pyi +242 -241
- reflex/components/el/elements/tables.pyi +162 -161
- reflex/components/el/elements/typography.pyi +242 -241
- reflex/components/gridjs/datatable.py +3 -2
- reflex/components/gridjs/datatable.pyi +35 -34
- reflex/components/lucide/icon.pyi +50 -49
- reflex/components/markdown/markdown.py +2 -1
- reflex/components/markdown/markdown.pyi +18 -17
- reflex/components/moment/moment.pyi +19 -18
- reflex/components/next/base.pyi +18 -17
- reflex/components/next/image.pyi +20 -19
- reflex/components/next/link.pyi +18 -17
- reflex/components/next/video.pyi +18 -17
- reflex/components/plotly/plotly.py +3 -3
- reflex/components/plotly/plotly.pyi +326 -325
- reflex/components/radix/primitives/accordion.py +2 -1
- reflex/components/radix/primitives/accordion.pyi +115 -114
- reflex/components/radix/primitives/base.pyi +34 -33
- reflex/components/radix/primitives/drawer.py +2 -1
- reflex/components/radix/primitives/drawer.pyi +187 -186
- reflex/components/radix/primitives/form.pyi +168 -182
- reflex/components/radix/primitives/progress.pyi +82 -81
- reflex/components/radix/primitives/slider.py +2 -1
- reflex/components/radix/primitives/slider.pyi +84 -83
- reflex/components/radix/themes/base.pyi +130 -129
- reflex/components/radix/themes/color_mode.pyi +51 -50
- reflex/components/radix/themes/components/alert_dialog.pyi +118 -117
- reflex/components/radix/themes/components/aspect_ratio.pyi +18 -17
- reflex/components/radix/themes/components/avatar.pyi +18 -17
- reflex/components/radix/themes/components/badge.pyi +18 -17
- reflex/components/radix/themes/components/button.pyi +18 -17
- reflex/components/radix/themes/components/callout.pyi +82 -81
- reflex/components/radix/themes/components/card.pyi +18 -17
- reflex/components/radix/themes/components/checkbox.pyi +53 -52
- reflex/components/radix/themes/components/checkbox_cards.pyi +34 -33
- reflex/components/radix/themes/components/checkbox_group.py +2 -1
- reflex/components/radix/themes/components/checkbox_group.pyi +34 -33
- reflex/components/radix/themes/components/context_menu.pyi +225 -224
- reflex/components/radix/themes/components/data_list.pyi +66 -65
- reflex/components/radix/themes/components/dialog.pyi +121 -120
- reflex/components/radix/themes/components/dropdown_menu.pyi +142 -141
- reflex/components/radix/themes/components/hover_card.pyi +68 -67
- reflex/components/radix/themes/components/icon_button.pyi +18 -17
- reflex/components/radix/themes/components/inset.pyi +18 -17
- reflex/components/radix/themes/components/popover.pyi +73 -72
- reflex/components/radix/themes/components/progress.pyi +18 -17
- reflex/components/radix/themes/components/radio.pyi +18 -17
- reflex/components/radix/themes/components/radio_cards.pyi +35 -34
- reflex/components/radix/themes/components/radio_group.py +2 -1
- reflex/components/radix/themes/components/radio_group.pyi +67 -66
- reflex/components/radix/themes/components/scroll_area.pyi +18 -17
- reflex/components/radix/themes/components/segmented_control.py +2 -1
- reflex/components/radix/themes/components/segmented_control.pyi +35 -34
- reflex/components/radix/themes/components/select.py +2 -1
- reflex/components/radix/themes/components/select.pyi +155 -154
- reflex/components/radix/themes/components/separator.pyi +18 -17
- reflex/components/radix/themes/components/skeleton.pyi +18 -17
- reflex/components/radix/themes/components/slider.py +2 -1
- reflex/components/radix/themes/components/slider.pyi +20 -31
- reflex/components/radix/themes/components/spinner.pyi +18 -17
- reflex/components/radix/themes/components/switch.pyi +19 -18
- reflex/components/radix/themes/components/table.pyi +114 -113
- reflex/components/radix/themes/components/tabs.pyi +84 -83
- reflex/components/radix/themes/components/text_area.pyi +21 -24
- reflex/components/radix/themes/components/text_field.pyi +56 -63
- reflex/components/radix/themes/components/tooltip.py +2 -2
- reflex/components/radix/themes/components/tooltip.pyi +21 -20
- reflex/components/radix/themes/layout/base.pyi +18 -17
- reflex/components/radix/themes/layout/box.pyi +18 -17
- reflex/components/radix/themes/layout/center.pyi +18 -17
- reflex/components/radix/themes/layout/container.pyi +18 -17
- reflex/components/radix/themes/layout/flex.pyi +18 -17
- reflex/components/radix/themes/layout/grid.pyi +18 -17
- reflex/components/radix/themes/layout/list.py +2 -1
- reflex/components/radix/themes/layout/list.pyi +82 -81
- reflex/components/radix/themes/layout/section.pyi +18 -17
- reflex/components/radix/themes/layout/spacer.pyi +18 -17
- reflex/components/radix/themes/layout/stack.pyi +50 -49
- reflex/components/radix/themes/typography/blockquote.pyi +18 -17
- reflex/components/radix/themes/typography/code.pyi +18 -17
- reflex/components/radix/themes/typography/heading.pyi +18 -17
- reflex/components/radix/themes/typography/link.pyi +18 -17
- reflex/components/radix/themes/typography/text.pyi +114 -113
- reflex/components/react_player/audio.pyi +34 -36
- reflex/components/react_player/react_player.pyi +34 -33
- reflex/components/react_player/video.pyi +34 -36
- reflex/components/recharts/cartesian.py +7 -6
- reflex/components/recharts/cartesian.pyi +302 -301
- reflex/components/recharts/charts.py +2 -1
- reflex/components/recharts/charts.pyi +177 -176
- reflex/components/recharts/general.py +3 -2
- reflex/components/recharts/general.pyi +99 -98
- reflex/components/recharts/polar.py +9 -8
- reflex/components/recharts/polar.pyi +62 -61
- reflex/components/recharts/recharts.pyi +34 -33
- reflex/components/sonner/toast.pyi +19 -18
- reflex/components/suneditor/editor.py +22 -24
- reflex/components/suneditor/editor.pyi +27 -28
- reflex/components/tags/cond_tag.py +3 -3
- reflex/components/tags/iter_tag.py +2 -1
- reflex/components/tags/tag.py +3 -2
- reflex/config.py +27 -17
- reflex/constants/installer.py +4 -4
- reflex/constants/route.py +2 -3
- reflex/constants/utils.py +4 -3
- reflex/event.py +56 -28
- reflex/experimental/client_state.py +3 -2
- reflex/experimental/layout.pyi +84 -83
- reflex/istate/data.py +1 -1
- reflex/istate/storage.py +2 -2
- reflex/model.py +3 -3
- reflex/page.py +3 -2
- reflex/state.py +56 -57
- reflex/style.py +3 -2
- reflex/testing.py +12 -21
- reflex/utils/codespaces.py +14 -15
- reflex/utils/decorator.py +2 -1
- reflex/utils/exec.py +1 -1
- reflex/utils/format.py +2 -2
- reflex/utils/imports.py +6 -8
- reflex/utils/misc.py +2 -1
- reflex/utils/net.py +2 -1
- reflex/utils/prerequisites.py +12 -5
- reflex/utils/processes.py +6 -5
- reflex/utils/pyi_generator.py +6 -5
- reflex/utils/serializers.py +13 -25
- reflex/utils/types.py +34 -46
- reflex/vars/base.py +60 -56
- reflex/vars/dep_tracking.py +4 -4
- reflex/vars/function.py +13 -36
- reflex/vars/number.py +5 -17
- reflex/vars/object.py +9 -16
- reflex/vars/sequence.py +11 -23
- {reflex-0.7.7a1.dist-info → reflex-0.7.8.dist-info}/METADATA +1 -1
- {reflex-0.7.7a1.dist-info → reflex-0.7.8.dist-info}/RECORD +185 -185
- {reflex-0.7.7a1.dist-info → reflex-0.7.8.dist-info}/WHEEL +0 -0
- {reflex-0.7.7a1.dist-info → reflex-0.7.8.dist-info}/entry_points.txt +0 -0
- {reflex-0.7.7a1.dist-info → reflex-0.7.8.dist-info}/licenses/LICENSE +0 -0
reflex/utils/types.py
CHANGED
|
@@ -4,27 +4,20 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import dataclasses
|
|
6
6
|
import inspect
|
|
7
|
-
import sys
|
|
8
7
|
import types
|
|
8
|
+
from collections.abc import Callable, Iterable, Mapping, Sequence
|
|
9
9
|
from functools import cached_property, lru_cache, wraps
|
|
10
10
|
from types import GenericAlias
|
|
11
|
-
from typing import (
|
|
11
|
+
from typing import ( # noqa: UP035
|
|
12
12
|
TYPE_CHECKING,
|
|
13
13
|
Any,
|
|
14
|
-
Callable,
|
|
15
14
|
ClassVar,
|
|
16
15
|
Dict,
|
|
17
16
|
ForwardRef,
|
|
18
|
-
FrozenSet,
|
|
19
|
-
Iterable,
|
|
20
17
|
List,
|
|
21
18
|
Literal,
|
|
22
|
-
Mapping,
|
|
23
19
|
NoReturn,
|
|
24
|
-
Optional,
|
|
25
|
-
Sequence,
|
|
26
20
|
Tuple,
|
|
27
|
-
Type,
|
|
28
21
|
Union,
|
|
29
22
|
_GenericAlias, # pyright: ignore [reportAttributeAccessIssue]
|
|
30
23
|
_SpecialGenericAlias, # pyright: ignore [reportAttributeAccessIssue]
|
|
@@ -55,11 +48,11 @@ GenericAliasTypes = (_GenericAlias, GenericAlias, _SpecialGenericAlias)
|
|
|
55
48
|
UnionTypes = (Union, types.UnionType)
|
|
56
49
|
|
|
57
50
|
# Union of generic types.
|
|
58
|
-
GenericType =
|
|
51
|
+
GenericType = type | _GenericAlias
|
|
59
52
|
|
|
60
53
|
# Valid state var types.
|
|
61
54
|
JSONType = {str, int, float, bool}
|
|
62
|
-
PrimitiveType =
|
|
55
|
+
PrimitiveType = int | float | bool | str | list | dict | set | tuple
|
|
63
56
|
PrimitiveTypes = (int, float, bool, str, list, dict, set, tuple)
|
|
64
57
|
StateVar = PrimitiveType | Base | None
|
|
65
58
|
StateIterVar = list | set | tuple
|
|
@@ -82,9 +75,9 @@ else:
|
|
|
82
75
|
|
|
83
76
|
|
|
84
77
|
PrimitiveToAnnotation = {
|
|
85
|
-
list: List,
|
|
86
|
-
tuple: Tuple,
|
|
87
|
-
dict: Dict,
|
|
78
|
+
list: List, # noqa: UP006
|
|
79
|
+
tuple: Tuple, # noqa: UP006
|
|
80
|
+
dict: Dict, # noqa: UP006
|
|
88
81
|
}
|
|
89
82
|
|
|
90
83
|
RESERVED_BACKEND_VAR_NAMES = {
|
|
@@ -117,7 +110,7 @@ class Unset:
|
|
|
117
110
|
return False
|
|
118
111
|
|
|
119
112
|
|
|
120
|
-
@lru_cache
|
|
113
|
+
@lru_cache
|
|
121
114
|
def get_origin(tp: Any):
|
|
122
115
|
"""Get the origin of a class.
|
|
123
116
|
|
|
@@ -130,7 +123,7 @@ def get_origin(tp: Any):
|
|
|
130
123
|
return get_origin_og(tp)
|
|
131
124
|
|
|
132
125
|
|
|
133
|
-
@lru_cache
|
|
126
|
+
@lru_cache
|
|
134
127
|
def is_generic_alias(cls: GenericType) -> bool:
|
|
135
128
|
"""Check whether the class is a generic alias.
|
|
136
129
|
|
|
@@ -143,8 +136,8 @@ def is_generic_alias(cls: GenericType) -> bool:
|
|
|
143
136
|
return isinstance(cls, GenericAliasTypes)
|
|
144
137
|
|
|
145
138
|
|
|
146
|
-
@lru_cache
|
|
147
|
-
def get_type_hints(obj: Any) ->
|
|
139
|
+
@lru_cache
|
|
140
|
+
def get_type_hints(obj: Any) -> dict[str, Any]:
|
|
148
141
|
"""Get the type hints of a class.
|
|
149
142
|
|
|
150
143
|
Args:
|
|
@@ -156,7 +149,7 @@ def get_type_hints(obj: Any) -> Dict[str, Any]:
|
|
|
156
149
|
return get_type_hints_og(obj)
|
|
157
150
|
|
|
158
151
|
|
|
159
|
-
def _unionize(args: list[GenericType]) ->
|
|
152
|
+
def _unionize(args: list[GenericType]) -> type:
|
|
160
153
|
if not args:
|
|
161
154
|
return Any # pyright: ignore [reportReturnType]
|
|
162
155
|
if len(args) == 1:
|
|
@@ -165,10 +158,10 @@ def _unionize(args: list[GenericType]) -> Type:
|
|
|
165
158
|
# In Python versions >= 3.11, we can simply do `return Union[*args]`
|
|
166
159
|
midpoint = len(args) // 2
|
|
167
160
|
first_half, second_half = args[:midpoint], args[midpoint:]
|
|
168
|
-
return Union[unionize(*first_half), unionize(*second_half)] # pyright: ignore [reportReturnType]
|
|
161
|
+
return Union[unionize(*first_half), unionize(*second_half)] # pyright: ignore [reportReturnType] # noqa: UP007
|
|
169
162
|
|
|
170
163
|
|
|
171
|
-
def unionize(*args: GenericType) ->
|
|
164
|
+
def unionize(*args: GenericType) -> type:
|
|
172
165
|
"""Unionize the types.
|
|
173
166
|
|
|
174
167
|
Args:
|
|
@@ -192,7 +185,7 @@ def is_none(cls: GenericType) -> bool:
|
|
|
192
185
|
return cls is type(None) or cls is None
|
|
193
186
|
|
|
194
187
|
|
|
195
|
-
@lru_cache
|
|
188
|
+
@lru_cache
|
|
196
189
|
def is_union(cls: GenericType) -> bool:
|
|
197
190
|
"""Check if a class is a Union.
|
|
198
191
|
|
|
@@ -205,7 +198,7 @@ def is_union(cls: GenericType) -> bool:
|
|
|
205
198
|
return get_origin(cls) in UnionTypes
|
|
206
199
|
|
|
207
200
|
|
|
208
|
-
@lru_cache
|
|
201
|
+
@lru_cache
|
|
209
202
|
def is_literal(cls: GenericType) -> bool:
|
|
210
203
|
"""Check if a class is a Literal.
|
|
211
204
|
|
|
@@ -218,7 +211,7 @@ def is_literal(cls: GenericType) -> bool:
|
|
|
218
211
|
return get_origin(cls) is Literal
|
|
219
212
|
|
|
220
213
|
|
|
221
|
-
def has_args(cls:
|
|
214
|
+
def has_args(cls: type) -> bool:
|
|
222
215
|
"""Check if the class has generic parameters.
|
|
223
216
|
|
|
224
217
|
Args:
|
|
@@ -273,7 +266,7 @@ def true_type_for_pydantic_field(f: ModelField):
|
|
|
273
266
|
and f.annotation.__forward_arg__.startswith("Optional")
|
|
274
267
|
)
|
|
275
268
|
) and not is_optional(type_):
|
|
276
|
-
return
|
|
269
|
+
return type_ | None
|
|
277
270
|
|
|
278
271
|
return type_
|
|
279
272
|
|
|
@@ -414,10 +407,7 @@ def get_attribute_access_type(cls: GenericType, name: str) -> GenericType | None
|
|
|
414
407
|
)
|
|
415
408
|
elif isinstance(cls, type):
|
|
416
409
|
# Bare class
|
|
417
|
-
|
|
418
|
-
exceptions = NameError
|
|
419
|
-
else:
|
|
420
|
-
exceptions = (NameError, TypeError)
|
|
410
|
+
exceptions = NameError
|
|
421
411
|
try:
|
|
422
412
|
hints = get_type_hints(cls)
|
|
423
413
|
if name in hints:
|
|
@@ -428,8 +418,8 @@ def get_attribute_access_type(cls: GenericType, name: str) -> GenericType | None
|
|
|
428
418
|
return None # Attribute is not accessible.
|
|
429
419
|
|
|
430
420
|
|
|
431
|
-
@lru_cache
|
|
432
|
-
def get_base_class(cls: GenericType) ->
|
|
421
|
+
@lru_cache
|
|
422
|
+
def get_base_class(cls: GenericType) -> type:
|
|
433
423
|
"""Get the base class of a class.
|
|
434
424
|
|
|
435
425
|
Args:
|
|
@@ -548,7 +538,7 @@ def does_obj_satisfy_typed_dict(obj: Any, cls: GenericType) -> bool:
|
|
|
548
538
|
return False
|
|
549
539
|
|
|
550
540
|
key_names_to_values = get_type_hints(cls)
|
|
551
|
-
required_keys:
|
|
541
|
+
required_keys: frozenset[str] = getattr(cls, "__required_keys__", frozenset())
|
|
552
542
|
|
|
553
543
|
if not all(
|
|
554
544
|
isinstance(key, str)
|
|
@@ -730,7 +720,7 @@ def _isinstance(
|
|
|
730
720
|
return isinstance(obj, get_base_class(cls))
|
|
731
721
|
|
|
732
722
|
|
|
733
|
-
def is_dataframe(value:
|
|
723
|
+
def is_dataframe(value: type) -> bool:
|
|
734
724
|
"""Check if the given value is a dataframe.
|
|
735
725
|
|
|
736
726
|
Args:
|
|
@@ -744,7 +734,7 @@ def is_dataframe(value: Type) -> bool:
|
|
|
744
734
|
return value.__name__ == "DataFrame"
|
|
745
735
|
|
|
746
736
|
|
|
747
|
-
def is_valid_var_type(type_:
|
|
737
|
+
def is_valid_var_type(type_: type) -> bool:
|
|
748
738
|
"""Check if the given type is a valid prop type.
|
|
749
739
|
|
|
750
740
|
Args:
|
|
@@ -756,7 +746,7 @@ def is_valid_var_type(type_: Type) -> bool:
|
|
|
756
746
|
from reflex.utils import serializers
|
|
757
747
|
|
|
758
748
|
if is_union(type_):
|
|
759
|
-
return all(
|
|
749
|
+
return all(is_valid_var_type(arg) for arg in get_args(type_))
|
|
760
750
|
return (
|
|
761
751
|
_issubclass(type_, StateVar)
|
|
762
752
|
or serializers.has_serializer(type_)
|
|
@@ -764,7 +754,7 @@ def is_valid_var_type(type_: Type) -> bool:
|
|
|
764
754
|
)
|
|
765
755
|
|
|
766
756
|
|
|
767
|
-
def is_backend_base_variable(name: str, cls:
|
|
757
|
+
def is_backend_base_variable(name: str, cls: type) -> bool:
|
|
768
758
|
"""Check if this variable name correspond to a backend variable.
|
|
769
759
|
|
|
770
760
|
Args:
|
|
@@ -821,7 +811,7 @@ def is_backend_base_variable(name: str, cls: Type) -> bool:
|
|
|
821
811
|
return True
|
|
822
812
|
|
|
823
813
|
|
|
824
|
-
def check_type_in_allowed_types(value_type:
|
|
814
|
+
def check_type_in_allowed_types(value_type: type, allowed_types: Iterable) -> bool:
|
|
825
815
|
"""Check that a value type is found in a list of allowed types.
|
|
826
816
|
|
|
827
817
|
Args:
|
|
@@ -863,7 +853,7 @@ def is_encoded_fstring(value: Any) -> bool:
|
|
|
863
853
|
return isinstance(value, str) and constants.REFLEX_VAR_OPENING_TAG in value
|
|
864
854
|
|
|
865
855
|
|
|
866
|
-
def validate_literal(key: str, value: Any, expected_type:
|
|
856
|
+
def validate_literal(key: str, value: Any, expected_type: type, comp_name: str):
|
|
867
857
|
"""Check that a value is a valid literal.
|
|
868
858
|
|
|
869
859
|
Args:
|
|
@@ -1008,14 +998,12 @@ def typehint_issubclass(
|
|
|
1008
998
|
for arg in args
|
|
1009
999
|
)
|
|
1010
1000
|
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
Union if accepted_type_origin is types.UnionType else accepted_type_origin
|
|
1018
|
-
)
|
|
1001
|
+
provided_type_origin = (
|
|
1002
|
+
Union if provided_type_origin is types.UnionType else provided_type_origin
|
|
1003
|
+
)
|
|
1004
|
+
accepted_type_origin = (
|
|
1005
|
+
Union if accepted_type_origin is types.UnionType else accepted_type_origin
|
|
1006
|
+
)
|
|
1019
1007
|
|
|
1020
1008
|
# Get type arguments (e.g., [float, int] for dict[float, int])
|
|
1021
1009
|
provided_args = get_args(possible_subclass)
|
reflex/vars/base.py
CHANGED
|
@@ -14,30 +14,24 @@ import re
|
|
|
14
14
|
import string
|
|
15
15
|
import uuid
|
|
16
16
|
import warnings
|
|
17
|
+
from collections.abc import Callable, Coroutine, Iterable, Mapping, Sequence
|
|
17
18
|
from types import CodeType, FunctionType
|
|
18
|
-
from typing import (
|
|
19
|
+
from typing import ( # noqa: UP035
|
|
19
20
|
TYPE_CHECKING,
|
|
20
21
|
Any,
|
|
21
|
-
Callable,
|
|
22
22
|
ClassVar,
|
|
23
|
-
Coroutine,
|
|
24
23
|
Dict,
|
|
25
24
|
FrozenSet,
|
|
26
25
|
Generic,
|
|
27
|
-
Iterable,
|
|
28
26
|
List,
|
|
29
27
|
Literal,
|
|
30
|
-
Mapping,
|
|
31
28
|
NoReturn,
|
|
32
29
|
ParamSpec,
|
|
33
30
|
Protocol,
|
|
34
|
-
Sequence,
|
|
35
31
|
Set,
|
|
36
32
|
Tuple,
|
|
37
|
-
Type,
|
|
38
33
|
TypeGuard,
|
|
39
34
|
TypeVar,
|
|
40
|
-
Union,
|
|
41
35
|
cast,
|
|
42
36
|
get_args,
|
|
43
37
|
get_type_hints,
|
|
@@ -102,13 +96,13 @@ warnings.filterwarnings("ignore", message="fields may not start with an undersco
|
|
|
102
96
|
class VarSubclassEntry:
|
|
103
97
|
"""Entry for a Var subclass."""
|
|
104
98
|
|
|
105
|
-
var_subclass:
|
|
106
|
-
to_var_subclass:
|
|
99
|
+
var_subclass: type[Var]
|
|
100
|
+
to_var_subclass: type[ToOperation]
|
|
107
101
|
python_types: tuple[GenericType, ...]
|
|
108
102
|
|
|
109
103
|
|
|
110
104
|
_var_subclasses: list[VarSubclassEntry] = []
|
|
111
|
-
_var_literal_subclasses: list[tuple[
|
|
105
|
+
_var_literal_subclasses: list[tuple[type[LiteralVar], VarSubclassEntry]] = []
|
|
112
106
|
|
|
113
107
|
|
|
114
108
|
@dataclasses.dataclass(
|
|
@@ -137,7 +131,7 @@ class VarData:
|
|
|
137
131
|
position: Hooks.HookPosition | None = None
|
|
138
132
|
|
|
139
133
|
# Components that are part of this var
|
|
140
|
-
components:
|
|
134
|
+
components: tuple[BaseComponent, ...] = dataclasses.field(default_factory=tuple)
|
|
141
135
|
|
|
142
136
|
def __init__(
|
|
143
137
|
self,
|
|
@@ -284,7 +278,7 @@ class VarData:
|
|
|
284
278
|
)
|
|
285
279
|
|
|
286
280
|
@classmethod
|
|
287
|
-
def from_state(cls, state:
|
|
281
|
+
def from_state(cls, state: type[BaseState] | str, field_name: str = "") -> VarData:
|
|
288
282
|
"""Set the state of the var.
|
|
289
283
|
|
|
290
284
|
Args:
|
|
@@ -534,7 +528,7 @@ class Var(Generic[VAR_TYPE]):
|
|
|
534
528
|
@overload
|
|
535
529
|
def _replace(
|
|
536
530
|
self,
|
|
537
|
-
_var_type:
|
|
531
|
+
_var_type: type[OTHER_VAR_TYPE],
|
|
538
532
|
merge_var_data: VarData | None = None,
|
|
539
533
|
**kwargs: Any,
|
|
540
534
|
) -> Var[OTHER_VAR_TYPE]: ...
|
|
@@ -726,10 +720,10 @@ class Var(Generic[VAR_TYPE]):
|
|
|
726
720
|
return f"{constants.REFLEX_VAR_OPENING_TAG}{hashed_var}{constants.REFLEX_VAR_CLOSING_TAG}{self._js_expr}"
|
|
727
721
|
|
|
728
722
|
@overload
|
|
729
|
-
def to(self, output:
|
|
723
|
+
def to(self, output: type[str]) -> StringVar: ...
|
|
730
724
|
|
|
731
725
|
@overload
|
|
732
|
-
def to(self, output:
|
|
726
|
+
def to(self, output: type[bool]) -> BooleanVar: ...
|
|
733
727
|
|
|
734
728
|
@overload
|
|
735
729
|
def to(self, output: type[int]) -> NumberVar[int]: ...
|
|
@@ -751,12 +745,12 @@ class Var(Generic[VAR_TYPE]):
|
|
|
751
745
|
|
|
752
746
|
@overload
|
|
753
747
|
def to(
|
|
754
|
-
self, output:
|
|
748
|
+
self, output: type[ObjectVar], var_type: type[VAR_INSIDE]
|
|
755
749
|
) -> ObjectVar[VAR_INSIDE]: ...
|
|
756
750
|
|
|
757
751
|
@overload
|
|
758
752
|
def to(
|
|
759
|
-
self, output:
|
|
753
|
+
self, output: type[ObjectVar], var_type: None = None
|
|
760
754
|
) -> ObjectVar[VAR_TYPE]: ...
|
|
761
755
|
|
|
762
756
|
@overload
|
|
@@ -765,13 +759,13 @@ class Var(Generic[VAR_TYPE]):
|
|
|
765
759
|
@overload
|
|
766
760
|
def to(
|
|
767
761
|
self,
|
|
768
|
-
output:
|
|
762
|
+
output: type[OUTPUT] | types.GenericType,
|
|
769
763
|
var_type: types.GenericType | None = None,
|
|
770
764
|
) -> OUTPUT: ...
|
|
771
765
|
|
|
772
766
|
def to(
|
|
773
767
|
self,
|
|
774
|
-
output:
|
|
768
|
+
output: type[OUTPUT] | types.GenericType,
|
|
775
769
|
var_type: types.GenericType | None = None,
|
|
776
770
|
) -> Var:
|
|
777
771
|
"""Convert the var to a different type.
|
|
@@ -1064,6 +1058,16 @@ class Var(Generic[VAR_TYPE]):
|
|
|
1064
1058
|
|
|
1065
1059
|
return boolify(self)
|
|
1066
1060
|
|
|
1061
|
+
def is_none(self) -> BooleanVar:
|
|
1062
|
+
"""Check if the var is None.
|
|
1063
|
+
|
|
1064
|
+
Returns:
|
|
1065
|
+
A BooleanVar object representing the result of the check.
|
|
1066
|
+
"""
|
|
1067
|
+
from .number import is_not_none_operation
|
|
1068
|
+
|
|
1069
|
+
return ~is_not_none_operation(self)
|
|
1070
|
+
|
|
1067
1071
|
def is_not_none(self) -> BooleanVar:
|
|
1068
1072
|
"""Check if the var is not None.
|
|
1069
1073
|
|
|
@@ -1331,7 +1335,7 @@ class Var(Generic[VAR_TYPE]):
|
|
|
1331
1335
|
)
|
|
1332
1336
|
|
|
1333
1337
|
raise VarAttributeError(
|
|
1334
|
-
f"The State var has no attribute '{name}' or may have been annotated wrongly.",
|
|
1338
|
+
f"The State var {escape(self._js_expr)} of type {escape(str(self._var_type))} has no attribute '{name}' or may have been annotated wrongly.",
|
|
1335
1339
|
)
|
|
1336
1340
|
|
|
1337
1341
|
def __bool__(self) -> bool:
|
|
@@ -1831,7 +1835,7 @@ class cached_property: # noqa: N801
|
|
|
1831
1835
|
f"({self._attrname!r} and {name!r})."
|
|
1832
1836
|
)
|
|
1833
1837
|
|
|
1834
|
-
def __get__(self, instance: Any, owner:
|
|
1838
|
+
def __get__(self, instance: Any, owner: type | None = None):
|
|
1835
1839
|
"""Get the cached property.
|
|
1836
1840
|
|
|
1837
1841
|
Args:
|
|
@@ -2134,7 +2138,7 @@ class ComputedVar(Var[RETURN_TYPE]):
|
|
|
2134
2138
|
|
|
2135
2139
|
def _calculate_static_deps(
|
|
2136
2140
|
self,
|
|
2137
|
-
deps:
|
|
2141
|
+
deps: list[str | Var] | dict[str | None, set[str]] | None = None,
|
|
2138
2142
|
) -> dict[str | None, set[str]]:
|
|
2139
2143
|
"""Calculate the static dependencies of the computed var from user input or existing dependencies.
|
|
2140
2144
|
|
|
@@ -2269,56 +2273,56 @@ class ComputedVar(Var[RETURN_TYPE]):
|
|
|
2269
2273
|
def __get__(
|
|
2270
2274
|
self: ComputedVar[bool],
|
|
2271
2275
|
instance: None,
|
|
2272
|
-
owner:
|
|
2276
|
+
owner: type,
|
|
2273
2277
|
) -> BooleanVar: ...
|
|
2274
2278
|
|
|
2275
2279
|
@overload
|
|
2276
2280
|
def __get__(
|
|
2277
2281
|
self: ComputedVar[int] | ComputedVar[float],
|
|
2278
2282
|
instance: None,
|
|
2279
|
-
owner:
|
|
2283
|
+
owner: type,
|
|
2280
2284
|
) -> NumberVar: ...
|
|
2281
2285
|
|
|
2282
2286
|
@overload
|
|
2283
2287
|
def __get__(
|
|
2284
2288
|
self: ComputedVar[str],
|
|
2285
2289
|
instance: None,
|
|
2286
|
-
owner:
|
|
2290
|
+
owner: type,
|
|
2287
2291
|
) -> StringVar: ...
|
|
2288
2292
|
|
|
2289
2293
|
@overload
|
|
2290
2294
|
def __get__(
|
|
2291
2295
|
self: ComputedVar[MAPPING_TYPE],
|
|
2292
2296
|
instance: None,
|
|
2293
|
-
owner:
|
|
2297
|
+
owner: type,
|
|
2294
2298
|
) -> ObjectVar[MAPPING_TYPE]: ...
|
|
2295
2299
|
|
|
2296
2300
|
@overload
|
|
2297
2301
|
def __get__(
|
|
2298
2302
|
self: ComputedVar[list[LIST_INSIDE]],
|
|
2299
2303
|
instance: None,
|
|
2300
|
-
owner:
|
|
2304
|
+
owner: type,
|
|
2301
2305
|
) -> ArrayVar[list[LIST_INSIDE]]: ...
|
|
2302
2306
|
|
|
2303
2307
|
@overload
|
|
2304
2308
|
def __get__(
|
|
2305
2309
|
self: ComputedVar[tuple[LIST_INSIDE, ...]],
|
|
2306
2310
|
instance: None,
|
|
2307
|
-
owner:
|
|
2311
|
+
owner: type,
|
|
2308
2312
|
) -> ArrayVar[tuple[LIST_INSIDE, ...]]: ...
|
|
2309
2313
|
|
|
2310
2314
|
@overload
|
|
2311
2315
|
def __get__(
|
|
2312
2316
|
self: ComputedVar[BASE_TYPE],
|
|
2313
2317
|
instance: None,
|
|
2314
|
-
owner:
|
|
2318
|
+
owner: type,
|
|
2315
2319
|
) -> ObjectVar[BASE_TYPE]: ...
|
|
2316
2320
|
|
|
2317
2321
|
@overload
|
|
2318
2322
|
def __get__(
|
|
2319
2323
|
self: ComputedVar[SQLA_TYPE],
|
|
2320
2324
|
instance: None,
|
|
2321
|
-
owner:
|
|
2325
|
+
owner: type,
|
|
2322
2326
|
) -> ObjectVar[SQLA_TYPE]: ...
|
|
2323
2327
|
|
|
2324
2328
|
if TYPE_CHECKING:
|
|
@@ -2329,12 +2333,12 @@ class ComputedVar(Var[RETURN_TYPE]):
|
|
|
2329
2333
|
) -> ObjectVar[DATACLASS_TYPE]: ...
|
|
2330
2334
|
|
|
2331
2335
|
@overload
|
|
2332
|
-
def __get__(self, instance: None, owner:
|
|
2336
|
+
def __get__(self, instance: None, owner: type) -> ComputedVar[RETURN_TYPE]: ...
|
|
2333
2337
|
|
|
2334
2338
|
@overload
|
|
2335
|
-
def __get__(self, instance: BaseState, owner:
|
|
2339
|
+
def __get__(self, instance: BaseState, owner: type) -> RETURN_TYPE: ...
|
|
2336
2340
|
|
|
2337
|
-
def __get__(self, instance: BaseState | None, owner:
|
|
2341
|
+
def __get__(self, instance: BaseState | None, owner: type):
|
|
2338
2342
|
"""Get the ComputedVar value.
|
|
2339
2343
|
|
|
2340
2344
|
If the value is already cached on the instance, return the cached value.
|
|
@@ -2390,7 +2394,7 @@ class ComputedVar(Var[RETURN_TYPE]):
|
|
|
2390
2394
|
|
|
2391
2395
|
def _deps(
|
|
2392
2396
|
self,
|
|
2393
|
-
objclass:
|
|
2397
|
+
objclass: type[BaseState],
|
|
2394
2398
|
obj: FunctionType | CodeType | None = None,
|
|
2395
2399
|
) -> dict[str, set[str]]:
|
|
2396
2400
|
"""Determine var dependencies of this ComputedVar.
|
|
@@ -2448,7 +2452,7 @@ class ComputedVar(Var[RETURN_TYPE]):
|
|
|
2448
2452
|
with contextlib.suppress(AttributeError):
|
|
2449
2453
|
delattr(instance, self._cache_attr)
|
|
2450
2454
|
|
|
2451
|
-
def add_dependency(self, objclass:
|
|
2455
|
+
def add_dependency(self, objclass: type[BaseState], dep: Var):
|
|
2452
2456
|
"""Explicitly add a dependency to the ComputedVar.
|
|
2453
2457
|
|
|
2454
2458
|
After adding the dependency, when the `dep` changes, this computed var
|
|
@@ -2479,7 +2483,7 @@ class ComputedVar(Var[RETURN_TYPE]):
|
|
|
2479
2483
|
f"field name, got {dep!r}."
|
|
2480
2484
|
)
|
|
2481
2485
|
|
|
2482
|
-
def _determine_var_type(self) ->
|
|
2486
|
+
def _determine_var_type(self) -> type:
|
|
2483
2487
|
"""Get the type of the var.
|
|
2484
2488
|
|
|
2485
2489
|
Returns:
|
|
@@ -2491,7 +2495,7 @@ class ComputedVar(Var[RETURN_TYPE]):
|
|
|
2491
2495
|
return Any # pyright: ignore [reportReturnType]
|
|
2492
2496
|
|
|
2493
2497
|
@property
|
|
2494
|
-
def __class__(self) ->
|
|
2498
|
+
def __class__(self) -> type:
|
|
2495
2499
|
"""Get the class of the var.
|
|
2496
2500
|
|
|
2497
2501
|
Returns:
|
|
@@ -2536,56 +2540,56 @@ class AsyncComputedVar(ComputedVar[RETURN_TYPE]):
|
|
|
2536
2540
|
def __get__(
|
|
2537
2541
|
self: AsyncComputedVar[bool],
|
|
2538
2542
|
instance: None,
|
|
2539
|
-
owner:
|
|
2543
|
+
owner: type,
|
|
2540
2544
|
) -> BooleanVar: ...
|
|
2541
2545
|
|
|
2542
2546
|
@overload
|
|
2543
2547
|
def __get__(
|
|
2544
2548
|
self: AsyncComputedVar[int] | ComputedVar[float],
|
|
2545
2549
|
instance: None,
|
|
2546
|
-
owner:
|
|
2550
|
+
owner: type,
|
|
2547
2551
|
) -> NumberVar: ...
|
|
2548
2552
|
|
|
2549
2553
|
@overload
|
|
2550
2554
|
def __get__(
|
|
2551
2555
|
self: AsyncComputedVar[str],
|
|
2552
2556
|
instance: None,
|
|
2553
|
-
owner:
|
|
2557
|
+
owner: type,
|
|
2554
2558
|
) -> StringVar: ...
|
|
2555
2559
|
|
|
2556
2560
|
@overload
|
|
2557
2561
|
def __get__(
|
|
2558
2562
|
self: AsyncComputedVar[MAPPING_TYPE],
|
|
2559
2563
|
instance: None,
|
|
2560
|
-
owner:
|
|
2564
|
+
owner: type,
|
|
2561
2565
|
) -> ObjectVar[MAPPING_TYPE]: ...
|
|
2562
2566
|
|
|
2563
2567
|
@overload
|
|
2564
2568
|
def __get__(
|
|
2565
2569
|
self: AsyncComputedVar[list[LIST_INSIDE]],
|
|
2566
2570
|
instance: None,
|
|
2567
|
-
owner:
|
|
2571
|
+
owner: type,
|
|
2568
2572
|
) -> ArrayVar[list[LIST_INSIDE]]: ...
|
|
2569
2573
|
|
|
2570
2574
|
@overload
|
|
2571
2575
|
def __get__(
|
|
2572
2576
|
self: AsyncComputedVar[tuple[LIST_INSIDE, ...]],
|
|
2573
2577
|
instance: None,
|
|
2574
|
-
owner:
|
|
2578
|
+
owner: type,
|
|
2575
2579
|
) -> ArrayVar[tuple[LIST_INSIDE, ...]]: ...
|
|
2576
2580
|
|
|
2577
2581
|
@overload
|
|
2578
2582
|
def __get__(
|
|
2579
2583
|
self: AsyncComputedVar[BASE_TYPE],
|
|
2580
2584
|
instance: None,
|
|
2581
|
-
owner:
|
|
2585
|
+
owner: type,
|
|
2582
2586
|
) -> ObjectVar[BASE_TYPE]: ...
|
|
2583
2587
|
|
|
2584
2588
|
@overload
|
|
2585
2589
|
def __get__(
|
|
2586
2590
|
self: AsyncComputedVar[SQLA_TYPE],
|
|
2587
2591
|
instance: None,
|
|
2588
|
-
owner:
|
|
2592
|
+
owner: type,
|
|
2589
2593
|
) -> ObjectVar[SQLA_TYPE]: ...
|
|
2590
2594
|
|
|
2591
2595
|
if TYPE_CHECKING:
|
|
@@ -2596,11 +2600,11 @@ class AsyncComputedVar(ComputedVar[RETURN_TYPE]):
|
|
|
2596
2600
|
) -> ObjectVar[DATACLASS_TYPE]: ...
|
|
2597
2601
|
|
|
2598
2602
|
@overload
|
|
2599
|
-
def __get__(self, instance: None, owner:
|
|
2603
|
+
def __get__(self, instance: None, owner: type) -> AsyncComputedVar[RETURN_TYPE]: ...
|
|
2600
2604
|
|
|
2601
2605
|
@overload
|
|
2602
2606
|
def __get__(
|
|
2603
|
-
self, instance: BaseState, owner:
|
|
2607
|
+
self, instance: BaseState, owner: type
|
|
2604
2608
|
) -> Coroutine[None, None, RETURN_TYPE]: ...
|
|
2605
2609
|
|
|
2606
2610
|
def __get__(
|
|
@@ -2771,7 +2775,7 @@ class CustomVarOperationReturn(Var[RETURN]):
|
|
|
2771
2775
|
def create(
|
|
2772
2776
|
cls,
|
|
2773
2777
|
js_expression: str,
|
|
2774
|
-
_var_type:
|
|
2778
|
+
_var_type: type[RETURN] | None = None,
|
|
2775
2779
|
_var_data: VarData | None = None,
|
|
2776
2780
|
) -> CustomVarOperationReturn[RETURN]:
|
|
2777
2781
|
"""Create a CustomVarOperation.
|
|
@@ -2793,7 +2797,7 @@ class CustomVarOperationReturn(Var[RETURN]):
|
|
|
2793
2797
|
|
|
2794
2798
|
def var_operation_return(
|
|
2795
2799
|
js_expression: str,
|
|
2796
|
-
var_type:
|
|
2800
|
+
var_type: type[RETURN] | GenericType | None = None,
|
|
2797
2801
|
var_data: VarData | None = None,
|
|
2798
2802
|
) -> CustomVarOperationReturn[RETURN]:
|
|
2799
2803
|
"""Shortcut for creating a CustomVarOperationReturn.
|
|
@@ -2924,7 +2928,7 @@ class LiteralNoneVar(LiteralVar, NoneVar):
|
|
|
2924
2928
|
)
|
|
2925
2929
|
|
|
2926
2930
|
|
|
2927
|
-
def get_to_operation(var_subclass:
|
|
2931
|
+
def get_to_operation(var_subclass: type[Var]) -> type[ToOperation]:
|
|
2928
2932
|
"""Get the ToOperation class for a given Var subclass.
|
|
2929
2933
|
|
|
2930
2934
|
Args:
|
|
@@ -3169,11 +3173,11 @@ def resolve_generic_type_with_mapping(
|
|
|
3169
3173
|
return generic_type
|
|
3170
3174
|
|
|
3171
3175
|
mapping_for_older_python = {
|
|
3172
|
-
list: List,
|
|
3173
|
-
set: Set,
|
|
3174
|
-
dict: Dict,
|
|
3175
|
-
tuple: Tuple,
|
|
3176
|
-
frozenset: FrozenSet,
|
|
3176
|
+
list: List, # noqa: UP006
|
|
3177
|
+
set: Set, # noqa: UP006
|
|
3178
|
+
dict: Dict, # noqa: UP006
|
|
3179
|
+
tuple: Tuple, # noqa: UP006
|
|
3180
|
+
frozenset: FrozenSet, # noqa: UP006
|
|
3177
3181
|
}
|
|
3178
3182
|
|
|
3179
3183
|
return mapping_for_older_python.get(generic_origin, generic_origin)[
|
reflex/vars/dep_tracking.py
CHANGED
|
@@ -8,7 +8,7 @@ import dis
|
|
|
8
8
|
import enum
|
|
9
9
|
import inspect
|
|
10
10
|
from types import CellType, CodeType, FunctionType
|
|
11
|
-
from typing import TYPE_CHECKING, Any, ClassVar,
|
|
11
|
+
from typing import TYPE_CHECKING, Any, ClassVar, cast
|
|
12
12
|
|
|
13
13
|
from reflex.utils.exceptions import VarValueError
|
|
14
14
|
|
|
@@ -50,16 +50,16 @@ class DependencyTracker:
|
|
|
50
50
|
"""State machine for identifying state attributes that are accessed by a function."""
|
|
51
51
|
|
|
52
52
|
func: FunctionType | CodeType = dataclasses.field()
|
|
53
|
-
state_cls:
|
|
53
|
+
state_cls: type[BaseState] = dataclasses.field()
|
|
54
54
|
|
|
55
55
|
dependencies: dict[str, set[str]] = dataclasses.field(default_factory=dict)
|
|
56
56
|
|
|
57
57
|
scan_status: ScanStatus = dataclasses.field(default=ScanStatus.SCANNING)
|
|
58
58
|
top_of_stack: str | None = dataclasses.field(default=None)
|
|
59
59
|
|
|
60
|
-
tracked_locals: dict[str,
|
|
60
|
+
tracked_locals: dict[str, type[BaseState]] = dataclasses.field(default_factory=dict)
|
|
61
61
|
|
|
62
|
-
_getting_state_class:
|
|
62
|
+
_getting_state_class: type[BaseState] | None = dataclasses.field(default=None)
|
|
63
63
|
_getting_var_instructions: list[dis.Instruction] = dataclasses.field(
|
|
64
64
|
default_factory=list
|
|
65
65
|
)
|