reflex 0.5.10a3__py3-none-any.whl → 0.6.0__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 +4 -4
- reflex/.templates/jinja/web/utils/context.js.jinja2 +1 -1
- reflex/.templates/jinja/web/utils/theme.js.jinja2 +1 -1
- reflex/.templates/web/utils/state.js +3 -1
- reflex/__init__.py +10 -3
- reflex/__init__.pyi +3 -2
- reflex/app.py +47 -11
- reflex/app_module_for_backend.py +1 -1
- reflex/base.py +3 -2
- reflex/compiler/compiler.py +5 -5
- reflex/compiler/utils.py +5 -3
- reflex/components/base/app_wrap.py +2 -4
- reflex/components/base/app_wrap.pyi +16 -26
- reflex/components/base/bare.py +6 -4
- reflex/components/base/body.pyi +16 -26
- reflex/components/base/document.pyi +76 -126
- reflex/components/base/error_boundary.py +9 -8
- reflex/components/base/error_boundary.pyi +18 -30
- reflex/components/base/fragment.pyi +16 -26
- reflex/components/base/head.pyi +31 -51
- reflex/components/base/link.py +1 -1
- reflex/components/base/link.pyi +31 -51
- reflex/components/base/meta.pyi +61 -101
- reflex/components/base/script.py +2 -2
- reflex/components/base/script.pyi +20 -36
- reflex/components/component.py +107 -130
- reflex/components/core/banner.py +61 -66
- reflex/components/core/banner.pyi +129 -230
- reflex/components/core/client_side_routing.py +2 -2
- reflex/components/core/client_side_routing.pyi +31 -51
- reflex/components/core/clipboard.py +4 -3
- reflex/components/core/clipboard.pyi +19 -31
- reflex/components/core/cond.py +21 -44
- reflex/components/core/debounce.py +7 -9
- reflex/components/core/debounce.pyi +19 -31
- reflex/components/core/foreach.py +4 -14
- reflex/components/core/html.py +1 -1
- reflex/components/core/html.pyi +34 -44
- reflex/components/core/match.py +36 -43
- reflex/components/core/upload.py +27 -26
- reflex/components/core/upload.pyi +81 -116
- reflex/components/datadisplay/code.py +55 -29
- reflex/components/datadisplay/code.pyi +303 -410
- reflex/components/datadisplay/dataeditor.py +13 -9
- reflex/components/datadisplay/dataeditor.pyi +39 -51
- reflex/components/el/__init__.py +0 -1
- reflex/components/el/__init__.pyi +0 -11
- reflex/components/el/element.pyi +16 -26
- reflex/components/el/elements/__init__.py +1 -7
- reflex/components/el/elements/__init__.pyi +1 -15
- reflex/components/el/elements/base.py +1 -1
- reflex/components/el/elements/base.pyi +33 -43
- reflex/components/el/elements/forms.py +26 -33
- reflex/components/el/elements/forms.pyi +542 -694
- reflex/components/el/elements/inline.py +1 -1
- reflex/components/el/elements/inline.pyi +909 -1189
- reflex/components/el/elements/media.py +1 -22
- reflex/components/el/elements/media.pyi +765 -975
- reflex/components/el/elements/metadata.py +3 -5
- reflex/components/el/elements/metadata.pyi +175 -235
- reflex/components/el/elements/other.py +1 -1
- reflex/components/el/elements/other.pyi +228 -298
- reflex/components/el/elements/scripts.py +1 -1
- reflex/components/el/elements/scripts.pyi +106 -136
- reflex/components/el/elements/sectioning.py +0 -2
- reflex/components/el/elements/sectioning.pyi +481 -631
- reflex/components/el/elements/tables.py +1 -1
- reflex/components/el/elements/tables.pyi +341 -441
- reflex/components/el/elements/typography.py +1 -1
- reflex/components/el/elements/typography.pyi +491 -641
- reflex/components/gridjs/datatable.py +9 -13
- reflex/components/gridjs/datatable.pyi +33 -53
- reflex/components/lucide/icon.py +3 -127
- reflex/components/lucide/icon.pyi +31 -160
- reflex/components/markdown/markdown.py +32 -42
- reflex/components/markdown/markdown.pyi +28 -41
- reflex/components/moment/moment.py +13 -12
- reflex/components/moment/moment.pyi +22 -33
- reflex/components/next/base.pyi +16 -26
- reflex/components/next/image.py +1 -5
- reflex/components/next/image.pyi +21 -35
- reflex/components/next/link.py +1 -1
- reflex/components/next/link.pyi +16 -26
- reflex/components/next/video.py +1 -1
- reflex/components/next/video.pyi +16 -26
- reflex/components/plotly/plotly.py +17 -30
- reflex/components/plotly/plotly.pyi +38 -52
- reflex/components/props.py +21 -10
- reflex/components/radix/__init__.pyi +2 -1
- reflex/components/radix/primitives/accordion.py +6 -7
- reflex/components/radix/primitives/accordion.pyi +415 -485
- reflex/components/radix/primitives/base.py +1 -1
- reflex/components/radix/primitives/base.pyi +31 -51
- reflex/components/radix/primitives/drawer.py +1 -1
- reflex/components/radix/primitives/drawer.pyi +162 -262
- reflex/components/radix/primitives/form.py +1 -1
- reflex/components/radix/primitives/form.pyi +247 -353
- reflex/components/radix/primitives/progress.py +1 -1
- reflex/components/radix/primitives/progress.pyi +226 -276
- reflex/components/radix/primitives/slider.py +1 -1
- reflex/components/radix/primitives/slider.pyi +82 -132
- reflex/components/radix/themes/base.py +8 -25
- reflex/components/radix/themes/base.pyi +171 -242
- reflex/components/radix/themes/color_mode.py +11 -20
- reflex/components/radix/themes/color_mode.pyi +198 -231
- reflex/components/radix/themes/components/__init__.pyi +1 -0
- reflex/components/radix/themes/components/alert_dialog.py +1 -1
- reflex/components/radix/themes/components/alert_dialog.pyi +129 -199
- reflex/components/radix/themes/components/aspect_ratio.py +1 -1
- reflex/components/radix/themes/components/aspect_ratio.pyi +16 -26
- reflex/components/radix/themes/components/avatar.py +1 -1
- reflex/components/radix/themes/components/avatar.pyi +69 -79
- reflex/components/radix/themes/components/badge.py +1 -1
- reflex/components/radix/themes/components/badge.pyi +87 -97
- reflex/components/radix/themes/components/button.py +1 -1
- reflex/components/radix/themes/components/button.pyi +97 -107
- reflex/components/radix/themes/components/callout.py +1 -1
- reflex/components/radix/themes/components/callout.pyi +317 -367
- reflex/components/radix/themes/components/card.py +1 -1
- reflex/components/radix/themes/components/card.pyi +37 -47
- reflex/components/radix/themes/components/checkbox.py +2 -4
- reflex/components/radix/themes/components/checkbox.pyi +205 -241
- reflex/components/radix/themes/components/checkbox_cards.py +1 -1
- reflex/components/radix/themes/components/checkbox_cards.pyi +92 -112
- reflex/components/radix/themes/components/checkbox_group.py +1 -1
- reflex/components/radix/themes/components/checkbox_group.pyi +84 -104
- reflex/components/radix/themes/components/context_menu.py +1 -1
- reflex/components/radix/themes/components/context_menu.pyi +230 -310
- reflex/components/radix/themes/components/data_list.py +6 -1
- reflex/components/radix/themes/components/data_list.pyi +131 -166
- reflex/components/radix/themes/components/dialog.py +1 -1
- reflex/components/radix/themes/components/dialog.pyi +132 -202
- reflex/components/radix/themes/components/dropdown_menu.py +1 -1
- reflex/components/radix/themes/components/dropdown_menu.pyi +241 -323
- reflex/components/radix/themes/components/hover_card.py +1 -1
- reflex/components/radix/themes/components/hover_card.pyi +86 -126
- reflex/components/radix/themes/components/icon_button.py +1 -1
- reflex/components/radix/themes/components/icon_button.pyi +97 -107
- reflex/components/radix/themes/components/inset.py +1 -1
- reflex/components/radix/themes/components/inset.pyi +46 -56
- reflex/components/radix/themes/components/popover.py +1 -1
- reflex/components/radix/themes/components/popover.pyi +91 -131
- reflex/components/radix/themes/components/progress.py +1 -1
- reflex/components/radix/themes/components/progress.pyi +70 -80
- reflex/components/radix/themes/components/radio.py +1 -1
- reflex/components/radix/themes/components/radio.pyi +68 -78
- reflex/components/radix/themes/components/radio_cards.py +1 -1
- reflex/components/radix/themes/components/radio_cards.pyi +96 -116
- reflex/components/radix/themes/components/radio_group.py +32 -31
- reflex/components/radix/themes/components/radio_group.pyi +230 -266
- reflex/components/radix/themes/components/scroll_area.py +1 -1
- reflex/components/radix/themes/components/scroll_area.pyi +20 -30
- reflex/components/radix/themes/components/segmented_control.py +1 -1
- reflex/components/radix/themes/components/segmented_control.pyi +88 -110
- reflex/components/radix/themes/components/select.py +1 -1
- reflex/components/radix/themes/components/select.pyi +365 -461
- reflex/components/radix/themes/components/separator.py +2 -4
- reflex/components/radix/themes/components/separator.pyi +68 -78
- reflex/components/radix/themes/components/skeleton.py +1 -1
- reflex/components/radix/themes/components/skeleton.pyi +22 -32
- reflex/components/radix/themes/components/slider.py +1 -1
- reflex/components/radix/themes/components/slider.pyi +74 -86
- reflex/components/radix/themes/components/spinner.py +1 -1
- reflex/components/radix/themes/components/spinner.pyi +18 -28
- reflex/components/radix/themes/components/switch.py +1 -1
- reflex/components/radix/themes/components/switch.pyi +70 -82
- reflex/components/radix/themes/components/table.py +1 -1
- reflex/components/radix/themes/components/table.pyi +254 -324
- reflex/components/radix/themes/components/tabs.py +1 -1
- reflex/components/radix/themes/components/tabs.pyi +134 -188
- reflex/components/radix/themes/components/text_area.py +1 -1
- reflex/components/radix/themes/components/text_area.pyi +95 -109
- reflex/components/radix/themes/components/text_field.py +1 -80
- reflex/components/radix/themes/components/text_field.pyi +245 -290
- reflex/components/radix/themes/components/tooltip.py +1 -1
- reflex/components/radix/themes/components/tooltip.pyi +25 -35
- 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 +55 -65
- reflex/components/radix/themes/layout/box.pyi +33 -43
- reflex/components/radix/themes/layout/center.pyi +55 -65
- reflex/components/radix/themes/layout/container.py +2 -4
- reflex/components/radix/themes/layout/container.pyi +35 -45
- reflex/components/radix/themes/layout/flex.py +1 -1
- reflex/components/radix/themes/layout/flex.pyi +55 -65
- reflex/components/radix/themes/layout/grid.py +1 -1
- reflex/components/radix/themes/layout/grid.pyi +63 -73
- reflex/components/radix/themes/layout/list.py +1 -1
- reflex/components/radix/themes/layout/list.pyi +188 -238
- reflex/components/radix/themes/layout/section.py +2 -4
- reflex/components/radix/themes/layout/section.pyi +35 -45
- reflex/components/radix/themes/layout/spacer.pyi +55 -65
- reflex/components/radix/themes/layout/stack.py +1 -1
- reflex/components/radix/themes/layout/stack.pyi +125 -155
- reflex/components/radix/themes/typography/blockquote.py +1 -1
- reflex/components/radix/themes/typography/blockquote.pyi +88 -98
- reflex/components/radix/themes/typography/code.py +1 -1
- reflex/components/radix/themes/typography/code.pyi +89 -99
- reflex/components/radix/themes/typography/heading.py +1 -1
- reflex/components/radix/themes/typography/heading.pyi +95 -105
- reflex/components/radix/themes/typography/link.py +1 -1
- reflex/components/radix/themes/typography/link.pyi +101 -111
- reflex/components/radix/themes/typography/text.py +1 -1
- reflex/components/radix/themes/typography/text.pyi +494 -564
- reflex/components/react_player/audio.pyi +32 -58
- reflex/components/react_player/react_player.py +1 -1
- reflex/components/react_player/react_player.pyi +32 -58
- reflex/components/react_player/video.pyi +32 -58
- reflex/components/recharts/cartesian.py +22 -19
- reflex/components/recharts/cartesian.pyi +658 -840
- reflex/components/recharts/charts.py +3 -3
- reflex/components/recharts/charts.pyi +238 -342
- reflex/components/recharts/general.py +8 -8
- reflex/components/recharts/general.pyi +175 -225
- reflex/components/recharts/polar.py +11 -11
- reflex/components/recharts/polar.pyi +135 -171
- reflex/components/recharts/recharts.pyi +31 -51
- reflex/components/sonner/toast.py +27 -31
- reflex/components/sonner/toast.pyi +36 -45
- reflex/components/suneditor/editor.py +1 -1
- reflex/components/suneditor/editor.pyi +54 -76
- reflex/components/tags/cond_tag.py +6 -4
- reflex/components/tags/iter_tag.py +37 -25
- reflex/components/tags/match_tag.py +6 -4
- reflex/components/tags/tag.py +43 -28
- reflex/constants/base.py +3 -1
- reflex/constants/event.py +1 -0
- reflex/custom_components/custom_components.py +3 -1
- reflex/event.py +166 -108
- reflex/experimental/__init__.py +25 -6
- reflex/experimental/client_state.py +34 -57
- reflex/experimental/hooks.py +12 -17
- reflex/experimental/layout.py +4 -4
- reflex/experimental/layout.pyi +130 -180
- reflex/middleware/hydrate_middleware.py +2 -0
- reflex/middleware/middleware.py +3 -3
- reflex/model.py +22 -0
- reflex/reflex.py +4 -0
- reflex/state.py +491 -110
- reflex/style.py +56 -39
- reflex/testing.py +8 -3
- reflex/utils/exceptions.py +32 -0
- reflex/utils/exec.py +0 -14
- reflex/utils/format.py +80 -209
- reflex/utils/imports.py +16 -73
- reflex/utils/net.py +43 -0
- reflex/utils/path_ops.py +13 -1
- reflex/utils/prerequisites.py +81 -41
- reflex/utils/pyi_generator.py +12 -6
- reflex/utils/serializers.py +13 -41
- reflex/utils/telemetry.py +3 -2
- reflex/utils/types.py +47 -7
- reflex/{experimental/vars → vars}/__init__.py +6 -3
- reflex/vars/base.py +2563 -0
- reflex/vars/function.py +196 -0
- reflex/vars/number.py +1158 -0
- reflex/vars/object.py +562 -0
- reflex/vars/sequence.py +1604 -0
- {reflex-0.5.10a3.dist-info → reflex-0.6.0.dist-info}/METADATA +6 -9
- reflex-0.6.0.dist-info/RECORD +382 -0
- reflex/.templates/apps/demo/.gitignore +0 -4
- reflex/.templates/apps/demo/assets/favicon.ico +0 -0
- reflex/.templates/apps/demo/assets/github.svg +0 -10
- reflex/.templates/apps/demo/assets/icon.svg +0 -37
- reflex/.templates/apps/demo/assets/logo.svg +0 -68
- reflex/.templates/apps/demo/assets/paneleft.svg +0 -13
- reflex/.templates/apps/demo/code/__init__.py +0 -1
- reflex/.templates/apps/demo/code/demo.py +0 -127
- reflex/.templates/apps/demo/code/pages/__init__.py +0 -7
- reflex/.templates/apps/demo/code/pages/chatapp.py +0 -31
- reflex/.templates/apps/demo/code/pages/datatable.py +0 -360
- reflex/.templates/apps/demo/code/pages/forms.py +0 -257
- reflex/.templates/apps/demo/code/pages/graphing.py +0 -253
- reflex/.templates/apps/demo/code/pages/home.py +0 -56
- reflex/.templates/apps/demo/code/sidebar.py +0 -178
- reflex/.templates/apps/demo/code/state.py +0 -22
- reflex/.templates/apps/demo/code/states/form_state.py +0 -40
- reflex/.templates/apps/demo/code/states/pie_state.py +0 -47
- reflex/.templates/apps/demo/code/styles.py +0 -68
- reflex/.templates/apps/demo/code/webui/__init__.py +0 -0
- reflex/.templates/apps/demo/code/webui/components/__init__.py +0 -4
- reflex/.templates/apps/demo/code/webui/components/chat.py +0 -118
- reflex/.templates/apps/demo/code/webui/components/loading_icon.py +0 -19
- reflex/.templates/apps/demo/code/webui/components/modal.py +0 -56
- reflex/.templates/apps/demo/code/webui/components/navbar.py +0 -70
- reflex/.templates/apps/demo/code/webui/components/sidebar.py +0 -66
- reflex/.templates/apps/demo/code/webui/state.py +0 -146
- reflex/.templates/apps/demo/code/webui/styles.py +0 -88
- reflex/.templates/web/components/reflex/chakra_color_mode_provider.js +0 -36
- reflex/experimental/vars/base.py +0 -583
- reflex/experimental/vars/function.py +0 -290
- reflex/experimental/vars/number.py +0 -1458
- reflex/experimental/vars/object.py +0 -804
- reflex/experimental/vars/sequence.py +0 -1764
- reflex/utils/watch.py +0 -96
- reflex/vars.py +0 -2604
- reflex/vars.pyi +0 -218
- reflex-0.5.10a3.dist-info/RECORD +0 -413
- {reflex-0.5.10a3.dist-info → reflex-0.6.0.dist-info}/LICENSE +0 -0
- {reflex-0.5.10a3.dist-info → reflex-0.6.0.dist-info}/WHEEL +0 -0
- {reflex-0.5.10a3.dist-info → reflex-0.6.0.dist-info}/entry_points.txt +0 -0
|
@@ -1,1764 +0,0 @@
|
|
|
1
|
-
"""Collection of string classes and utilities."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
import dataclasses
|
|
6
|
-
import functools
|
|
7
|
-
import inspect
|
|
8
|
-
import json
|
|
9
|
-
import re
|
|
10
|
-
import sys
|
|
11
|
-
import typing
|
|
12
|
-
from functools import cached_property
|
|
13
|
-
from typing import (
|
|
14
|
-
TYPE_CHECKING,
|
|
15
|
-
Any,
|
|
16
|
-
Dict,
|
|
17
|
-
List,
|
|
18
|
-
Literal,
|
|
19
|
-
Set,
|
|
20
|
-
Tuple,
|
|
21
|
-
TypeVar,
|
|
22
|
-
Union,
|
|
23
|
-
overload,
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
from typing_extensions import get_origin
|
|
27
|
-
|
|
28
|
-
from reflex import constants
|
|
29
|
-
from reflex.constants.base import REFLEX_VAR_OPENING_TAG
|
|
30
|
-
from reflex.experimental.vars.base import (
|
|
31
|
-
ImmutableVar,
|
|
32
|
-
LiteralVar,
|
|
33
|
-
figure_out_type,
|
|
34
|
-
unionize,
|
|
35
|
-
)
|
|
36
|
-
from reflex.experimental.vars.number import (
|
|
37
|
-
BooleanVar,
|
|
38
|
-
LiteralNumberVar,
|
|
39
|
-
NotEqualOperation,
|
|
40
|
-
NumberVar,
|
|
41
|
-
)
|
|
42
|
-
from reflex.utils.types import GenericType
|
|
43
|
-
from reflex.vars import ImmutableVarData, Var, VarData, _global_vars
|
|
44
|
-
|
|
45
|
-
if TYPE_CHECKING:
|
|
46
|
-
from .object import ObjectVar
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
class StringVar(ImmutableVar[str]):
|
|
50
|
-
"""Base class for immutable string vars."""
|
|
51
|
-
|
|
52
|
-
def __add__(self, other: StringVar | str) -> ConcatVarOperation:
|
|
53
|
-
"""Concatenate two strings.
|
|
54
|
-
|
|
55
|
-
Args:
|
|
56
|
-
other: The other string.
|
|
57
|
-
|
|
58
|
-
Returns:
|
|
59
|
-
The string concatenation operation.
|
|
60
|
-
"""
|
|
61
|
-
return ConcatVarOperation(self, other)
|
|
62
|
-
|
|
63
|
-
def __radd__(self, other: StringVar | str) -> ConcatVarOperation:
|
|
64
|
-
"""Concatenate two strings.
|
|
65
|
-
|
|
66
|
-
Args:
|
|
67
|
-
other: The other string.
|
|
68
|
-
|
|
69
|
-
Returns:
|
|
70
|
-
The string concatenation operation.
|
|
71
|
-
"""
|
|
72
|
-
return ConcatVarOperation(other, self)
|
|
73
|
-
|
|
74
|
-
def __mul__(self, other: int) -> ConcatVarOperation:
|
|
75
|
-
"""Concatenate two strings.
|
|
76
|
-
|
|
77
|
-
Args:
|
|
78
|
-
other: The other string.
|
|
79
|
-
|
|
80
|
-
Returns:
|
|
81
|
-
The string concatenation operation.
|
|
82
|
-
"""
|
|
83
|
-
return ConcatVarOperation(*[self for _ in range(other)])
|
|
84
|
-
|
|
85
|
-
def __rmul__(self, other: int) -> ConcatVarOperation:
|
|
86
|
-
"""Concatenate two strings.
|
|
87
|
-
|
|
88
|
-
Args:
|
|
89
|
-
other: The other string.
|
|
90
|
-
|
|
91
|
-
Returns:
|
|
92
|
-
The string concatenation operation.
|
|
93
|
-
"""
|
|
94
|
-
return ConcatVarOperation(*[self for _ in range(other)])
|
|
95
|
-
|
|
96
|
-
@overload
|
|
97
|
-
def __getitem__(self, i: slice) -> ArrayJoinOperation: ...
|
|
98
|
-
|
|
99
|
-
@overload
|
|
100
|
-
def __getitem__(self, i: int | NumberVar) -> StringItemOperation: ...
|
|
101
|
-
|
|
102
|
-
def __getitem__(
|
|
103
|
-
self, i: slice | int | NumberVar
|
|
104
|
-
) -> ArrayJoinOperation | StringItemOperation:
|
|
105
|
-
"""Get a slice of the string.
|
|
106
|
-
|
|
107
|
-
Args:
|
|
108
|
-
i: The slice.
|
|
109
|
-
|
|
110
|
-
Returns:
|
|
111
|
-
The string slice operation.
|
|
112
|
-
"""
|
|
113
|
-
if isinstance(i, slice):
|
|
114
|
-
return self.split()[i].join()
|
|
115
|
-
return StringItemOperation(self, i)
|
|
116
|
-
|
|
117
|
-
def length(self) -> NumberVar:
|
|
118
|
-
"""Get the length of the string.
|
|
119
|
-
|
|
120
|
-
Returns:
|
|
121
|
-
The string length operation.
|
|
122
|
-
"""
|
|
123
|
-
return self.split().length()
|
|
124
|
-
|
|
125
|
-
def lower(self) -> StringLowerOperation:
|
|
126
|
-
"""Convert the string to lowercase.
|
|
127
|
-
|
|
128
|
-
Returns:
|
|
129
|
-
The string lower operation.
|
|
130
|
-
"""
|
|
131
|
-
return StringLowerOperation(self)
|
|
132
|
-
|
|
133
|
-
def upper(self) -> StringUpperOperation:
|
|
134
|
-
"""Convert the string to uppercase.
|
|
135
|
-
|
|
136
|
-
Returns:
|
|
137
|
-
The string upper operation.
|
|
138
|
-
"""
|
|
139
|
-
return StringUpperOperation(self)
|
|
140
|
-
|
|
141
|
-
def strip(self) -> StringStripOperation:
|
|
142
|
-
"""Strip the string.
|
|
143
|
-
|
|
144
|
-
Returns:
|
|
145
|
-
The string strip operation.
|
|
146
|
-
"""
|
|
147
|
-
return StringStripOperation(self)
|
|
148
|
-
|
|
149
|
-
def bool(self) -> NotEqualOperation:
|
|
150
|
-
"""Boolean conversion.
|
|
151
|
-
|
|
152
|
-
Returns:
|
|
153
|
-
The boolean value of the string.
|
|
154
|
-
"""
|
|
155
|
-
return NotEqualOperation(self.length(), 0)
|
|
156
|
-
|
|
157
|
-
def reversed(self) -> ArrayJoinOperation:
|
|
158
|
-
"""Reverse the string.
|
|
159
|
-
|
|
160
|
-
Returns:
|
|
161
|
-
The string reverse operation.
|
|
162
|
-
"""
|
|
163
|
-
return self.split().reverse().join()
|
|
164
|
-
|
|
165
|
-
def contains(self, other: StringVar | str) -> StringContainsOperation:
|
|
166
|
-
"""Check if the string contains another string.
|
|
167
|
-
|
|
168
|
-
Args:
|
|
169
|
-
other: The other string.
|
|
170
|
-
|
|
171
|
-
Returns:
|
|
172
|
-
The string contains operation.
|
|
173
|
-
"""
|
|
174
|
-
return StringContainsOperation(self, other)
|
|
175
|
-
|
|
176
|
-
def split(self, separator: StringVar | str = "") -> StringSplitOperation:
|
|
177
|
-
"""Split the string.
|
|
178
|
-
|
|
179
|
-
Args:
|
|
180
|
-
separator: The separator.
|
|
181
|
-
|
|
182
|
-
Returns:
|
|
183
|
-
The string split operation.
|
|
184
|
-
"""
|
|
185
|
-
return StringSplitOperation(self, separator)
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
@dataclasses.dataclass(
|
|
189
|
-
eq=False,
|
|
190
|
-
frozen=True,
|
|
191
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
192
|
-
)
|
|
193
|
-
class StringToStringOperation(StringVar):
|
|
194
|
-
"""Base class for immutable string vars that are the result of a string to string operation."""
|
|
195
|
-
|
|
196
|
-
a: StringVar = dataclasses.field(
|
|
197
|
-
default_factory=lambda: LiteralStringVar.create("")
|
|
198
|
-
)
|
|
199
|
-
|
|
200
|
-
def __init__(self, a: StringVar | str, _var_data: VarData | None = None):
|
|
201
|
-
"""Initialize the string to string operation var.
|
|
202
|
-
|
|
203
|
-
Args:
|
|
204
|
-
a: The string.
|
|
205
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
206
|
-
"""
|
|
207
|
-
super(StringToStringOperation, self).__init__(
|
|
208
|
-
_var_name="",
|
|
209
|
-
_var_type=str,
|
|
210
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
211
|
-
)
|
|
212
|
-
object.__setattr__(
|
|
213
|
-
self, "a", a if isinstance(a, Var) else LiteralStringVar.create(a)
|
|
214
|
-
)
|
|
215
|
-
object.__delattr__(self, "_var_name")
|
|
216
|
-
|
|
217
|
-
@cached_property
|
|
218
|
-
def _cached_var_name(self) -> str:
|
|
219
|
-
"""The name of the var.
|
|
220
|
-
|
|
221
|
-
Raises:
|
|
222
|
-
NotImplementedError: Must be implemented by subclasses.
|
|
223
|
-
"""
|
|
224
|
-
raise NotImplementedError(
|
|
225
|
-
"StringToStringOperation must implement _cached_var_name"
|
|
226
|
-
)
|
|
227
|
-
|
|
228
|
-
def __getattr__(self, name: str) -> Any:
|
|
229
|
-
"""Get an attribute of the var.
|
|
230
|
-
|
|
231
|
-
Args:
|
|
232
|
-
name: The name of the attribute.
|
|
233
|
-
|
|
234
|
-
Returns:
|
|
235
|
-
The attribute value.
|
|
236
|
-
"""
|
|
237
|
-
if name == "_var_name":
|
|
238
|
-
return self._cached_var_name
|
|
239
|
-
getattr(super(StringToStringOperation, self), name)
|
|
240
|
-
|
|
241
|
-
@cached_property
|
|
242
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
243
|
-
"""Get all VarData associated with the Var.
|
|
244
|
-
|
|
245
|
-
Returns:
|
|
246
|
-
The VarData of the components and all of its children.
|
|
247
|
-
"""
|
|
248
|
-
return ImmutableVarData.merge(
|
|
249
|
-
self.a._get_all_var_data() if isinstance(self.a, Var) else None,
|
|
250
|
-
self._var_data,
|
|
251
|
-
)
|
|
252
|
-
|
|
253
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
254
|
-
return self._cached_get_all_var_data
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
class StringLowerOperation(StringToStringOperation):
|
|
258
|
-
"""Base class for immutable string vars that are the result of a string lower operation."""
|
|
259
|
-
|
|
260
|
-
@cached_property
|
|
261
|
-
def _cached_var_name(self) -> str:
|
|
262
|
-
"""The name of the var.
|
|
263
|
-
|
|
264
|
-
Returns:
|
|
265
|
-
The name of the var.
|
|
266
|
-
"""
|
|
267
|
-
return f"{str(self.a)}.toLowerCase()"
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
class StringUpperOperation(StringToStringOperation):
|
|
271
|
-
"""Base class for immutable string vars that are the result of a string upper operation."""
|
|
272
|
-
|
|
273
|
-
@cached_property
|
|
274
|
-
def _cached_var_name(self) -> str:
|
|
275
|
-
"""The name of the var.
|
|
276
|
-
|
|
277
|
-
Returns:
|
|
278
|
-
The name of the var.
|
|
279
|
-
"""
|
|
280
|
-
return f"{str(self.a)}.toUpperCase()"
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
class StringStripOperation(StringToStringOperation):
|
|
284
|
-
"""Base class for immutable string vars that are the result of a string strip operation."""
|
|
285
|
-
|
|
286
|
-
@cached_property
|
|
287
|
-
def _cached_var_name(self) -> str:
|
|
288
|
-
"""The name of the var.
|
|
289
|
-
|
|
290
|
-
Returns:
|
|
291
|
-
The name of the var.
|
|
292
|
-
"""
|
|
293
|
-
return f"{str(self.a)}.trim()"
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
@dataclasses.dataclass(
|
|
297
|
-
eq=False,
|
|
298
|
-
frozen=True,
|
|
299
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
300
|
-
)
|
|
301
|
-
class StringContainsOperation(BooleanVar):
|
|
302
|
-
"""Base class for immutable boolean vars that are the result of a string contains operation."""
|
|
303
|
-
|
|
304
|
-
a: StringVar = dataclasses.field(
|
|
305
|
-
default_factory=lambda: LiteralStringVar.create("")
|
|
306
|
-
)
|
|
307
|
-
b: StringVar = dataclasses.field(
|
|
308
|
-
default_factory=lambda: LiteralStringVar.create("")
|
|
309
|
-
)
|
|
310
|
-
|
|
311
|
-
def __init__(
|
|
312
|
-
self, a: StringVar | str, b: StringVar | str, _var_data: VarData | None = None
|
|
313
|
-
):
|
|
314
|
-
"""Initialize the string contains operation var.
|
|
315
|
-
|
|
316
|
-
Args:
|
|
317
|
-
a: The first string.
|
|
318
|
-
b: The second string.
|
|
319
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
320
|
-
"""
|
|
321
|
-
super(StringContainsOperation, self).__init__(
|
|
322
|
-
_var_name="",
|
|
323
|
-
_var_type=bool,
|
|
324
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
325
|
-
)
|
|
326
|
-
object.__setattr__(
|
|
327
|
-
self, "a", a if isinstance(a, Var) else LiteralStringVar.create(a)
|
|
328
|
-
)
|
|
329
|
-
object.__setattr__(
|
|
330
|
-
self, "b", b if isinstance(b, Var) else LiteralStringVar.create(b)
|
|
331
|
-
)
|
|
332
|
-
object.__delattr__(self, "_var_name")
|
|
333
|
-
|
|
334
|
-
@cached_property
|
|
335
|
-
def _cached_var_name(self) -> str:
|
|
336
|
-
"""The name of the var.
|
|
337
|
-
|
|
338
|
-
Returns:
|
|
339
|
-
The name of the var.
|
|
340
|
-
"""
|
|
341
|
-
return f"{str(self.a)}.includes({str(self.b)})"
|
|
342
|
-
|
|
343
|
-
def __getattr__(self, name: str) -> Any:
|
|
344
|
-
"""Get an attribute of the var.
|
|
345
|
-
|
|
346
|
-
Args:
|
|
347
|
-
name: The name of the attribute.
|
|
348
|
-
|
|
349
|
-
Returns:
|
|
350
|
-
The attribute value.
|
|
351
|
-
"""
|
|
352
|
-
if name == "_var_name":
|
|
353
|
-
return self._cached_var_name
|
|
354
|
-
getattr(super(StringContainsOperation, self), name)
|
|
355
|
-
|
|
356
|
-
@cached_property
|
|
357
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
358
|
-
"""Get all VarData associated with the Var.
|
|
359
|
-
|
|
360
|
-
Returns:
|
|
361
|
-
The VarData of the components and all of its children.
|
|
362
|
-
"""
|
|
363
|
-
return ImmutableVarData.merge(
|
|
364
|
-
self.a._get_all_var_data(), self.b._get_all_var_data(), self._var_data
|
|
365
|
-
)
|
|
366
|
-
|
|
367
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
368
|
-
return self._cached_get_all_var_data
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
@dataclasses.dataclass(
|
|
372
|
-
eq=False,
|
|
373
|
-
frozen=True,
|
|
374
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
375
|
-
)
|
|
376
|
-
class StringItemOperation(StringVar):
|
|
377
|
-
"""Base class for immutable string vars that are the result of a string item operation."""
|
|
378
|
-
|
|
379
|
-
a: StringVar = dataclasses.field(
|
|
380
|
-
default_factory=lambda: LiteralStringVar.create("")
|
|
381
|
-
)
|
|
382
|
-
i: NumberVar = dataclasses.field(default_factory=lambda: LiteralNumberVar(0))
|
|
383
|
-
|
|
384
|
-
def __init__(
|
|
385
|
-
self, a: StringVar | str, i: int | NumberVar, _var_data: VarData | None = None
|
|
386
|
-
):
|
|
387
|
-
"""Initialize the string item operation var.
|
|
388
|
-
|
|
389
|
-
Args:
|
|
390
|
-
a: The string.
|
|
391
|
-
i: The index.
|
|
392
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
393
|
-
"""
|
|
394
|
-
super(StringItemOperation, self).__init__(
|
|
395
|
-
_var_name="",
|
|
396
|
-
_var_type=str,
|
|
397
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
398
|
-
)
|
|
399
|
-
object.__setattr__(
|
|
400
|
-
self, "a", a if isinstance(a, Var) else LiteralStringVar.create(a)
|
|
401
|
-
)
|
|
402
|
-
object.__setattr__(self, "i", i if isinstance(i, Var) else LiteralNumberVar(i))
|
|
403
|
-
object.__delattr__(self, "_var_name")
|
|
404
|
-
|
|
405
|
-
@cached_property
|
|
406
|
-
def _cached_var_name(self) -> str:
|
|
407
|
-
"""The name of the var.
|
|
408
|
-
|
|
409
|
-
Returns:
|
|
410
|
-
The name of the var.
|
|
411
|
-
"""
|
|
412
|
-
return f"{str(self.a)}.at({str(self.i)})"
|
|
413
|
-
|
|
414
|
-
def __getattr__(self, name: str) -> Any:
|
|
415
|
-
"""Get an attribute of the var.
|
|
416
|
-
|
|
417
|
-
Args:
|
|
418
|
-
name: The name of the attribute.
|
|
419
|
-
|
|
420
|
-
Returns:
|
|
421
|
-
The attribute value.
|
|
422
|
-
"""
|
|
423
|
-
if name == "_var_name":
|
|
424
|
-
return self._cached_var_name
|
|
425
|
-
getattr(super(StringItemOperation, self), name)
|
|
426
|
-
|
|
427
|
-
@cached_property
|
|
428
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
429
|
-
"""Get all VarData associated with the Var.
|
|
430
|
-
|
|
431
|
-
Returns:
|
|
432
|
-
The VarData of the components and all of its children.
|
|
433
|
-
"""
|
|
434
|
-
return ImmutableVarData.merge(
|
|
435
|
-
self.a._get_all_var_data(), self.i._get_all_var_data(), self._var_data
|
|
436
|
-
)
|
|
437
|
-
|
|
438
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
439
|
-
return self._cached_get_all_var_data
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
class ArrayJoinOperation(StringVar):
|
|
443
|
-
"""Base class for immutable string vars that are the result of an array join operation."""
|
|
444
|
-
|
|
445
|
-
a: ArrayVar = dataclasses.field(default_factory=lambda: LiteralArrayVar([]))
|
|
446
|
-
b: StringVar = dataclasses.field(
|
|
447
|
-
default_factory=lambda: LiteralStringVar.create("")
|
|
448
|
-
)
|
|
449
|
-
|
|
450
|
-
def __init__(
|
|
451
|
-
self, a: ArrayVar, b: StringVar | str, _var_data: VarData | None = None
|
|
452
|
-
):
|
|
453
|
-
"""Initialize the array join operation var.
|
|
454
|
-
|
|
455
|
-
Args:
|
|
456
|
-
a: The array.
|
|
457
|
-
b: The separator.
|
|
458
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
459
|
-
"""
|
|
460
|
-
super(ArrayJoinOperation, self).__init__(
|
|
461
|
-
_var_name="",
|
|
462
|
-
_var_type=str,
|
|
463
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
464
|
-
)
|
|
465
|
-
object.__setattr__(self, "a", a)
|
|
466
|
-
object.__setattr__(
|
|
467
|
-
self, "b", b if isinstance(b, Var) else LiteralStringVar.create(b)
|
|
468
|
-
)
|
|
469
|
-
object.__delattr__(self, "_var_name")
|
|
470
|
-
|
|
471
|
-
@cached_property
|
|
472
|
-
def _cached_var_name(self) -> str:
|
|
473
|
-
"""The name of the var.
|
|
474
|
-
|
|
475
|
-
Returns:
|
|
476
|
-
The name of the var.
|
|
477
|
-
"""
|
|
478
|
-
return f"{str(self.a)}.join({str(self.b)})"
|
|
479
|
-
|
|
480
|
-
def __getattr__(self, name: str) -> Any:
|
|
481
|
-
"""Get an attribute of the var.
|
|
482
|
-
|
|
483
|
-
Args:
|
|
484
|
-
name: The name of the attribute.
|
|
485
|
-
|
|
486
|
-
Returns:
|
|
487
|
-
The attribute value.
|
|
488
|
-
"""
|
|
489
|
-
if name == "_var_name":
|
|
490
|
-
return self._cached_var_name
|
|
491
|
-
getattr(super(ArrayJoinOperation, self), name)
|
|
492
|
-
|
|
493
|
-
@cached_property
|
|
494
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
495
|
-
"""Get all VarData associated with the Var.
|
|
496
|
-
|
|
497
|
-
Returns:
|
|
498
|
-
The VarData of the components and all of its children.
|
|
499
|
-
"""
|
|
500
|
-
return ImmutableVarData.merge(
|
|
501
|
-
self.a._get_all_var_data(), self.b._get_all_var_data(), self._var_data
|
|
502
|
-
)
|
|
503
|
-
|
|
504
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
505
|
-
return self._cached_get_all_var_data
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
# Compile regex for finding reflex var tags.
|
|
509
|
-
_decode_var_pattern_re = (
|
|
510
|
-
rf"{constants.REFLEX_VAR_OPENING_TAG}(.*?){constants.REFLEX_VAR_CLOSING_TAG}"
|
|
511
|
-
)
|
|
512
|
-
_decode_var_pattern = re.compile(_decode_var_pattern_re, flags=re.DOTALL)
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
@dataclasses.dataclass(
|
|
516
|
-
eq=False,
|
|
517
|
-
frozen=True,
|
|
518
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
519
|
-
)
|
|
520
|
-
class LiteralStringVar(LiteralVar, StringVar):
|
|
521
|
-
"""Base class for immutable literal string vars."""
|
|
522
|
-
|
|
523
|
-
_var_value: str = dataclasses.field(default="")
|
|
524
|
-
|
|
525
|
-
def __init__(
|
|
526
|
-
self,
|
|
527
|
-
_var_value: str,
|
|
528
|
-
_var_data: VarData | None = None,
|
|
529
|
-
):
|
|
530
|
-
"""Initialize the string var.
|
|
531
|
-
|
|
532
|
-
Args:
|
|
533
|
-
_var_value: The value of the var.
|
|
534
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
535
|
-
"""
|
|
536
|
-
super(LiteralStringVar, self).__init__(
|
|
537
|
-
_var_name=f'"{_var_value}"',
|
|
538
|
-
_var_type=str,
|
|
539
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
540
|
-
)
|
|
541
|
-
object.__setattr__(self, "_var_value", _var_value)
|
|
542
|
-
|
|
543
|
-
@classmethod
|
|
544
|
-
def create(
|
|
545
|
-
cls,
|
|
546
|
-
value: str,
|
|
547
|
-
_var_data: VarData | None = None,
|
|
548
|
-
) -> LiteralStringVar | ConcatVarOperation:
|
|
549
|
-
"""Create a var from a string value.
|
|
550
|
-
|
|
551
|
-
Args:
|
|
552
|
-
value: The value to create the var from.
|
|
553
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
554
|
-
|
|
555
|
-
Returns:
|
|
556
|
-
The var.
|
|
557
|
-
"""
|
|
558
|
-
if REFLEX_VAR_OPENING_TAG in value:
|
|
559
|
-
strings_and_vals: list[Var | str] = []
|
|
560
|
-
offset = 0
|
|
561
|
-
|
|
562
|
-
# Initialize some methods for reading json.
|
|
563
|
-
var_data_config = VarData().__config__
|
|
564
|
-
|
|
565
|
-
def json_loads(s):
|
|
566
|
-
try:
|
|
567
|
-
return var_data_config.json_loads(s)
|
|
568
|
-
except json.decoder.JSONDecodeError:
|
|
569
|
-
return var_data_config.json_loads(
|
|
570
|
-
var_data_config.json_loads(f'"{s}"')
|
|
571
|
-
)
|
|
572
|
-
|
|
573
|
-
# Find all tags
|
|
574
|
-
while m := _decode_var_pattern.search(value):
|
|
575
|
-
start, end = m.span()
|
|
576
|
-
if start > 0:
|
|
577
|
-
strings_and_vals.append(value[:start])
|
|
578
|
-
|
|
579
|
-
serialized_data = m.group(1)
|
|
580
|
-
|
|
581
|
-
if serialized_data.isnumeric() or (
|
|
582
|
-
serialized_data[0] == "-" and serialized_data[1:].isnumeric()
|
|
583
|
-
):
|
|
584
|
-
# This is a global immutable var.
|
|
585
|
-
var = _global_vars[int(serialized_data)]
|
|
586
|
-
strings_and_vals.append(var)
|
|
587
|
-
value = value[(end + len(var._var_name)) :]
|
|
588
|
-
else:
|
|
589
|
-
data = json_loads(serialized_data)
|
|
590
|
-
string_length = data.pop("string_length", None)
|
|
591
|
-
var_data = VarData.parse_obj(data)
|
|
592
|
-
|
|
593
|
-
# Use string length to compute positions of interpolations.
|
|
594
|
-
if string_length is not None:
|
|
595
|
-
realstart = start + offset
|
|
596
|
-
var_data.interpolations = [
|
|
597
|
-
(realstart, realstart + string_length)
|
|
598
|
-
]
|
|
599
|
-
strings_and_vals.append(
|
|
600
|
-
ImmutableVar.create_safe(
|
|
601
|
-
value[end : (end + string_length)], _var_data=var_data
|
|
602
|
-
)
|
|
603
|
-
)
|
|
604
|
-
value = value[(end + string_length) :]
|
|
605
|
-
|
|
606
|
-
offset += end - start
|
|
607
|
-
|
|
608
|
-
if value:
|
|
609
|
-
strings_and_vals.append(value)
|
|
610
|
-
|
|
611
|
-
return ConcatVarOperation(*strings_and_vals, _var_data=_var_data)
|
|
612
|
-
|
|
613
|
-
return LiteralStringVar(
|
|
614
|
-
value,
|
|
615
|
-
_var_data=_var_data,
|
|
616
|
-
)
|
|
617
|
-
|
|
618
|
-
def __hash__(self) -> int:
|
|
619
|
-
"""Get the hash of the var.
|
|
620
|
-
|
|
621
|
-
Returns:
|
|
622
|
-
The hash of the var.
|
|
623
|
-
"""
|
|
624
|
-
return hash((self.__class__.__name__, self._var_value))
|
|
625
|
-
|
|
626
|
-
def json(self) -> str:
|
|
627
|
-
"""Get the JSON representation of the var.
|
|
628
|
-
|
|
629
|
-
Returns:
|
|
630
|
-
The JSON representation of the var.
|
|
631
|
-
"""
|
|
632
|
-
return json.dumps(self._var_value)
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
@dataclasses.dataclass(
|
|
636
|
-
eq=False,
|
|
637
|
-
frozen=True,
|
|
638
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
639
|
-
)
|
|
640
|
-
class ConcatVarOperation(StringVar):
|
|
641
|
-
"""Representing a concatenation of literal string vars."""
|
|
642
|
-
|
|
643
|
-
_var_value: Tuple[Union[Var, str], ...] = dataclasses.field(default_factory=tuple)
|
|
644
|
-
|
|
645
|
-
def __init__(self, *value: Var | str, _var_data: VarData | None = None):
|
|
646
|
-
"""Initialize the operation of concatenating literal string vars.
|
|
647
|
-
|
|
648
|
-
Args:
|
|
649
|
-
value: The values to concatenate.
|
|
650
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
651
|
-
"""
|
|
652
|
-
super(ConcatVarOperation, self).__init__(
|
|
653
|
-
_var_name="", _var_data=ImmutableVarData.merge(_var_data), _var_type=str
|
|
654
|
-
)
|
|
655
|
-
object.__setattr__(self, "_var_value", value)
|
|
656
|
-
object.__delattr__(self, "_var_name")
|
|
657
|
-
|
|
658
|
-
def __getattr__(self, name):
|
|
659
|
-
"""Get an attribute of the var.
|
|
660
|
-
|
|
661
|
-
Args:
|
|
662
|
-
name: The name of the attribute.
|
|
663
|
-
|
|
664
|
-
Returns:
|
|
665
|
-
The attribute of the var.
|
|
666
|
-
"""
|
|
667
|
-
if name == "_var_name":
|
|
668
|
-
return self._cached_var_name
|
|
669
|
-
return super(type(self), self).__getattr__(name)
|
|
670
|
-
|
|
671
|
-
@cached_property
|
|
672
|
-
def _cached_var_name(self) -> str:
|
|
673
|
-
"""The name of the var.
|
|
674
|
-
|
|
675
|
-
Returns:
|
|
676
|
-
The name of the var.
|
|
677
|
-
"""
|
|
678
|
-
return (
|
|
679
|
-
"("
|
|
680
|
-
+ "+".join(
|
|
681
|
-
[
|
|
682
|
-
str(element) if isinstance(element, Var) else f'"{element}"'
|
|
683
|
-
for element in self._var_value
|
|
684
|
-
]
|
|
685
|
-
)
|
|
686
|
-
+ ")"
|
|
687
|
-
)
|
|
688
|
-
|
|
689
|
-
@cached_property
|
|
690
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
691
|
-
"""Get all VarData associated with the Var.
|
|
692
|
-
|
|
693
|
-
Returns:
|
|
694
|
-
The VarData of the components and all of its children.
|
|
695
|
-
"""
|
|
696
|
-
return ImmutableVarData.merge(
|
|
697
|
-
*[
|
|
698
|
-
var._get_all_var_data()
|
|
699
|
-
for var in self._var_value
|
|
700
|
-
if isinstance(var, Var)
|
|
701
|
-
],
|
|
702
|
-
self._var_data,
|
|
703
|
-
)
|
|
704
|
-
|
|
705
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
706
|
-
"""Wrapper method for cached property.
|
|
707
|
-
|
|
708
|
-
Returns:
|
|
709
|
-
The VarData of the components and all of its children.
|
|
710
|
-
"""
|
|
711
|
-
return self._cached_get_all_var_data
|
|
712
|
-
|
|
713
|
-
def __post_init__(self):
|
|
714
|
-
"""Post-initialize the var."""
|
|
715
|
-
pass
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
ARRAY_VAR_TYPE = TypeVar("ARRAY_VAR_TYPE", bound=Union[List, Tuple, Set])
|
|
719
|
-
|
|
720
|
-
OTHER_TUPLE = TypeVar("OTHER_TUPLE")
|
|
721
|
-
|
|
722
|
-
INNER_ARRAY_VAR = TypeVar("INNER_ARRAY_VAR")
|
|
723
|
-
|
|
724
|
-
KEY_TYPE = TypeVar("KEY_TYPE")
|
|
725
|
-
VALUE_TYPE = TypeVar("VALUE_TYPE")
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
class ArrayVar(ImmutableVar[ARRAY_VAR_TYPE]):
|
|
729
|
-
"""Base class for immutable array vars."""
|
|
730
|
-
|
|
731
|
-
from reflex.experimental.vars.sequence import StringVar
|
|
732
|
-
|
|
733
|
-
def join(self, sep: StringVar | str = "") -> ArrayJoinOperation:
|
|
734
|
-
"""Join the elements of the array.
|
|
735
|
-
|
|
736
|
-
Args:
|
|
737
|
-
sep: The separator between elements.
|
|
738
|
-
|
|
739
|
-
Returns:
|
|
740
|
-
The joined elements.
|
|
741
|
-
"""
|
|
742
|
-
from reflex.experimental.vars.sequence import ArrayJoinOperation
|
|
743
|
-
|
|
744
|
-
return ArrayJoinOperation(self, sep)
|
|
745
|
-
|
|
746
|
-
def reverse(self) -> ArrayVar[ARRAY_VAR_TYPE]:
|
|
747
|
-
"""Reverse the array.
|
|
748
|
-
|
|
749
|
-
Returns:
|
|
750
|
-
The reversed array.
|
|
751
|
-
"""
|
|
752
|
-
return ArrayReverseOperation(self)
|
|
753
|
-
|
|
754
|
-
@overload
|
|
755
|
-
def __getitem__(self, i: slice) -> ArrayVar[ARRAY_VAR_TYPE]: ...
|
|
756
|
-
|
|
757
|
-
@overload
|
|
758
|
-
def __getitem__(
|
|
759
|
-
self: (
|
|
760
|
-
ArrayVar[Tuple[int, OTHER_TUPLE]]
|
|
761
|
-
| ArrayVar[Tuple[float, OTHER_TUPLE]]
|
|
762
|
-
| ArrayVar[Tuple[int | float, OTHER_TUPLE]]
|
|
763
|
-
),
|
|
764
|
-
i: Literal[0, -2],
|
|
765
|
-
) -> NumberVar: ...
|
|
766
|
-
|
|
767
|
-
@overload
|
|
768
|
-
def __getitem__(
|
|
769
|
-
self: (
|
|
770
|
-
ArrayVar[Tuple[OTHER_TUPLE, int]]
|
|
771
|
-
| ArrayVar[Tuple[OTHER_TUPLE, float]]
|
|
772
|
-
| ArrayVar[Tuple[OTHER_TUPLE, int | float]]
|
|
773
|
-
),
|
|
774
|
-
i: Literal[1, -1],
|
|
775
|
-
) -> NumberVar: ...
|
|
776
|
-
|
|
777
|
-
@overload
|
|
778
|
-
def __getitem__(
|
|
779
|
-
self: ArrayVar[Tuple[str, OTHER_TUPLE]], i: Literal[0, -2]
|
|
780
|
-
) -> StringVar: ...
|
|
781
|
-
|
|
782
|
-
@overload
|
|
783
|
-
def __getitem__(
|
|
784
|
-
self: ArrayVar[Tuple[OTHER_TUPLE, str]], i: Literal[1, -1]
|
|
785
|
-
) -> StringVar: ...
|
|
786
|
-
|
|
787
|
-
@overload
|
|
788
|
-
def __getitem__(
|
|
789
|
-
self: ArrayVar[Tuple[bool, OTHER_TUPLE]], i: Literal[0, -2]
|
|
790
|
-
) -> BooleanVar: ...
|
|
791
|
-
|
|
792
|
-
@overload
|
|
793
|
-
def __getitem__(
|
|
794
|
-
self: ArrayVar[Tuple[OTHER_TUPLE, bool]], i: Literal[1, -1]
|
|
795
|
-
) -> BooleanVar: ...
|
|
796
|
-
|
|
797
|
-
@overload
|
|
798
|
-
def __getitem__(
|
|
799
|
-
self: (
|
|
800
|
-
ARRAY_VAR_OF_LIST_ELEMENT[int]
|
|
801
|
-
| ARRAY_VAR_OF_LIST_ELEMENT[float]
|
|
802
|
-
| ARRAY_VAR_OF_LIST_ELEMENT[int | float]
|
|
803
|
-
),
|
|
804
|
-
i: int | NumberVar,
|
|
805
|
-
) -> NumberVar: ...
|
|
806
|
-
|
|
807
|
-
@overload
|
|
808
|
-
def __getitem__(
|
|
809
|
-
self: ARRAY_VAR_OF_LIST_ELEMENT[str], i: int | NumberVar
|
|
810
|
-
) -> StringVar: ...
|
|
811
|
-
|
|
812
|
-
@overload
|
|
813
|
-
def __getitem__(
|
|
814
|
-
self: ARRAY_VAR_OF_LIST_ELEMENT[bool], i: int | NumberVar
|
|
815
|
-
) -> BooleanVar: ...
|
|
816
|
-
|
|
817
|
-
@overload
|
|
818
|
-
def __getitem__(
|
|
819
|
-
self: ARRAY_VAR_OF_LIST_ELEMENT[List[INNER_ARRAY_VAR]],
|
|
820
|
-
i: int | NumberVar,
|
|
821
|
-
) -> ArrayVar[List[INNER_ARRAY_VAR]]: ...
|
|
822
|
-
|
|
823
|
-
@overload
|
|
824
|
-
def __getitem__(
|
|
825
|
-
self: ARRAY_VAR_OF_LIST_ELEMENT[Set[INNER_ARRAY_VAR]],
|
|
826
|
-
i: int | NumberVar,
|
|
827
|
-
) -> ArrayVar[Set[INNER_ARRAY_VAR]]: ...
|
|
828
|
-
|
|
829
|
-
@overload
|
|
830
|
-
def __getitem__(
|
|
831
|
-
self: ARRAY_VAR_OF_LIST_ELEMENT[Tuple[INNER_ARRAY_VAR, ...]],
|
|
832
|
-
i: int | NumberVar,
|
|
833
|
-
) -> ArrayVar[Tuple[INNER_ARRAY_VAR, ...]]: ...
|
|
834
|
-
|
|
835
|
-
@overload
|
|
836
|
-
def __getitem__(
|
|
837
|
-
self: ARRAY_VAR_OF_LIST_ELEMENT[Dict[KEY_TYPE, VALUE_TYPE]],
|
|
838
|
-
i: int | NumberVar,
|
|
839
|
-
) -> ObjectVar[Dict[KEY_TYPE, VALUE_TYPE]]: ...
|
|
840
|
-
|
|
841
|
-
@overload
|
|
842
|
-
def __getitem__(self, i: int | NumberVar) -> ImmutableVar: ...
|
|
843
|
-
|
|
844
|
-
def __getitem__(
|
|
845
|
-
self, i: slice | int | NumberVar
|
|
846
|
-
) -> ArrayVar[ARRAY_VAR_TYPE] | ImmutableVar:
|
|
847
|
-
"""Get a slice of the array.
|
|
848
|
-
|
|
849
|
-
Args:
|
|
850
|
-
i: The slice.
|
|
851
|
-
|
|
852
|
-
Returns:
|
|
853
|
-
The array slice operation.
|
|
854
|
-
"""
|
|
855
|
-
if isinstance(i, slice):
|
|
856
|
-
return ArraySliceOperation(self, i)
|
|
857
|
-
return ArrayItemOperation(self, i).guess_type()
|
|
858
|
-
|
|
859
|
-
def length(self) -> NumberVar:
|
|
860
|
-
"""Get the length of the array.
|
|
861
|
-
|
|
862
|
-
Returns:
|
|
863
|
-
The length of the array.
|
|
864
|
-
"""
|
|
865
|
-
return ArrayLengthOperation(self)
|
|
866
|
-
|
|
867
|
-
@overload
|
|
868
|
-
@classmethod
|
|
869
|
-
def range(cls, stop: int | NumberVar, /) -> ArrayVar[List[int]]: ...
|
|
870
|
-
|
|
871
|
-
@overload
|
|
872
|
-
@classmethod
|
|
873
|
-
def range(
|
|
874
|
-
cls,
|
|
875
|
-
start: int | NumberVar,
|
|
876
|
-
end: int | NumberVar,
|
|
877
|
-
step: int | NumberVar = 1,
|
|
878
|
-
/,
|
|
879
|
-
) -> ArrayVar[List[int]]: ...
|
|
880
|
-
|
|
881
|
-
@classmethod
|
|
882
|
-
def range(
|
|
883
|
-
cls,
|
|
884
|
-
first_endpoint: int | NumberVar,
|
|
885
|
-
second_endpoint: int | NumberVar | None = None,
|
|
886
|
-
step: int | NumberVar | None = None,
|
|
887
|
-
) -> ArrayVar[List[int]]:
|
|
888
|
-
"""Create a range of numbers.
|
|
889
|
-
|
|
890
|
-
Args:
|
|
891
|
-
first_endpoint: The end of the range if second_endpoint is not provided, otherwise the start of the range.
|
|
892
|
-
second_endpoint: The end of the range.
|
|
893
|
-
step: The step of the range.
|
|
894
|
-
|
|
895
|
-
Returns:
|
|
896
|
-
The range of numbers.
|
|
897
|
-
"""
|
|
898
|
-
if second_endpoint is None:
|
|
899
|
-
start = 0
|
|
900
|
-
end = first_endpoint
|
|
901
|
-
else:
|
|
902
|
-
start = first_endpoint
|
|
903
|
-
end = second_endpoint
|
|
904
|
-
|
|
905
|
-
return RangeOperation(start, end, step or 1)
|
|
906
|
-
|
|
907
|
-
def contains(self, other: Any) -> BooleanVar:
|
|
908
|
-
"""Check if the array contains an element.
|
|
909
|
-
|
|
910
|
-
Args:
|
|
911
|
-
other: The element to check for.
|
|
912
|
-
|
|
913
|
-
Returns:
|
|
914
|
-
The array contains operation.
|
|
915
|
-
"""
|
|
916
|
-
return ArrayContainsOperation(self, other)
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
LIST_ELEMENT = TypeVar("LIST_ELEMENT")
|
|
920
|
-
|
|
921
|
-
ARRAY_VAR_OF_LIST_ELEMENT = Union[
|
|
922
|
-
ArrayVar[List[LIST_ELEMENT]],
|
|
923
|
-
ArrayVar[Set[LIST_ELEMENT]],
|
|
924
|
-
ArrayVar[Tuple[LIST_ELEMENT, ...]],
|
|
925
|
-
]
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
@dataclasses.dataclass(
|
|
929
|
-
eq=False,
|
|
930
|
-
frozen=True,
|
|
931
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
932
|
-
)
|
|
933
|
-
class LiteralArrayVar(LiteralVar, ArrayVar[ARRAY_VAR_TYPE]):
|
|
934
|
-
"""Base class for immutable literal array vars."""
|
|
935
|
-
|
|
936
|
-
_var_value: Union[
|
|
937
|
-
List[Union[Var, Any]], Set[Union[Var, Any]], Tuple[Union[Var, Any], ...]
|
|
938
|
-
] = dataclasses.field(default_factory=list)
|
|
939
|
-
|
|
940
|
-
def __init__(
|
|
941
|
-
self: LiteralArrayVar[ARRAY_VAR_TYPE],
|
|
942
|
-
_var_value: ARRAY_VAR_TYPE,
|
|
943
|
-
_var_type: type[ARRAY_VAR_TYPE] | None = None,
|
|
944
|
-
_var_data: VarData | None = None,
|
|
945
|
-
):
|
|
946
|
-
"""Initialize the array var.
|
|
947
|
-
|
|
948
|
-
Args:
|
|
949
|
-
_var_value: The value of the var.
|
|
950
|
-
_var_type: The type of the var.
|
|
951
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
952
|
-
"""
|
|
953
|
-
super(LiteralArrayVar, self).__init__(
|
|
954
|
-
_var_name="",
|
|
955
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
956
|
-
_var_type=(figure_out_type(_var_value) if _var_type is None else _var_type),
|
|
957
|
-
)
|
|
958
|
-
object.__setattr__(self, "_var_value", _var_value)
|
|
959
|
-
object.__delattr__(self, "_var_name")
|
|
960
|
-
|
|
961
|
-
def __getattr__(self, name):
|
|
962
|
-
"""Get an attribute of the var.
|
|
963
|
-
|
|
964
|
-
Args:
|
|
965
|
-
name: The name of the attribute.
|
|
966
|
-
|
|
967
|
-
Returns:
|
|
968
|
-
The attribute of the var.
|
|
969
|
-
"""
|
|
970
|
-
if name == "_var_name":
|
|
971
|
-
return self._cached_var_name
|
|
972
|
-
return super(type(self), self).__getattr__(name)
|
|
973
|
-
|
|
974
|
-
@functools.cached_property
|
|
975
|
-
def _cached_var_name(self) -> str:
|
|
976
|
-
"""The name of the var.
|
|
977
|
-
|
|
978
|
-
Returns:
|
|
979
|
-
The name of the var.
|
|
980
|
-
"""
|
|
981
|
-
return (
|
|
982
|
-
"["
|
|
983
|
-
+ ", ".join(
|
|
984
|
-
[str(LiteralVar.create(element)) for element in self._var_value]
|
|
985
|
-
)
|
|
986
|
-
+ "]"
|
|
987
|
-
)
|
|
988
|
-
|
|
989
|
-
@functools.cached_property
|
|
990
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
991
|
-
"""Get all VarData associated with the Var.
|
|
992
|
-
|
|
993
|
-
Returns:
|
|
994
|
-
The VarData of the components and all of its children.
|
|
995
|
-
"""
|
|
996
|
-
return ImmutableVarData.merge(
|
|
997
|
-
*[
|
|
998
|
-
var._get_all_var_data()
|
|
999
|
-
for var in self._var_value
|
|
1000
|
-
if isinstance(var, Var)
|
|
1001
|
-
],
|
|
1002
|
-
self._var_data,
|
|
1003
|
-
)
|
|
1004
|
-
|
|
1005
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
1006
|
-
"""Wrapper method for cached property.
|
|
1007
|
-
|
|
1008
|
-
Returns:
|
|
1009
|
-
The VarData of the components and all of its children.
|
|
1010
|
-
"""
|
|
1011
|
-
return self._cached_get_all_var_data
|
|
1012
|
-
|
|
1013
|
-
def __hash__(self) -> int:
|
|
1014
|
-
"""Get the hash of the var.
|
|
1015
|
-
|
|
1016
|
-
Returns:
|
|
1017
|
-
The hash of the var.
|
|
1018
|
-
"""
|
|
1019
|
-
return hash((self.__class__.__name__, self._var_name))
|
|
1020
|
-
|
|
1021
|
-
def json(self) -> str:
|
|
1022
|
-
"""Get the JSON representation of the var.
|
|
1023
|
-
|
|
1024
|
-
Returns:
|
|
1025
|
-
The JSON representation of the var.
|
|
1026
|
-
"""
|
|
1027
|
-
return (
|
|
1028
|
-
"["
|
|
1029
|
-
+ ", ".join(
|
|
1030
|
-
[LiteralVar.create(element).json() for element in self._var_value]
|
|
1031
|
-
)
|
|
1032
|
-
+ "]"
|
|
1033
|
-
)
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
@dataclasses.dataclass(
|
|
1037
|
-
eq=False,
|
|
1038
|
-
frozen=True,
|
|
1039
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
1040
|
-
)
|
|
1041
|
-
class StringSplitOperation(ArrayVar):
|
|
1042
|
-
"""Base class for immutable array vars that are the result of a string split operation."""
|
|
1043
|
-
|
|
1044
|
-
a: StringVar = dataclasses.field(
|
|
1045
|
-
default_factory=lambda: LiteralStringVar.create("")
|
|
1046
|
-
)
|
|
1047
|
-
b: StringVar = dataclasses.field(
|
|
1048
|
-
default_factory=lambda: LiteralStringVar.create("")
|
|
1049
|
-
)
|
|
1050
|
-
|
|
1051
|
-
def __init__(
|
|
1052
|
-
self, a: StringVar | str, b: StringVar | str, _var_data: VarData | None = None
|
|
1053
|
-
):
|
|
1054
|
-
"""Initialize the string split operation var.
|
|
1055
|
-
|
|
1056
|
-
Args:
|
|
1057
|
-
a: The string.
|
|
1058
|
-
b: The separator.
|
|
1059
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
1060
|
-
"""
|
|
1061
|
-
super(StringSplitOperation, self).__init__(
|
|
1062
|
-
_var_name="",
|
|
1063
|
-
_var_type=List[str],
|
|
1064
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
1065
|
-
)
|
|
1066
|
-
object.__setattr__(
|
|
1067
|
-
self, "a", a if isinstance(a, Var) else LiteralStringVar.create(a)
|
|
1068
|
-
)
|
|
1069
|
-
object.__setattr__(
|
|
1070
|
-
self, "b", b if isinstance(b, Var) else LiteralStringVar.create(b)
|
|
1071
|
-
)
|
|
1072
|
-
object.__delattr__(self, "_var_name")
|
|
1073
|
-
|
|
1074
|
-
@cached_property
|
|
1075
|
-
def _cached_var_name(self) -> str:
|
|
1076
|
-
"""The name of the var.
|
|
1077
|
-
|
|
1078
|
-
Returns:
|
|
1079
|
-
The name of the var.
|
|
1080
|
-
"""
|
|
1081
|
-
return f"{str(self.a)}.split({str(self.b)})"
|
|
1082
|
-
|
|
1083
|
-
def __getattr__(self, name: str) -> Any:
|
|
1084
|
-
"""Get an attribute of the var.
|
|
1085
|
-
|
|
1086
|
-
Args:
|
|
1087
|
-
name: The name of the attribute.
|
|
1088
|
-
|
|
1089
|
-
Returns:
|
|
1090
|
-
The attribute value.
|
|
1091
|
-
"""
|
|
1092
|
-
if name == "_var_name":
|
|
1093
|
-
return self._cached_var_name
|
|
1094
|
-
getattr(super(StringSplitOperation, self), name)
|
|
1095
|
-
|
|
1096
|
-
@cached_property
|
|
1097
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
1098
|
-
"""Get all VarData associated with the Var.
|
|
1099
|
-
|
|
1100
|
-
Returns:
|
|
1101
|
-
The VarData of the components and all of its children.
|
|
1102
|
-
"""
|
|
1103
|
-
return ImmutableVarData.merge(
|
|
1104
|
-
self.a._get_all_var_data(), self.b._get_all_var_data(), self._var_data
|
|
1105
|
-
)
|
|
1106
|
-
|
|
1107
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
1108
|
-
return self._cached_get_all_var_data
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
@dataclasses.dataclass(
|
|
1112
|
-
eq=False,
|
|
1113
|
-
frozen=True,
|
|
1114
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
1115
|
-
)
|
|
1116
|
-
class ArrayToArrayOperation(ArrayVar):
|
|
1117
|
-
"""Base class for immutable array vars that are the result of an array to array operation."""
|
|
1118
|
-
|
|
1119
|
-
a: ArrayVar = dataclasses.field(default_factory=lambda: LiteralArrayVar([]))
|
|
1120
|
-
|
|
1121
|
-
def __init__(self, a: ArrayVar, _var_data: VarData | None = None):
|
|
1122
|
-
"""Initialize the array to array operation var.
|
|
1123
|
-
|
|
1124
|
-
Args:
|
|
1125
|
-
a: The string.
|
|
1126
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
1127
|
-
"""
|
|
1128
|
-
super(ArrayToArrayOperation, self).__init__(
|
|
1129
|
-
_var_name="",
|
|
1130
|
-
_var_type=a._var_type,
|
|
1131
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
1132
|
-
)
|
|
1133
|
-
object.__setattr__(self, "a", a)
|
|
1134
|
-
object.__delattr__(self, "_var_name")
|
|
1135
|
-
|
|
1136
|
-
@cached_property
|
|
1137
|
-
def _cached_var_name(self) -> str:
|
|
1138
|
-
"""The name of the var.
|
|
1139
|
-
|
|
1140
|
-
Raises:
|
|
1141
|
-
NotImplementedError: Must be implemented by subclasses.
|
|
1142
|
-
"""
|
|
1143
|
-
raise NotImplementedError(
|
|
1144
|
-
"ArrayToArrayOperation must implement _cached_var_name"
|
|
1145
|
-
)
|
|
1146
|
-
|
|
1147
|
-
def __getattr__(self, name: str) -> Any:
|
|
1148
|
-
"""Get an attribute of the var.
|
|
1149
|
-
|
|
1150
|
-
Args:
|
|
1151
|
-
name: The name of the attribute.
|
|
1152
|
-
|
|
1153
|
-
Returns:
|
|
1154
|
-
The attribute value.
|
|
1155
|
-
"""
|
|
1156
|
-
if name == "_var_name":
|
|
1157
|
-
return self._cached_var_name
|
|
1158
|
-
getattr(super(ArrayToArrayOperation, self), name)
|
|
1159
|
-
|
|
1160
|
-
@cached_property
|
|
1161
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
1162
|
-
"""Get all VarData associated with the Var.
|
|
1163
|
-
|
|
1164
|
-
Returns:
|
|
1165
|
-
The VarData of the components and all of its children.
|
|
1166
|
-
"""
|
|
1167
|
-
return ImmutableVarData.merge(
|
|
1168
|
-
self.a._get_all_var_data() if isinstance(self.a, Var) else None,
|
|
1169
|
-
self._var_data,
|
|
1170
|
-
)
|
|
1171
|
-
|
|
1172
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
1173
|
-
return self._cached_get_all_var_data
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
@dataclasses.dataclass(
|
|
1177
|
-
eq=False,
|
|
1178
|
-
frozen=True,
|
|
1179
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
1180
|
-
)
|
|
1181
|
-
class ArraySliceOperation(ArrayVar):
|
|
1182
|
-
"""Base class for immutable string vars that are the result of a string slice operation."""
|
|
1183
|
-
|
|
1184
|
-
a: ArrayVar = dataclasses.field(default_factory=lambda: LiteralArrayVar([]))
|
|
1185
|
-
_slice: slice = dataclasses.field(default_factory=lambda: slice(None, None, None))
|
|
1186
|
-
|
|
1187
|
-
def __init__(self, a: ArrayVar, _slice: slice, _var_data: VarData | None = None):
|
|
1188
|
-
"""Initialize the string slice operation var.
|
|
1189
|
-
|
|
1190
|
-
Args:
|
|
1191
|
-
a: The string.
|
|
1192
|
-
_slice: The slice.
|
|
1193
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
1194
|
-
"""
|
|
1195
|
-
super(ArraySliceOperation, self).__init__(
|
|
1196
|
-
_var_name="",
|
|
1197
|
-
_var_type=a._var_type,
|
|
1198
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
1199
|
-
)
|
|
1200
|
-
object.__setattr__(self, "a", a)
|
|
1201
|
-
object.__setattr__(self, "_slice", _slice)
|
|
1202
|
-
object.__delattr__(self, "_var_name")
|
|
1203
|
-
|
|
1204
|
-
@cached_property
|
|
1205
|
-
def _cached_var_name(self) -> str:
|
|
1206
|
-
"""The name of the var.
|
|
1207
|
-
|
|
1208
|
-
Returns:
|
|
1209
|
-
The name of the var.
|
|
1210
|
-
|
|
1211
|
-
Raises:
|
|
1212
|
-
ValueError: If the slice step is zero.
|
|
1213
|
-
"""
|
|
1214
|
-
start, end, step = self._slice.start, self._slice.stop, self._slice.step
|
|
1215
|
-
|
|
1216
|
-
normalized_start = (
|
|
1217
|
-
LiteralVar.create(start)
|
|
1218
|
-
if start is not None
|
|
1219
|
-
else ImmutableVar.create_safe("undefined")
|
|
1220
|
-
)
|
|
1221
|
-
normalized_end = (
|
|
1222
|
-
LiteralVar.create(end)
|
|
1223
|
-
if end is not None
|
|
1224
|
-
else ImmutableVar.create_safe("undefined")
|
|
1225
|
-
)
|
|
1226
|
-
if step is None:
|
|
1227
|
-
return (
|
|
1228
|
-
f"{str(self.a)}.slice({str(normalized_start)}, {str(normalized_end)})"
|
|
1229
|
-
)
|
|
1230
|
-
if not isinstance(step, Var):
|
|
1231
|
-
if step < 0:
|
|
1232
|
-
actual_start = end + 1 if end is not None else 0
|
|
1233
|
-
actual_end = start + 1 if start is not None else self.a.length()
|
|
1234
|
-
return str(
|
|
1235
|
-
ArraySliceOperation(
|
|
1236
|
-
ArrayReverseOperation(
|
|
1237
|
-
ArraySliceOperation(self.a, slice(actual_start, actual_end))
|
|
1238
|
-
),
|
|
1239
|
-
slice(None, None, -step),
|
|
1240
|
-
)
|
|
1241
|
-
)
|
|
1242
|
-
if step == 0:
|
|
1243
|
-
raise ValueError("slice step cannot be zero")
|
|
1244
|
-
return f"{str(self.a)}.slice({str(normalized_start)}, {str(normalized_end)}).filter((_, i) => i % {str(step)} === 0)"
|
|
1245
|
-
|
|
1246
|
-
actual_start_reverse = end + 1 if end is not None else 0
|
|
1247
|
-
actual_end_reverse = start + 1 if start is not None else self.a.length()
|
|
1248
|
-
|
|
1249
|
-
return f"{str(self.step)} > 0 ? {str(self.a)}.slice({str(normalized_start)}, {str(normalized_end)}).filter((_, i) => i % {str(step)} === 0) : {str(self.a)}.slice({str(actual_start_reverse)}, {str(actual_end_reverse)}).reverse().filter((_, i) => i % {str(-step)} === 0)"
|
|
1250
|
-
|
|
1251
|
-
def __getattr__(self, name: str) -> Any:
|
|
1252
|
-
"""Get an attribute of the var.
|
|
1253
|
-
|
|
1254
|
-
Args:
|
|
1255
|
-
name: The name of the attribute.
|
|
1256
|
-
|
|
1257
|
-
Returns:
|
|
1258
|
-
The attribute value.
|
|
1259
|
-
"""
|
|
1260
|
-
if name == "_var_name":
|
|
1261
|
-
return self._cached_var_name
|
|
1262
|
-
getattr(super(ArraySliceOperation, self), name)
|
|
1263
|
-
|
|
1264
|
-
@cached_property
|
|
1265
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
1266
|
-
"""Get all VarData associated with the Var.
|
|
1267
|
-
|
|
1268
|
-
Returns:
|
|
1269
|
-
The VarData of the components and all of its children.
|
|
1270
|
-
"""
|
|
1271
|
-
return ImmutableVarData.merge(
|
|
1272
|
-
self.a._get_all_var_data(),
|
|
1273
|
-
*[
|
|
1274
|
-
slice_value._get_all_var_data()
|
|
1275
|
-
for slice_value in (
|
|
1276
|
-
self._slice.start,
|
|
1277
|
-
self._slice.stop,
|
|
1278
|
-
self._slice.step,
|
|
1279
|
-
)
|
|
1280
|
-
if slice_value is not None and isinstance(slice_value, Var)
|
|
1281
|
-
],
|
|
1282
|
-
self._var_data,
|
|
1283
|
-
)
|
|
1284
|
-
|
|
1285
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
1286
|
-
return self._cached_get_all_var_data
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
class ArrayReverseOperation(ArrayToArrayOperation):
|
|
1290
|
-
"""Base class for immutable string vars that are the result of a string reverse operation."""
|
|
1291
|
-
|
|
1292
|
-
@cached_property
|
|
1293
|
-
def _cached_var_name(self) -> str:
|
|
1294
|
-
"""The name of the var.
|
|
1295
|
-
|
|
1296
|
-
Returns:
|
|
1297
|
-
The name of the var.
|
|
1298
|
-
"""
|
|
1299
|
-
return f"{str(self.a)}.reverse()"
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
@dataclasses.dataclass(
|
|
1303
|
-
eq=False,
|
|
1304
|
-
frozen=True,
|
|
1305
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
1306
|
-
)
|
|
1307
|
-
class ArrayToNumberOperation(NumberVar):
|
|
1308
|
-
"""Base class for immutable number vars that are the result of an array to number operation."""
|
|
1309
|
-
|
|
1310
|
-
a: ArrayVar = dataclasses.field(
|
|
1311
|
-
default_factory=lambda: LiteralArrayVar([]),
|
|
1312
|
-
)
|
|
1313
|
-
|
|
1314
|
-
def __init__(self, a: ArrayVar, _var_data: VarData | None = None):
|
|
1315
|
-
"""Initialize the string to number operation var.
|
|
1316
|
-
|
|
1317
|
-
Args:
|
|
1318
|
-
a: The array.
|
|
1319
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
1320
|
-
"""
|
|
1321
|
-
super(ArrayToNumberOperation, self).__init__(
|
|
1322
|
-
_var_name="",
|
|
1323
|
-
_var_type=int,
|
|
1324
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
1325
|
-
)
|
|
1326
|
-
object.__setattr__(self, "a", a if isinstance(a, Var) else LiteralArrayVar(a))
|
|
1327
|
-
object.__delattr__(self, "_var_name")
|
|
1328
|
-
|
|
1329
|
-
@cached_property
|
|
1330
|
-
def _cached_var_name(self) -> str:
|
|
1331
|
-
"""The name of the var.
|
|
1332
|
-
|
|
1333
|
-
Raises:
|
|
1334
|
-
NotImplementedError: Must be implemented by subclasses.
|
|
1335
|
-
"""
|
|
1336
|
-
raise NotImplementedError(
|
|
1337
|
-
"StringToNumberOperation must implement _cached_var_name"
|
|
1338
|
-
)
|
|
1339
|
-
|
|
1340
|
-
def __getattr__(self, name: str) -> Any:
|
|
1341
|
-
"""Get an attribute of the var.
|
|
1342
|
-
|
|
1343
|
-
Args:
|
|
1344
|
-
name: The name of the attribute.
|
|
1345
|
-
|
|
1346
|
-
Returns:
|
|
1347
|
-
The attribute value.
|
|
1348
|
-
"""
|
|
1349
|
-
if name == "_var_name":
|
|
1350
|
-
return self._cached_var_name
|
|
1351
|
-
getattr(super(ArrayToNumberOperation, self), name)
|
|
1352
|
-
|
|
1353
|
-
@cached_property
|
|
1354
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
1355
|
-
"""Get all VarData associated with the Var.
|
|
1356
|
-
|
|
1357
|
-
Returns:
|
|
1358
|
-
The VarData of the components and all of its children.
|
|
1359
|
-
"""
|
|
1360
|
-
return ImmutableVarData.merge(self.a._get_all_var_data(), self._var_data)
|
|
1361
|
-
|
|
1362
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
1363
|
-
return self._cached_get_all_var_data
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
class ArrayLengthOperation(ArrayToNumberOperation):
|
|
1367
|
-
"""Base class for immutable number vars that are the result of an array length operation."""
|
|
1368
|
-
|
|
1369
|
-
@cached_property
|
|
1370
|
-
def _cached_var_name(self) -> str:
|
|
1371
|
-
"""The name of the var.
|
|
1372
|
-
|
|
1373
|
-
Returns:
|
|
1374
|
-
The name of the var.
|
|
1375
|
-
"""
|
|
1376
|
-
return f"{str(self.a)}.length"
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
def is_tuple_type(t: GenericType) -> bool:
|
|
1380
|
-
"""Check if a type is a tuple type.
|
|
1381
|
-
|
|
1382
|
-
Args:
|
|
1383
|
-
t: The type to check.
|
|
1384
|
-
|
|
1385
|
-
Returns:
|
|
1386
|
-
Whether the type is a tuple type.
|
|
1387
|
-
"""
|
|
1388
|
-
if inspect.isclass(t):
|
|
1389
|
-
return issubclass(t, tuple)
|
|
1390
|
-
return get_origin(t) is tuple
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
@dataclasses.dataclass(
|
|
1394
|
-
eq=False,
|
|
1395
|
-
frozen=True,
|
|
1396
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
1397
|
-
)
|
|
1398
|
-
class ArrayItemOperation(ImmutableVar):
|
|
1399
|
-
"""Base class for immutable array vars that are the result of an array item operation."""
|
|
1400
|
-
|
|
1401
|
-
a: ArrayVar = dataclasses.field(default_factory=lambda: LiteralArrayVar([]))
|
|
1402
|
-
i: NumberVar = dataclasses.field(default_factory=lambda: LiteralNumberVar(0))
|
|
1403
|
-
|
|
1404
|
-
def __init__(
|
|
1405
|
-
self,
|
|
1406
|
-
a: ArrayVar,
|
|
1407
|
-
i: NumberVar | int,
|
|
1408
|
-
_var_data: VarData | None = None,
|
|
1409
|
-
):
|
|
1410
|
-
"""Initialize the array item operation var.
|
|
1411
|
-
|
|
1412
|
-
Args:
|
|
1413
|
-
a: The array.
|
|
1414
|
-
i: The index.
|
|
1415
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
1416
|
-
"""
|
|
1417
|
-
args = typing.get_args(a._var_type)
|
|
1418
|
-
if args and isinstance(i, int) and is_tuple_type(a._var_type):
|
|
1419
|
-
element_type = args[i % len(args)]
|
|
1420
|
-
else:
|
|
1421
|
-
element_type = unionize(*args)
|
|
1422
|
-
super(ArrayItemOperation, self).__init__(
|
|
1423
|
-
_var_name="",
|
|
1424
|
-
_var_type=element_type,
|
|
1425
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
1426
|
-
)
|
|
1427
|
-
object.__setattr__(self, "a", a if isinstance(a, Var) else LiteralArrayVar(a))
|
|
1428
|
-
object.__setattr__(
|
|
1429
|
-
self,
|
|
1430
|
-
"i",
|
|
1431
|
-
i if isinstance(i, Var) else LiteralNumberVar(i),
|
|
1432
|
-
)
|
|
1433
|
-
object.__delattr__(self, "_var_name")
|
|
1434
|
-
|
|
1435
|
-
@cached_property
|
|
1436
|
-
def _cached_var_name(self) -> str:
|
|
1437
|
-
"""The name of the var.
|
|
1438
|
-
|
|
1439
|
-
Returns:
|
|
1440
|
-
The name of the var.
|
|
1441
|
-
"""
|
|
1442
|
-
return f"{str(self.a)}.at({str(self.i)})"
|
|
1443
|
-
|
|
1444
|
-
def __getattr__(self, name: str) -> Any:
|
|
1445
|
-
"""Get an attribute of the var.
|
|
1446
|
-
|
|
1447
|
-
Args:
|
|
1448
|
-
name: The name of the attribute.
|
|
1449
|
-
|
|
1450
|
-
Returns:
|
|
1451
|
-
The attribute value.
|
|
1452
|
-
"""
|
|
1453
|
-
if name == "_var_name":
|
|
1454
|
-
return self._cached_var_name
|
|
1455
|
-
getattr(super(ArrayItemOperation, self), name)
|
|
1456
|
-
|
|
1457
|
-
@cached_property
|
|
1458
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
1459
|
-
"""Get all VarData associated with the Var.
|
|
1460
|
-
|
|
1461
|
-
Returns:
|
|
1462
|
-
The VarData of the components and all of its children.
|
|
1463
|
-
"""
|
|
1464
|
-
return ImmutableVarData.merge(
|
|
1465
|
-
self.a._get_all_var_data(), self.i._get_all_var_data(), self._var_data
|
|
1466
|
-
)
|
|
1467
|
-
|
|
1468
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
1469
|
-
return self._cached_get_all_var_data
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
@dataclasses.dataclass(
|
|
1473
|
-
eq=False,
|
|
1474
|
-
frozen=True,
|
|
1475
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
1476
|
-
)
|
|
1477
|
-
class RangeOperation(ArrayVar):
|
|
1478
|
-
"""Base class for immutable array vars that are the result of a range operation."""
|
|
1479
|
-
|
|
1480
|
-
start: NumberVar = dataclasses.field(default_factory=lambda: LiteralNumberVar(0))
|
|
1481
|
-
end: NumberVar = dataclasses.field(default_factory=lambda: LiteralNumberVar(0))
|
|
1482
|
-
step: NumberVar = dataclasses.field(default_factory=lambda: LiteralNumberVar(1))
|
|
1483
|
-
|
|
1484
|
-
def __init__(
|
|
1485
|
-
self,
|
|
1486
|
-
start: NumberVar | int,
|
|
1487
|
-
end: NumberVar | int,
|
|
1488
|
-
step: NumberVar | int,
|
|
1489
|
-
_var_data: VarData | None = None,
|
|
1490
|
-
):
|
|
1491
|
-
"""Initialize the range operation var.
|
|
1492
|
-
|
|
1493
|
-
Args:
|
|
1494
|
-
start: The start of the range.
|
|
1495
|
-
end: The end of the range.
|
|
1496
|
-
step: The step of the range.
|
|
1497
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
1498
|
-
"""
|
|
1499
|
-
super(RangeOperation, self).__init__(
|
|
1500
|
-
_var_name="",
|
|
1501
|
-
_var_type=List[int],
|
|
1502
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
1503
|
-
)
|
|
1504
|
-
object.__setattr__(
|
|
1505
|
-
self,
|
|
1506
|
-
"start",
|
|
1507
|
-
start if isinstance(start, Var) else LiteralNumberVar(start),
|
|
1508
|
-
)
|
|
1509
|
-
object.__setattr__(
|
|
1510
|
-
self,
|
|
1511
|
-
"end",
|
|
1512
|
-
end if isinstance(end, Var) else LiteralNumberVar(end),
|
|
1513
|
-
)
|
|
1514
|
-
object.__setattr__(
|
|
1515
|
-
self,
|
|
1516
|
-
"step",
|
|
1517
|
-
step if isinstance(step, Var) else LiteralNumberVar(step),
|
|
1518
|
-
)
|
|
1519
|
-
object.__delattr__(self, "_var_name")
|
|
1520
|
-
|
|
1521
|
-
@cached_property
|
|
1522
|
-
def _cached_var_name(self) -> str:
|
|
1523
|
-
"""The name of the var.
|
|
1524
|
-
|
|
1525
|
-
Returns:
|
|
1526
|
-
The name of the var.
|
|
1527
|
-
"""
|
|
1528
|
-
start, end, step = self.start, self.end, self.step
|
|
1529
|
-
return f"Array.from({{ length: ({str(end)} - {str(start)}) / {str(step)} }}, (_, i) => {str(start)} + i * {str(step)})"
|
|
1530
|
-
|
|
1531
|
-
def __getattr__(self, name: str) -> Any:
|
|
1532
|
-
"""Get an attribute of the var.
|
|
1533
|
-
|
|
1534
|
-
Args:
|
|
1535
|
-
name: The name of the attribute.
|
|
1536
|
-
|
|
1537
|
-
Returns:
|
|
1538
|
-
The attribute value.
|
|
1539
|
-
"""
|
|
1540
|
-
if name == "_var_name":
|
|
1541
|
-
return self._cached_var_name
|
|
1542
|
-
getattr(super(RangeOperation, self), name)
|
|
1543
|
-
|
|
1544
|
-
@cached_property
|
|
1545
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
1546
|
-
"""Get all VarData associated with the Var.
|
|
1547
|
-
|
|
1548
|
-
Returns:
|
|
1549
|
-
The VarData of the components and all of its children.
|
|
1550
|
-
"""
|
|
1551
|
-
return ImmutableVarData.merge(
|
|
1552
|
-
self.start._get_all_var_data(),
|
|
1553
|
-
self.end._get_all_var_data(),
|
|
1554
|
-
self.step._get_all_var_data(),
|
|
1555
|
-
self._var_data,
|
|
1556
|
-
)
|
|
1557
|
-
|
|
1558
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
1559
|
-
return self._cached_get_all_var_data
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
@dataclasses.dataclass(
|
|
1563
|
-
eq=False,
|
|
1564
|
-
frozen=True,
|
|
1565
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
1566
|
-
)
|
|
1567
|
-
class ArrayContainsOperation(BooleanVar):
|
|
1568
|
-
"""Base class for immutable boolean vars that are the result of an array contains operation."""
|
|
1569
|
-
|
|
1570
|
-
a: ArrayVar = dataclasses.field(default_factory=lambda: LiteralArrayVar([]))
|
|
1571
|
-
b: Var = dataclasses.field(default_factory=lambda: LiteralVar.create(None))
|
|
1572
|
-
|
|
1573
|
-
def __init__(self, a: ArrayVar, b: Any | Var, _var_data: VarData | None = None):
|
|
1574
|
-
"""Initialize the array contains operation var.
|
|
1575
|
-
|
|
1576
|
-
Args:
|
|
1577
|
-
a: The array.
|
|
1578
|
-
b: The element to check for.
|
|
1579
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
1580
|
-
"""
|
|
1581
|
-
super(ArrayContainsOperation, self).__init__(
|
|
1582
|
-
_var_name="",
|
|
1583
|
-
_var_type=bool,
|
|
1584
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
1585
|
-
)
|
|
1586
|
-
object.__setattr__(self, "a", a)
|
|
1587
|
-
object.__setattr__(self, "b", b if isinstance(b, Var) else LiteralVar.create(b))
|
|
1588
|
-
object.__delattr__(self, "_var_name")
|
|
1589
|
-
|
|
1590
|
-
@cached_property
|
|
1591
|
-
def _cached_var_name(self) -> str:
|
|
1592
|
-
"""The name of the var.
|
|
1593
|
-
|
|
1594
|
-
Returns:
|
|
1595
|
-
The name of the var.
|
|
1596
|
-
"""
|
|
1597
|
-
return f"{str(self.a)}.includes({str(self.b)})"
|
|
1598
|
-
|
|
1599
|
-
def __getattr__(self, name: str) -> Any:
|
|
1600
|
-
"""Get an attribute of the var.
|
|
1601
|
-
|
|
1602
|
-
Args:
|
|
1603
|
-
name: The name of the attribute.
|
|
1604
|
-
|
|
1605
|
-
Returns:
|
|
1606
|
-
The attribute value.
|
|
1607
|
-
"""
|
|
1608
|
-
if name == "_var_name":
|
|
1609
|
-
return self._cached_var_name
|
|
1610
|
-
getattr(super(ArrayContainsOperation, self), name)
|
|
1611
|
-
|
|
1612
|
-
@cached_property
|
|
1613
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
1614
|
-
"""Get all VarData associated with the Var.
|
|
1615
|
-
|
|
1616
|
-
Returns:
|
|
1617
|
-
The VarData of the components and all of its children.
|
|
1618
|
-
"""
|
|
1619
|
-
return ImmutableVarData.merge(
|
|
1620
|
-
self.a._get_all_var_data(), self.b._get_all_var_data(), self._var_data
|
|
1621
|
-
)
|
|
1622
|
-
|
|
1623
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
1624
|
-
return self._cached_get_all_var_data
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
@dataclasses.dataclass(
|
|
1628
|
-
eq=False,
|
|
1629
|
-
frozen=True,
|
|
1630
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
1631
|
-
)
|
|
1632
|
-
class ToStringOperation(StringVar):
|
|
1633
|
-
"""Base class for immutable string vars that are the result of a to string operation."""
|
|
1634
|
-
|
|
1635
|
-
original_var: Var = dataclasses.field(
|
|
1636
|
-
default_factory=lambda: LiteralStringVar.create("")
|
|
1637
|
-
)
|
|
1638
|
-
|
|
1639
|
-
def __init__(self, original_var: Var, _var_data: VarData | None = None):
|
|
1640
|
-
"""Initialize the to string operation var.
|
|
1641
|
-
|
|
1642
|
-
Args:
|
|
1643
|
-
original_var: The original var.
|
|
1644
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
1645
|
-
"""
|
|
1646
|
-
super(ToStringOperation, self).__init__(
|
|
1647
|
-
_var_name="",
|
|
1648
|
-
_var_type=str,
|
|
1649
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
1650
|
-
)
|
|
1651
|
-
object.__setattr__(
|
|
1652
|
-
self,
|
|
1653
|
-
"original_var",
|
|
1654
|
-
original_var,
|
|
1655
|
-
)
|
|
1656
|
-
object.__delattr__(self, "_var_name")
|
|
1657
|
-
|
|
1658
|
-
@cached_property
|
|
1659
|
-
def _cached_var_name(self) -> str:
|
|
1660
|
-
"""The name of the var.
|
|
1661
|
-
|
|
1662
|
-
Returns:
|
|
1663
|
-
The name of the var.
|
|
1664
|
-
"""
|
|
1665
|
-
return str(self.original_var)
|
|
1666
|
-
|
|
1667
|
-
def __getattr__(self, name: str) -> Any:
|
|
1668
|
-
"""Get an attribute of the var.
|
|
1669
|
-
|
|
1670
|
-
Args:
|
|
1671
|
-
name: The name of the attribute.
|
|
1672
|
-
|
|
1673
|
-
Returns:
|
|
1674
|
-
The attribute value.
|
|
1675
|
-
"""
|
|
1676
|
-
if name == "_var_name":
|
|
1677
|
-
return self._cached_var_name
|
|
1678
|
-
getattr(super(ToStringOperation, self), name)
|
|
1679
|
-
|
|
1680
|
-
@cached_property
|
|
1681
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
1682
|
-
"""Get all VarData associated with the Var.
|
|
1683
|
-
|
|
1684
|
-
Returns:
|
|
1685
|
-
The VarData of the components and all of its children.
|
|
1686
|
-
"""
|
|
1687
|
-
return ImmutableVarData.merge(
|
|
1688
|
-
self.original_var._get_all_var_data(), self._var_data
|
|
1689
|
-
)
|
|
1690
|
-
|
|
1691
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
1692
|
-
return self._cached_get_all_var_data
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
@dataclasses.dataclass(
|
|
1696
|
-
eq=False,
|
|
1697
|
-
frozen=True,
|
|
1698
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
1699
|
-
)
|
|
1700
|
-
class ToArrayOperation(ArrayVar):
|
|
1701
|
-
"""Base class for immutable array vars that are the result of a to array operation."""
|
|
1702
|
-
|
|
1703
|
-
original_var: Var = dataclasses.field(default_factory=lambda: LiteralArrayVar([]))
|
|
1704
|
-
|
|
1705
|
-
def __init__(
|
|
1706
|
-
self,
|
|
1707
|
-
original_var: Var,
|
|
1708
|
-
_var_type: type[list] | type[set] | type[tuple] = list,
|
|
1709
|
-
_var_data: VarData | None = None,
|
|
1710
|
-
):
|
|
1711
|
-
"""Initialize the to array operation var.
|
|
1712
|
-
|
|
1713
|
-
Args:
|
|
1714
|
-
original_var: The original var.
|
|
1715
|
-
_var_type: The type of the array.
|
|
1716
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
1717
|
-
"""
|
|
1718
|
-
super(ToArrayOperation, self).__init__(
|
|
1719
|
-
_var_name="",
|
|
1720
|
-
_var_type=_var_type,
|
|
1721
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
1722
|
-
)
|
|
1723
|
-
object.__setattr__(
|
|
1724
|
-
self,
|
|
1725
|
-
"original_var",
|
|
1726
|
-
original_var,
|
|
1727
|
-
)
|
|
1728
|
-
object.__delattr__(self, "_var_name")
|
|
1729
|
-
|
|
1730
|
-
@cached_property
|
|
1731
|
-
def _cached_var_name(self) -> str:
|
|
1732
|
-
"""The name of the var.
|
|
1733
|
-
|
|
1734
|
-
Returns:
|
|
1735
|
-
The name of the var.
|
|
1736
|
-
"""
|
|
1737
|
-
return str(self.original_var)
|
|
1738
|
-
|
|
1739
|
-
def __getattr__(self, name: str) -> Any:
|
|
1740
|
-
"""Get an attribute of the var.
|
|
1741
|
-
|
|
1742
|
-
Args:
|
|
1743
|
-
name: The name of the attribute.
|
|
1744
|
-
|
|
1745
|
-
Returns:
|
|
1746
|
-
The attribute value.
|
|
1747
|
-
"""
|
|
1748
|
-
if name == "_var_name":
|
|
1749
|
-
return self._cached_var_name
|
|
1750
|
-
getattr(super(ToArrayOperation, self), name)
|
|
1751
|
-
|
|
1752
|
-
@cached_property
|
|
1753
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
1754
|
-
"""Get all VarData associated with the Var.
|
|
1755
|
-
|
|
1756
|
-
Returns:
|
|
1757
|
-
The VarData of the components and all of its children.
|
|
1758
|
-
"""
|
|
1759
|
-
return ImmutableVarData.merge(
|
|
1760
|
-
self.original_var._get_all_var_data(), self._var_data
|
|
1761
|
-
)
|
|
1762
|
-
|
|
1763
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
1764
|
-
return self._cached_get_all_var_data
|