reflex 0.7.1a4__py3-none-any.whl → 0.7.2a1__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/web/utils/context.js.jinja2 +8 -8
- reflex/.templates/web/components/reflex/radix_themes_color_mode_provider.js +3 -3
- reflex/admin.py +1 -2
- reflex/app.py +46 -49
- reflex/app_mixins/lifespan.py +2 -2
- reflex/app_mixins/middleware.py +1 -2
- reflex/assets.py +1 -2
- reflex/base.py +2 -2
- reflex/compiler/compiler.py +51 -16
- reflex/compiler/utils.py +4 -13
- reflex/components/base/app_wrap.pyi +7 -7
- reflex/components/base/bare.py +3 -3
- reflex/components/base/body.pyi +7 -7
- reflex/components/base/document.py +1 -3
- reflex/components/base/document.pyi +32 -32
- reflex/components/base/error_boundary.py +2 -4
- reflex/components/base/error_boundary.pyi +11 -13
- reflex/components/base/fragment.pyi +7 -7
- reflex/components/base/head.pyi +13 -13
- reflex/components/base/link.pyi +22 -22
- reflex/components/base/meta.py +5 -7
- reflex/components/base/meta.pyi +40 -40
- reflex/components/base/script.pyi +11 -14
- reflex/components/base/strict_mode.pyi +7 -7
- reflex/components/component.py +188 -113
- reflex/components/core/auto_scroll.py +8 -1
- reflex/components/core/auto_scroll.pyi +183 -210
- reflex/components/core/banner.py +2 -4
- reflex/components/core/banner.pyi +390 -444
- reflex/components/core/breakpoints.py +5 -5
- reflex/components/core/client_side_routing.pyi +14 -14
- reflex/components/core/clipboard.py +4 -4
- reflex/components/core/clipboard.pyi +12 -14
- reflex/components/core/cond.py +17 -25
- reflex/components/core/debounce.py +3 -3
- reflex/components/core/debounce.pyi +14 -14
- reflex/components/core/foreach.py +7 -2
- reflex/components/core/html.py +1 -3
- reflex/components/core/html.pyi +184 -213
- reflex/components/core/match.py +15 -19
- reflex/components/core/sticky.pyi +930 -1078
- reflex/components/core/upload.py +4 -4
- reflex/components/core/upload.pyi +62 -62
- reflex/components/datadisplay/code.py +6 -6
- reflex/components/datadisplay/code.pyi +1159 -1165
- reflex/components/datadisplay/dataeditor.py +49 -49
- reflex/components/datadisplay/dataeditor.pyi +95 -123
- reflex/components/datadisplay/logo.py +1 -3
- reflex/components/datadisplay/shiki_code_block.py +8 -10
- reflex/components/datadisplay/shiki_code_block.pyi +1678 -1720
- reflex/components/el/element.pyi +7 -7
- reflex/components/el/elements/base.pyi +183 -210
- reflex/components/el/elements/forms.py +23 -23
- reflex/components/el/elements/forms.pyi +2571 -2933
- reflex/components/el/elements/inline.py +4 -4
- reflex/components/el/elements/inline.pyi +5191 -5953
- reflex/components/el/elements/media.py +47 -47
- reflex/components/el/elements/media.pyi +4802 -5500
- reflex/components/el/elements/metadata.py +1 -3
- reflex/components/el/elements/metadata.pyi +782 -896
- reflex/components/el/elements/other.pyi +1278 -1467
- reflex/components/el/elements/scripts.pyi +580 -667
- reflex/components/el/elements/sectioning.pyi +2761 -3166
- reflex/components/el/elements/tables.pyi +1840 -2119
- reflex/components/el/elements/typography.pyi +2772 -3179
- reflex/components/gridjs/datatable.py +7 -7
- reflex/components/gridjs/datatable.pyi +19 -19
- reflex/components/lucide/icon.pyi +21 -21
- reflex/components/markdown/markdown.py +2 -2
- reflex/components/markdown/markdown.pyi +9 -9
- reflex/components/moment/moment.py +11 -12
- reflex/components/moment/moment.pyi +44 -47
- reflex/components/next/base.pyi +7 -7
- reflex/components/next/image.py +3 -3
- reflex/components/next/image.pyi +19 -21
- reflex/components/next/link.pyi +9 -9
- reflex/components/next/video.py +1 -3
- reflex/components/next/video.pyi +9 -9
- reflex/components/plotly/plotly.py +22 -45
- reflex/components/plotly/plotly.pyi +164 -164
- reflex/components/radix/primitives/accordion.py +14 -14
- reflex/components/radix/primitives/accordion.pyi +439 -487
- reflex/components/radix/primitives/base.py +1 -3
- reflex/components/radix/primitives/base.pyi +15 -15
- reflex/components/radix/primitives/drawer.py +3 -3
- reflex/components/radix/primitives/drawer.pyi +110 -116
- reflex/components/radix/primitives/form.py +1 -1
- reflex/components/radix/primitives/form.pyi +668 -752
- reflex/components/radix/primitives/progress.py +6 -6
- reflex/components/radix/primitives/progress.pyi +225 -243
- reflex/components/radix/primitives/slider.py +6 -6
- reflex/components/radix/primitives/slider.pyi +52 -55
- reflex/components/radix/themes/base.py +3 -6
- reflex/components/radix/themes/base.pyi +197 -303
- reflex/components/radix/themes/color_mode.py +5 -5
- reflex/components/radix/themes/color_mode.pyi +366 -436
- reflex/components/radix/themes/components/alert_dialog.pyi +229 -262
- reflex/components/radix/themes/components/aspect_ratio.py +1 -3
- reflex/components/radix/themes/components/aspect_ratio.pyi +8 -8
- reflex/components/radix/themes/components/avatar.pyi +79 -94
- reflex/components/radix/themes/components/badge.pyi +252 -295
- reflex/components/radix/themes/components/button.pyi +269 -314
- reflex/components/radix/themes/components/callout.py +2 -2
- reflex/components/radix/themes/components/callout.pyi +1116 -1290
- reflex/components/radix/themes/components/card.pyi +194 -229
- reflex/components/radix/themes/components/checkbox.pyi +243 -278
- reflex/components/radix/themes/components/checkbox_cards.py +3 -7
- reflex/components/radix/themes/components/checkbox_cards.pyi +101 -135
- reflex/components/radix/themes/components/checkbox_group.py +2 -2
- reflex/components/radix/themes/components/checkbox_group.pyi +83 -96
- reflex/components/radix/themes/components/context_menu.py +18 -15
- reflex/components/radix/themes/components/context_menu.pyi +408 -458
- reflex/components/radix/themes/components/data_list.pyi +122 -147
- reflex/components/radix/themes/components/dialog.pyi +231 -264
- reflex/components/radix/themes/components/dropdown_menu.py +16 -13
- reflex/components/radix/themes/components/dropdown_menu.pyi +223 -246
- reflex/components/radix/themes/components/hover_card.py +2 -2
- reflex/components/radix/themes/components/hover_card.pyi +237 -282
- reflex/components/radix/themes/components/icon_button.pyi +269 -314
- reflex/components/radix/themes/components/inset.py +8 -8
- reflex/components/radix/themes/components/inset.pyi +232 -292
- reflex/components/radix/themes/components/popover.py +2 -2
- reflex/components/radix/themes/components/popover.pyi +229 -271
- reflex/components/radix/themes/components/progress.pyi +80 -96
- reflex/components/radix/themes/components/radio.pyi +73 -86
- reflex/components/radix/themes/components/radio_cards.py +4 -8
- reflex/components/radix/themes/components/radio_cards.pyi +117 -154
- reflex/components/radix/themes/components/radio_group.py +3 -3
- reflex/components/radix/themes/components/radio_group.pyi +250 -291
- reflex/components/radix/themes/components/scroll_area.pyi +14 -20
- reflex/components/radix/themes/components/segmented_control.py +6 -6
- reflex/components/radix/themes/components/segmented_control.pyi +89 -108
- reflex/components/radix/themes/components/select.py +7 -7
- reflex/components/radix/themes/components/select.pyi +376 -444
- reflex/components/radix/themes/components/separator.pyi +79 -93
- reflex/components/radix/themes/components/skeleton.pyi +32 -26
- reflex/components/radix/themes/components/slider.py +8 -8
- reflex/components/radix/themes/components/slider.pyi +99 -122
- reflex/components/radix/themes/components/spinner.pyi +12 -19
- reflex/components/radix/themes/components/switch.pyi +84 -99
- reflex/components/radix/themes/components/table.py +9 -9
- reflex/components/radix/themes/components/table.pyi +1440 -1794
- reflex/components/radix/themes/components/tabs.py +4 -4
- reflex/components/radix/themes/components/tabs.pyi +120 -132
- reflex/components/radix/themes/components/text_area.pyi +281 -331
- reflex/components/radix/themes/components/text_field.py +2 -2
- reflex/components/radix/themes/components/text_field.pyi +639 -734
- reflex/components/radix/themes/components/tooltip.py +6 -6
- reflex/components/radix/themes/components/tooltip.pyi +34 -43
- reflex/components/radix/themes/layout/base.pyi +85 -182
- reflex/components/radix/themes/layout/box.pyi +183 -210
- reflex/components/radix/themes/layout/center.pyi +225 -286
- reflex/components/radix/themes/layout/container.pyi +191 -224
- reflex/components/radix/themes/layout/flex.py +2 -2
- reflex/components/radix/themes/layout/flex.pyi +225 -286
- reflex/components/radix/themes/layout/grid.py +2 -2
- reflex/components/radix/themes/layout/grid.pyi +245 -315
- reflex/components/radix/themes/layout/list.py +2 -2
- reflex/components/radix/themes/layout/list.pyi +712 -815
- reflex/components/radix/themes/layout/section.pyi +187 -221
- reflex/components/radix/themes/layout/spacer.pyi +225 -286
- reflex/components/radix/themes/layout/stack.pyi +625 -768
- reflex/components/radix/themes/typography/blockquote.pyi +257 -299
- reflex/components/radix/themes/typography/code.pyi +259 -304
- reflex/components/radix/themes/typography/heading.pyi +272 -324
- reflex/components/radix/themes/typography/link.pyi +302 -358
- reflex/components/radix/themes/typography/text.pyi +1669 -1945
- reflex/components/react_player/audio.pyi +20 -22
- reflex/components/react_player/react_player.pyi +19 -19
- reflex/components/react_player/video.pyi +20 -22
- reflex/components/recharts/cartesian.py +100 -97
- reflex/components/recharts/cartesian.pyi +891 -1007
- reflex/components/recharts/charts.py +42 -42
- reflex/components/recharts/charts.pyi +212 -249
- reflex/components/recharts/general.py +22 -21
- reflex/components/recharts/general.pyi +198 -223
- reflex/components/recharts/polar.py +42 -45
- reflex/components/recharts/polar.pyi +254 -288
- reflex/components/recharts/recharts.pyi +13 -13
- reflex/components/sonner/toast.py +20 -20
- reflex/components/sonner/toast.pyi +58 -61
- reflex/components/suneditor/editor.py +9 -9
- reflex/components/suneditor/editor.pyi +78 -83
- reflex/components/tags/cond_tag.py +2 -2
- reflex/components/tags/iter_tag.py +10 -14
- reflex/components/tags/match_tag.py +2 -2
- reflex/components/tags/tag.py +10 -10
- reflex/config.py +36 -35
- reflex/constants/__init__.py +56 -53
- reflex/custom_components/custom_components.py +6 -7
- reflex/event.py +38 -42
- reflex/experimental/client_state.py +2 -4
- reflex/experimental/layout.py +2 -2
- reflex/experimental/layout.pyi +579 -663
- reflex/istate/data.py +4 -5
- reflex/middleware/hydrate_middleware.py +2 -2
- reflex/middleware/middleware.py +2 -2
- reflex/model.py +3 -5
- reflex/page.py +2 -2
- reflex/reflex.py +9 -10
- reflex/state.py +77 -49
- reflex/style.py +9 -3
- reflex/testing.py +21 -24
- reflex/utils/console.py +1 -1
- reflex/utils/decorator.py +26 -1
- reflex/utils/exec.py +6 -11
- reflex/utils/export.py +2 -3
- reflex/utils/format.py +4 -4
- reflex/utils/imports.py +12 -12
- reflex/utils/prerequisites.py +35 -84
- reflex/utils/processes.py +5 -5
- reflex/utils/pyi_generator.py +33 -22
- reflex/utils/serializers.py +60 -15
- reflex/utils/types.py +237 -56
- reflex/vars/base.py +122 -72
- reflex/vars/datetime.py +2 -2
- reflex/vars/function.py +52 -55
- reflex/vars/number.py +59 -5
- reflex/vars/object.py +57 -26
- reflex/vars/sequence.py +983 -958
- {reflex-0.7.1a4.dist-info → reflex-0.7.2a1.dist-info}/METADATA +3 -6
- reflex-0.7.2a1.dist-info/RECORD +405 -0
- {reflex-0.7.1a4.dist-info → reflex-0.7.2a1.dist-info}/WHEEL +1 -1
- reflex-0.7.1a4.dist-info/RECORD +0 -405
- {reflex-0.7.1a4.dist-info → reflex-0.7.2a1.dist-info}/LICENSE +0 -0
- {reflex-0.7.1a4.dist-info → reflex-0.7.2a1.dist-info}/entry_points.txt +0 -0
reflex/vars/base.py
CHANGED
|
@@ -28,7 +28,6 @@ from typing import (
|
|
|
28
28
|
Literal,
|
|
29
29
|
Mapping,
|
|
30
30
|
NoReturn,
|
|
31
|
-
Optional,
|
|
32
31
|
ParamSpec,
|
|
33
32
|
Sequence,
|
|
34
33
|
Set,
|
|
@@ -101,11 +100,11 @@ class VarSubclassEntry:
|
|
|
101
100
|
|
|
102
101
|
var_subclass: Type[Var]
|
|
103
102
|
to_var_subclass: Type[ToOperation]
|
|
104
|
-
python_types:
|
|
103
|
+
python_types: tuple[GenericType, ...]
|
|
105
104
|
|
|
106
105
|
|
|
107
|
-
_var_subclasses:
|
|
108
|
-
_var_literal_subclasses:
|
|
106
|
+
_var_subclasses: list[VarSubclassEntry] = []
|
|
107
|
+
_var_literal_subclasses: list[tuple[Type[LiteralVar], VarSubclassEntry]] = []
|
|
109
108
|
|
|
110
109
|
|
|
111
110
|
@dataclasses.dataclass(
|
|
@@ -125,10 +124,10 @@ class VarData:
|
|
|
125
124
|
imports: ImmutableParsedImportDict = dataclasses.field(default_factory=tuple)
|
|
126
125
|
|
|
127
126
|
# Hooks that need to be present in the component to render this var
|
|
128
|
-
hooks:
|
|
127
|
+
hooks: tuple[str, ...] = dataclasses.field(default_factory=tuple)
|
|
129
128
|
|
|
130
129
|
# Dependencies of the var
|
|
131
|
-
deps:
|
|
130
|
+
deps: tuple[Var, ...] = dataclasses.field(default_factory=tuple)
|
|
132
131
|
|
|
133
132
|
# Position of the hook in the component
|
|
134
133
|
position: Hooks.HookPosition | None = None
|
|
@@ -360,7 +359,7 @@ def can_use_in_object_var(cls: GenericType) -> bool:
|
|
|
360
359
|
return all(can_use_in_object_var(t) for t in types.get_args(cls))
|
|
361
360
|
return (
|
|
362
361
|
inspect.isclass(cls)
|
|
363
|
-
and not
|
|
362
|
+
and not safe_issubclass(cls, Var)
|
|
364
363
|
and serializers.can_serialize(cls, dict)
|
|
365
364
|
)
|
|
366
365
|
|
|
@@ -379,7 +378,7 @@ class Var(Generic[VAR_TYPE]):
|
|
|
379
378
|
_var_type: types.GenericType = dataclasses.field(default=Any)
|
|
380
379
|
|
|
381
380
|
# Extra metadata associated with the Var
|
|
382
|
-
_var_data:
|
|
381
|
+
_var_data: VarData | None = dataclasses.field(default=None)
|
|
383
382
|
|
|
384
383
|
def __str__(self) -> str:
|
|
385
384
|
"""String representation of the var. Guaranteed to be a valid Javascript expression.
|
|
@@ -440,7 +439,7 @@ class Var(Generic[VAR_TYPE]):
|
|
|
440
439
|
|
|
441
440
|
def __init_subclass__(
|
|
442
441
|
cls,
|
|
443
|
-
python_types:
|
|
442
|
+
python_types: tuple[GenericType, ...] | GenericType = types.Unset(),
|
|
444
443
|
default_type: GenericType = types.Unset(),
|
|
445
444
|
**kwargs,
|
|
446
445
|
):
|
|
@@ -476,7 +475,7 @@ class Var(Generic[VAR_TYPE]):
|
|
|
476
475
|
|
|
477
476
|
_default_var_type: ClassVar[GenericType] = default_type
|
|
478
477
|
|
|
479
|
-
new_to_var_operation_name = f"
|
|
478
|
+
new_to_var_operation_name = f"{cls.__name__.removesuffix('Var')}CastedVar"
|
|
480
479
|
ToVarOperation.__qualname__ = (
|
|
481
480
|
ToVarOperation.__qualname__.removesuffix(ToVarOperation.__name__)
|
|
482
481
|
+ new_to_var_operation_name
|
|
@@ -797,7 +796,7 @@ class Var(Generic[VAR_TYPE]):
|
|
|
797
796
|
|
|
798
797
|
if inspect.isclass(output):
|
|
799
798
|
for var_subclass in _var_subclasses[::-1]:
|
|
800
|
-
if
|
|
799
|
+
if safe_issubclass(output, var_subclass.var_subclass):
|
|
801
800
|
current_var_type = self._var_type
|
|
802
801
|
if current_var_type is Any:
|
|
803
802
|
new_var_type = var_type
|
|
@@ -809,7 +808,7 @@ class Var(Generic[VAR_TYPE]):
|
|
|
809
808
|
return to_operation_return # pyright: ignore [reportReturnType]
|
|
810
809
|
|
|
811
810
|
# If we can't determine the first argument, we just replace the _var_type.
|
|
812
|
-
if not
|
|
811
|
+
if not safe_issubclass(output, Var) or var_type is None:
|
|
813
812
|
return dataclasses.replace(
|
|
814
813
|
self,
|
|
815
814
|
_var_type=output,
|
|
@@ -851,14 +850,15 @@ class Var(Generic[VAR_TYPE]):
|
|
|
851
850
|
Raises:
|
|
852
851
|
TypeError: If the type is not supported for guessing.
|
|
853
852
|
"""
|
|
854
|
-
from .number import NumberVar
|
|
855
853
|
from .object import ObjectVar
|
|
856
854
|
|
|
857
855
|
var_type = self._var_type
|
|
858
856
|
if var_type is None:
|
|
859
857
|
return self.to(None)
|
|
860
|
-
if
|
|
861
|
-
|
|
858
|
+
if var_type is NoReturn:
|
|
859
|
+
return self.to(Any)
|
|
860
|
+
|
|
861
|
+
var_type = types.value_inside_optional(var_type)
|
|
862
862
|
|
|
863
863
|
if var_type is Any:
|
|
864
864
|
return self
|
|
@@ -867,11 +867,20 @@ class Var(Generic[VAR_TYPE]):
|
|
|
867
867
|
|
|
868
868
|
if fixed_type in types.UnionTypes:
|
|
869
869
|
inner_types = get_args(var_type)
|
|
870
|
+
non_optional_inner_types = [
|
|
871
|
+
types.value_inside_optional(inner_type) for inner_type in inner_types
|
|
872
|
+
]
|
|
873
|
+
fixed_inner_types = [
|
|
874
|
+
get_origin(inner_type) or inner_type
|
|
875
|
+
for inner_type in non_optional_inner_types
|
|
876
|
+
]
|
|
870
877
|
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
878
|
+
for var_subclass in _var_subclasses[::-1]:
|
|
879
|
+
if all(
|
|
880
|
+
safe_issubclass(t, var_subclass.python_types)
|
|
881
|
+
for t in fixed_inner_types
|
|
882
|
+
):
|
|
883
|
+
return self.to(var_subclass.var_subclass, self._var_type)
|
|
875
884
|
|
|
876
885
|
if can_use_in_object_var(var_type):
|
|
877
886
|
return self.to(ObjectVar, self._var_type)
|
|
@@ -889,7 +898,7 @@ class Var(Generic[VAR_TYPE]):
|
|
|
889
898
|
return self.to(None)
|
|
890
899
|
|
|
891
900
|
for var_subclass in _var_subclasses[::-1]:
|
|
892
|
-
if
|
|
901
|
+
if safe_issubclass(fixed_type, var_subclass.python_types):
|
|
893
902
|
return self.to(var_subclass.var_subclass, self._var_type)
|
|
894
903
|
|
|
895
904
|
if can_use_in_object_var(fixed_type):
|
|
@@ -917,17 +926,17 @@ class Var(Generic[VAR_TYPE]):
|
|
|
917
926
|
if type_ is Literal:
|
|
918
927
|
args = get_args(self._var_type)
|
|
919
928
|
return args[0] if args else None
|
|
920
|
-
if
|
|
929
|
+
if safe_issubclass(type_, str):
|
|
921
930
|
return ""
|
|
922
|
-
if
|
|
931
|
+
if safe_issubclass(type_, types.get_args(int | float)):
|
|
923
932
|
return 0
|
|
924
|
-
if
|
|
933
|
+
if safe_issubclass(type_, bool):
|
|
925
934
|
return False
|
|
926
|
-
if
|
|
935
|
+
if safe_issubclass(type_, list):
|
|
927
936
|
return []
|
|
928
|
-
if
|
|
937
|
+
if safe_issubclass(type_, Mapping):
|
|
929
938
|
return {}
|
|
930
|
-
if
|
|
939
|
+
if safe_issubclass(type_, tuple):
|
|
931
940
|
return ()
|
|
932
941
|
if types.is_dataframe(type_):
|
|
933
942
|
try:
|
|
@@ -938,7 +947,7 @@ class Var(Generic[VAR_TYPE]):
|
|
|
938
947
|
raise ImportError(
|
|
939
948
|
"Please install pandas to use dataframes in your app."
|
|
940
949
|
) from e
|
|
941
|
-
return set() if
|
|
950
|
+
return set() if safe_issubclass(type_, set) else None
|
|
942
951
|
|
|
943
952
|
def _get_setter_name(self, include_state: bool = True) -> str:
|
|
944
953
|
"""Get the name of the var's generated setter function.
|
|
@@ -1211,7 +1220,7 @@ class Var(Generic[VAR_TYPE]):
|
|
|
1211
1220
|
|
|
1212
1221
|
@overload
|
|
1213
1222
|
@classmethod
|
|
1214
|
-
def range(cls, stop: int | NumberVar, /) -> ArrayVar[
|
|
1223
|
+
def range(cls, stop: int | NumberVar, /) -> ArrayVar[Sequence[int]]: ...
|
|
1215
1224
|
|
|
1216
1225
|
@overload
|
|
1217
1226
|
@classmethod
|
|
@@ -1221,7 +1230,7 @@ class Var(Generic[VAR_TYPE]):
|
|
|
1221
1230
|
end: int | NumberVar,
|
|
1222
1231
|
step: int | NumberVar = 1,
|
|
1223
1232
|
/,
|
|
1224
|
-
) -> ArrayVar[
|
|
1233
|
+
) -> ArrayVar[Sequence[int]]: ...
|
|
1225
1234
|
|
|
1226
1235
|
@classmethod
|
|
1227
1236
|
def range(
|
|
@@ -1229,7 +1238,7 @@ class Var(Generic[VAR_TYPE]):
|
|
|
1229
1238
|
first_endpoint: int | NumberVar,
|
|
1230
1239
|
second_endpoint: int | NumberVar | None = None,
|
|
1231
1240
|
step: int | NumberVar | None = None,
|
|
1232
|
-
) -> ArrayVar[
|
|
1241
|
+
) -> ArrayVar[Sequence[int]]:
|
|
1233
1242
|
"""Create a range of numbers.
|
|
1234
1243
|
|
|
1235
1244
|
Args:
|
|
@@ -1411,7 +1420,7 @@ class LiteralVar(Var):
|
|
|
1411
1420
|
possible_bases = [
|
|
1412
1421
|
base
|
|
1413
1422
|
for base in bases_normalized
|
|
1414
|
-
if
|
|
1423
|
+
if safe_issubclass(base, Var) and base != LiteralVar
|
|
1415
1424
|
]
|
|
1416
1425
|
|
|
1417
1426
|
if not possible_bases:
|
|
@@ -1560,7 +1569,7 @@ def serialize_literal(value: LiteralVar):
|
|
|
1560
1569
|
return value._var_value
|
|
1561
1570
|
|
|
1562
1571
|
|
|
1563
|
-
def get_python_literal(value:
|
|
1572
|
+
def get_python_literal(value: LiteralVar | Any) -> Any | None:
|
|
1564
1573
|
"""Get the Python literal value.
|
|
1565
1574
|
|
|
1566
1575
|
Args:
|
|
@@ -1589,22 +1598,31 @@ def var_operation( # pyright: ignore [reportOverlappingOverload]
|
|
|
1589
1598
|
|
|
1590
1599
|
@overload
|
|
1591
1600
|
def var_operation(
|
|
1592
|
-
func: Callable[P, CustomVarOperationReturn[
|
|
1601
|
+
func: Callable[P, CustomVarOperationReturn[None]],
|
|
1602
|
+
) -> Callable[P, NoneVar]: ...
|
|
1603
|
+
|
|
1604
|
+
|
|
1605
|
+
@overload
|
|
1606
|
+
def var_operation( # pyright: ignore [reportOverlappingOverload]
|
|
1607
|
+
func: Callable[P, CustomVarOperationReturn[bool]]
|
|
1608
|
+
| Callable[P, CustomVarOperationReturn[bool | None]],
|
|
1593
1609
|
) -> Callable[P, BooleanVar]: ...
|
|
1594
1610
|
|
|
1595
1611
|
|
|
1596
|
-
NUMBER_T = TypeVar("NUMBER_T", int, float,
|
|
1612
|
+
NUMBER_T = TypeVar("NUMBER_T", int, float, int | float)
|
|
1597
1613
|
|
|
1598
1614
|
|
|
1599
1615
|
@overload
|
|
1600
1616
|
def var_operation(
|
|
1601
|
-
func: Callable[P, CustomVarOperationReturn[NUMBER_T]]
|
|
1617
|
+
func: Callable[P, CustomVarOperationReturn[NUMBER_T]]
|
|
1618
|
+
| Callable[P, CustomVarOperationReturn[NUMBER_T | None]],
|
|
1602
1619
|
) -> Callable[P, NumberVar[NUMBER_T]]: ...
|
|
1603
1620
|
|
|
1604
1621
|
|
|
1605
1622
|
@overload
|
|
1606
1623
|
def var_operation(
|
|
1607
|
-
func: Callable[P, CustomVarOperationReturn[str]]
|
|
1624
|
+
func: Callable[P, CustomVarOperationReturn[str]]
|
|
1625
|
+
| Callable[P, CustomVarOperationReturn[str | None]],
|
|
1608
1626
|
) -> Callable[P, StringVar]: ...
|
|
1609
1627
|
|
|
1610
1628
|
|
|
@@ -1613,7 +1631,8 @@ LIST_T = TypeVar("LIST_T", bound=Sequence)
|
|
|
1613
1631
|
|
|
1614
1632
|
@overload
|
|
1615
1633
|
def var_operation(
|
|
1616
|
-
func: Callable[P, CustomVarOperationReturn[LIST_T]]
|
|
1634
|
+
func: Callable[P, CustomVarOperationReturn[LIST_T]]
|
|
1635
|
+
| Callable[P, CustomVarOperationReturn[LIST_T | None]],
|
|
1617
1636
|
) -> Callable[P, ArrayVar[LIST_T]]: ...
|
|
1618
1637
|
|
|
1619
1638
|
|
|
@@ -1622,13 +1641,15 @@ OBJECT_TYPE = TypeVar("OBJECT_TYPE", bound=Mapping)
|
|
|
1622
1641
|
|
|
1623
1642
|
@overload
|
|
1624
1643
|
def var_operation(
|
|
1625
|
-
func: Callable[P, CustomVarOperationReturn[OBJECT_TYPE]]
|
|
1644
|
+
func: Callable[P, CustomVarOperationReturn[OBJECT_TYPE]]
|
|
1645
|
+
| Callable[P, CustomVarOperationReturn[OBJECT_TYPE | None]],
|
|
1626
1646
|
) -> Callable[P, ObjectVar[OBJECT_TYPE]]: ...
|
|
1627
1647
|
|
|
1628
1648
|
|
|
1629
1649
|
@overload
|
|
1630
1650
|
def var_operation(
|
|
1631
|
-
func: Callable[P, CustomVarOperationReturn[T]]
|
|
1651
|
+
func: Callable[P, CustomVarOperationReturn[T]]
|
|
1652
|
+
| Callable[P, CustomVarOperationReturn[T | None]],
|
|
1632
1653
|
) -> Callable[P, Var[T]]: ...
|
|
1633
1654
|
|
|
1634
1655
|
|
|
@@ -1687,12 +1708,16 @@ def figure_out_type(value: Any) -> types.GenericType:
|
|
|
1687
1708
|
if has_args(type_):
|
|
1688
1709
|
return type_
|
|
1689
1710
|
if isinstance(value, list):
|
|
1690
|
-
|
|
1711
|
+
if not value:
|
|
1712
|
+
return Sequence[NoReturn]
|
|
1713
|
+
return Sequence[unionize(*(figure_out_type(v) for v in value))]
|
|
1691
1714
|
if isinstance(value, set):
|
|
1692
|
-
return
|
|
1715
|
+
return set[unionize(*(figure_out_type(v) for v in value))]
|
|
1693
1716
|
if isinstance(value, tuple):
|
|
1694
|
-
return
|
|
1717
|
+
return tuple[unionize(*(figure_out_type(v) for v in value)), ...]
|
|
1695
1718
|
if isinstance(value, Mapping):
|
|
1719
|
+
if not value:
|
|
1720
|
+
return Mapping[NoReturn, NoReturn]
|
|
1696
1721
|
return Mapping[
|
|
1697
1722
|
unionize(*(figure_out_type(k) for k in value)),
|
|
1698
1723
|
unionize(*(figure_out_type(v) for v in value.values())),
|
|
@@ -1967,7 +1992,7 @@ class ComputedVar(Var[RETURN_TYPE]):
|
|
|
1967
1992
|
_auto_deps: bool = dataclasses.field(default=True)
|
|
1968
1993
|
|
|
1969
1994
|
# Interval at which the computed var should be updated
|
|
1970
|
-
_update_interval:
|
|
1995
|
+
_update_interval: datetime.timedelta | None = dataclasses.field(default=None)
|
|
1971
1996
|
|
|
1972
1997
|
_fget: Callable[[BaseState], RETURN_TYPE] = dataclasses.field(
|
|
1973
1998
|
default_factory=lambda: lambda _: None
|
|
@@ -1978,9 +2003,9 @@ class ComputedVar(Var[RETURN_TYPE]):
|
|
|
1978
2003
|
fget: Callable[[BASE_STATE], RETURN_TYPE],
|
|
1979
2004
|
initial_value: RETURN_TYPE | types.Unset = types.Unset(),
|
|
1980
2005
|
cache: bool = True,
|
|
1981
|
-
deps:
|
|
2006
|
+
deps: list[str | Var] | None = None,
|
|
1982
2007
|
auto_deps: bool = True,
|
|
1983
|
-
interval:
|
|
2008
|
+
interval: int | datetime.timedelta | None = None,
|
|
1984
2009
|
backend: bool | None = None,
|
|
1985
2010
|
**kwargs,
|
|
1986
2011
|
):
|
|
@@ -2042,7 +2067,7 @@ class ComputedVar(Var[RETURN_TYPE]):
|
|
|
2042
2067
|
|
|
2043
2068
|
def _calculate_static_deps(
|
|
2044
2069
|
self,
|
|
2045
|
-
deps: Union[
|
|
2070
|
+
deps: Union[list[str | Var], dict[str | None, set[str]]] | None = None,
|
|
2046
2071
|
) -> dict[str | None, set[str]]:
|
|
2047
2072
|
"""Calculate the static dependencies of the computed var from user input or existing dependencies.
|
|
2048
2073
|
|
|
@@ -2062,7 +2087,7 @@ class ComputedVar(Var[RETURN_TYPE]):
|
|
|
2062
2087
|
return _static_deps
|
|
2063
2088
|
|
|
2064
2089
|
def _add_static_dep(
|
|
2065
|
-
self, dep:
|
|
2090
|
+
self, dep: str | Var, deps: dict[str | None, set[str]] | None = None
|
|
2066
2091
|
) -> dict[str | None, set[str]]:
|
|
2067
2092
|
"""Add a static dependency to the computed var or existing dependency set.
|
|
2068
2093
|
|
|
@@ -2290,7 +2315,7 @@ class ComputedVar(Var[RETURN_TYPE]):
|
|
|
2290
2315
|
return value
|
|
2291
2316
|
|
|
2292
2317
|
def _check_deprecated_return_type(self, instance: BaseState, value: Any) -> None:
|
|
2293
|
-
if not _isinstance(value, self._var_type):
|
|
2318
|
+
if not _isinstance(value, self._var_type, nested=1, treat_var_as_type=False):
|
|
2294
2319
|
console.error(
|
|
2295
2320
|
f"Computed var '{type(instance).__name__}.{self._js_expr}' must return"
|
|
2296
2321
|
f" type '{self._var_type}', got '{type(value)}'."
|
|
@@ -2417,7 +2442,7 @@ class ComputedVar(Var[RETURN_TYPE]):
|
|
|
2417
2442
|
return self._fget
|
|
2418
2443
|
|
|
2419
2444
|
|
|
2420
|
-
class DynamicRouteVar(ComputedVar[
|
|
2445
|
+
class DynamicRouteVar(ComputedVar[str | list[str]]):
|
|
2421
2446
|
"""A ComputedVar that represents a dynamic route."""
|
|
2422
2447
|
|
|
2423
2448
|
pass
|
|
@@ -2573,9 +2598,9 @@ def computed_var(
|
|
|
2573
2598
|
fget: None = None,
|
|
2574
2599
|
initial_value: Any | types.Unset = types.Unset(),
|
|
2575
2600
|
cache: bool = True,
|
|
2576
|
-
deps:
|
|
2601
|
+
deps: list[str | Var] | None = None,
|
|
2577
2602
|
auto_deps: bool = True,
|
|
2578
|
-
interval:
|
|
2603
|
+
interval: datetime.timedelta | int | None = None,
|
|
2579
2604
|
backend: bool | None = None,
|
|
2580
2605
|
**kwargs,
|
|
2581
2606
|
) -> Callable[[Callable[[BASE_STATE], RETURN_TYPE]], ComputedVar[RETURN_TYPE]]: ... # pyright: ignore [reportInvalidTypeVarUse]
|
|
@@ -2586,9 +2611,9 @@ def computed_var(
|
|
|
2586
2611
|
fget: Callable[[BASE_STATE], RETURN_TYPE],
|
|
2587
2612
|
initial_value: RETURN_TYPE | types.Unset = types.Unset(),
|
|
2588
2613
|
cache: bool = True,
|
|
2589
|
-
deps:
|
|
2614
|
+
deps: list[str | Var] | None = None,
|
|
2590
2615
|
auto_deps: bool = True,
|
|
2591
|
-
interval:
|
|
2616
|
+
interval: datetime.timedelta | int | None = None,
|
|
2592
2617
|
backend: bool | None = None,
|
|
2593
2618
|
**kwargs,
|
|
2594
2619
|
) -> ComputedVar[RETURN_TYPE]: ...
|
|
@@ -2598,9 +2623,9 @@ def computed_var(
|
|
|
2598
2623
|
fget: Callable[[BASE_STATE], Any] | None = None,
|
|
2599
2624
|
initial_value: Any | types.Unset = types.Unset(),
|
|
2600
2625
|
cache: bool = True,
|
|
2601
|
-
deps:
|
|
2626
|
+
deps: list[str | Var] | None = None,
|
|
2602
2627
|
auto_deps: bool = True,
|
|
2603
|
-
interval:
|
|
2628
|
+
interval: datetime.timedelta | int | None = None,
|
|
2604
2629
|
backend: bool | None = None,
|
|
2605
2630
|
**kwargs,
|
|
2606
2631
|
) -> ComputedVar | Callable[[Callable[[BASE_STATE], Any]], ComputedVar]:
|
|
@@ -2701,7 +2726,7 @@ class CustomVarOperationReturn(Var[RETURN]):
|
|
|
2701
2726
|
|
|
2702
2727
|
def var_operation_return(
|
|
2703
2728
|
js_expression: str,
|
|
2704
|
-
var_type: Type[RETURN] | None = None,
|
|
2729
|
+
var_type: Type[RETURN] | GenericType | None = None,
|
|
2705
2730
|
var_data: VarData | None = None,
|
|
2706
2731
|
) -> CustomVarOperationReturn[RETURN]:
|
|
2707
2732
|
"""Shortcut for creating a CustomVarOperationReturn.
|
|
@@ -2731,7 +2756,7 @@ class CustomVarOperation(CachedVarOperation, Var[T]):
|
|
|
2731
2756
|
|
|
2732
2757
|
_name: str = dataclasses.field(default="")
|
|
2733
2758
|
|
|
2734
|
-
_args:
|
|
2759
|
+
_args: tuple[tuple[str, Var], ...] = dataclasses.field(default_factory=tuple)
|
|
2735
2760
|
|
|
2736
2761
|
_return: CustomVarOperationReturn[T] = dataclasses.field(
|
|
2737
2762
|
default_factory=lambda: CustomVarOperationReturn.create("")
|
|
@@ -2763,7 +2788,7 @@ class CustomVarOperation(CachedVarOperation, Var[T]):
|
|
|
2763
2788
|
def create(
|
|
2764
2789
|
cls,
|
|
2765
2790
|
name: str,
|
|
2766
|
-
args:
|
|
2791
|
+
args: tuple[tuple[str, Var], ...],
|
|
2767
2792
|
return_var: CustomVarOperationReturn[T],
|
|
2768
2793
|
_var_data: VarData | None = None,
|
|
2769
2794
|
) -> CustomVarOperation[T]:
|
|
@@ -2966,7 +2991,7 @@ _decode_var_pattern_re = (
|
|
|
2966
2991
|
_decode_var_pattern = re.compile(_decode_var_pattern_re, flags=re.DOTALL)
|
|
2967
2992
|
|
|
2968
2993
|
# Defined global immutable vars.
|
|
2969
|
-
_global_vars:
|
|
2994
|
+
_global_vars: dict[int, Var] = {}
|
|
2970
2995
|
|
|
2971
2996
|
|
|
2972
2997
|
def _extract_var_data(value: Iterable) -> list[VarData | None]:
|
|
@@ -3004,7 +3029,7 @@ def _extract_var_data(value: Iterable) -> list[VarData | None]:
|
|
|
3004
3029
|
return var_datas
|
|
3005
3030
|
|
|
3006
3031
|
|
|
3007
|
-
dispatchers:
|
|
3032
|
+
dispatchers: dict[GenericType, Callable[[Var], Var]] = {}
|
|
3008
3033
|
|
|
3009
3034
|
|
|
3010
3035
|
def transform(fn: Callable[[Var], Var]) -> Callable[[Var], Var]:
|
|
@@ -3049,7 +3074,7 @@ def transform(fn: Callable[[Var], Var]) -> Callable[[Var], Var]:
|
|
|
3049
3074
|
|
|
3050
3075
|
def generic_type_to_actual_type_map(
|
|
3051
3076
|
generic_type: GenericType, actual_type: GenericType
|
|
3052
|
-
) ->
|
|
3077
|
+
) -> dict[TypeVar, GenericType]:
|
|
3053
3078
|
"""Map the generic type to the actual type.
|
|
3054
3079
|
|
|
3055
3080
|
Args:
|
|
@@ -3090,7 +3115,7 @@ def generic_type_to_actual_type_map(
|
|
|
3090
3115
|
|
|
3091
3116
|
|
|
3092
3117
|
def resolve_generic_type_with_mapping(
|
|
3093
|
-
generic_type: GenericType, type_mapping:
|
|
3118
|
+
generic_type: GenericType, type_mapping: dict[TypeVar, GenericType]
|
|
3094
3119
|
):
|
|
3095
3120
|
"""Resolve a generic type with a type mapping.
|
|
3096
3121
|
|
|
@@ -3265,46 +3290,71 @@ class Field(Generic[FIELD_TYPE]):
|
|
|
3265
3290
|
"""
|
|
3266
3291
|
|
|
3267
3292
|
@overload
|
|
3268
|
-
def __get__(self: Field[
|
|
3293
|
+
def __get__(self: Field[None], instance: None, owner: Any) -> NoneVar: ...
|
|
3294
|
+
|
|
3295
|
+
@overload
|
|
3296
|
+
def __get__(
|
|
3297
|
+
self: Field[bool] | Field[bool | None], instance: None, owner: Any
|
|
3298
|
+
) -> BooleanVar: ...
|
|
3269
3299
|
|
|
3270
3300
|
@overload
|
|
3271
3301
|
def __get__(
|
|
3272
|
-
self: Field[int]
|
|
3302
|
+
self: Field[int]
|
|
3303
|
+
| Field[float]
|
|
3304
|
+
| Field[int | float]
|
|
3305
|
+
| Field[int | None]
|
|
3306
|
+
| Field[float | None]
|
|
3307
|
+
| Field[int | float | None],
|
|
3308
|
+
instance: None,
|
|
3309
|
+
owner: Any,
|
|
3273
3310
|
) -> NumberVar: ...
|
|
3274
3311
|
|
|
3275
3312
|
@overload
|
|
3276
|
-
def __get__(
|
|
3313
|
+
def __get__(
|
|
3314
|
+
self: Field[str] | Field[str | None], instance: None, owner: Any
|
|
3315
|
+
) -> StringVar: ...
|
|
3277
3316
|
|
|
3278
3317
|
@overload
|
|
3279
|
-
def __get__(
|
|
3318
|
+
def __get__(
|
|
3319
|
+
self: Field[list[V]]
|
|
3320
|
+
| Field[set[V]]
|
|
3321
|
+
| Field[list[V] | None]
|
|
3322
|
+
| Field[set[V] | None],
|
|
3323
|
+
instance: None,
|
|
3324
|
+
owner: Any,
|
|
3325
|
+
) -> ArrayVar[Sequence[V]]: ...
|
|
3280
3326
|
|
|
3281
3327
|
@overload
|
|
3282
3328
|
def __get__(
|
|
3283
|
-
self: Field[
|
|
3329
|
+
self: Field[SEQUENCE_TYPE] | Field[SEQUENCE_TYPE | None],
|
|
3284
3330
|
instance: None,
|
|
3285
3331
|
owner: Any,
|
|
3286
|
-
) -> ArrayVar[
|
|
3332
|
+
) -> ArrayVar[SEQUENCE_TYPE]: ...
|
|
3287
3333
|
|
|
3288
3334
|
@overload
|
|
3289
3335
|
def __get__(
|
|
3290
|
-
self: Field[MAPPING_TYPE]
|
|
3336
|
+
self: Field[MAPPING_TYPE] | Field[MAPPING_TYPE | None],
|
|
3337
|
+
instance: None,
|
|
3338
|
+
owner: Any,
|
|
3291
3339
|
) -> ObjectVar[MAPPING_TYPE]: ...
|
|
3292
3340
|
|
|
3293
3341
|
@overload
|
|
3294
3342
|
def __get__(
|
|
3295
|
-
self: Field[BASE_TYPE], instance: None, owner: Any
|
|
3343
|
+
self: Field[BASE_TYPE] | Field[BASE_TYPE | None], instance: None, owner: Any
|
|
3296
3344
|
) -> ObjectVar[BASE_TYPE]: ...
|
|
3297
3345
|
|
|
3298
3346
|
@overload
|
|
3299
3347
|
def __get__(
|
|
3300
|
-
self: Field[SQLA_TYPE], instance: None, owner: Any
|
|
3348
|
+
self: Field[SQLA_TYPE] | Field[SQLA_TYPE | None], instance: None, owner: Any
|
|
3301
3349
|
) -> ObjectVar[SQLA_TYPE]: ...
|
|
3302
3350
|
|
|
3303
3351
|
if TYPE_CHECKING:
|
|
3304
3352
|
|
|
3305
3353
|
@overload
|
|
3306
3354
|
def __get__(
|
|
3307
|
-
self: Field[DATACLASS_TYPE]
|
|
3355
|
+
self: Field[DATACLASS_TYPE] | Field[DATACLASS_TYPE | None],
|
|
3356
|
+
instance: None,
|
|
3357
|
+
owner: Any,
|
|
3308
3358
|
) -> ObjectVar[DATACLASS_TYPE]: ...
|
|
3309
3359
|
|
|
3310
3360
|
@overload
|
reflex/vars/datetime.py
CHANGED
|
@@ -4,7 +4,7 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import dataclasses
|
|
6
6
|
from datetime import date, datetime
|
|
7
|
-
from typing import Any, NoReturn, TypeVar,
|
|
7
|
+
from typing import Any, NoReturn, TypeVar, overload
|
|
8
8
|
|
|
9
9
|
from reflex.utils.exceptions import VarTypeError
|
|
10
10
|
from reflex.vars.number import BooleanVar
|
|
@@ -20,7 +20,7 @@ from .base import (
|
|
|
20
20
|
|
|
21
21
|
DATETIME_T = TypeVar("DATETIME_T", datetime, date)
|
|
22
22
|
|
|
23
|
-
datetime_types =
|
|
23
|
+
datetime_types = datetime | date
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
def raise_var_type_error():
|