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,804 +0,0 @@
|
|
|
1
|
-
"""Classes for immutable object vars."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
import dataclasses
|
|
6
|
-
import sys
|
|
7
|
-
import typing
|
|
8
|
-
from functools import cached_property
|
|
9
|
-
from inspect import isclass
|
|
10
|
-
from typing import (
|
|
11
|
-
Any,
|
|
12
|
-
Dict,
|
|
13
|
-
List,
|
|
14
|
-
NoReturn,
|
|
15
|
-
Tuple,
|
|
16
|
-
Type,
|
|
17
|
-
TypeVar,
|
|
18
|
-
Union,
|
|
19
|
-
get_args,
|
|
20
|
-
overload,
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
from typing_extensions import get_origin
|
|
24
|
-
|
|
25
|
-
from reflex.experimental.vars.base import (
|
|
26
|
-
ImmutableVar,
|
|
27
|
-
LiteralVar,
|
|
28
|
-
figure_out_type,
|
|
29
|
-
)
|
|
30
|
-
from reflex.experimental.vars.number import NumberVar
|
|
31
|
-
from reflex.experimental.vars.sequence import ArrayVar, StringVar
|
|
32
|
-
from reflex.utils.exceptions import VarAttributeError
|
|
33
|
-
from reflex.utils.types import GenericType, get_attribute_access_type
|
|
34
|
-
from reflex.vars import ImmutableVarData, Var, VarData
|
|
35
|
-
|
|
36
|
-
OBJECT_TYPE = TypeVar("OBJECT_TYPE")
|
|
37
|
-
|
|
38
|
-
KEY_TYPE = TypeVar("KEY_TYPE")
|
|
39
|
-
VALUE_TYPE = TypeVar("VALUE_TYPE")
|
|
40
|
-
|
|
41
|
-
ARRAY_INNER_TYPE = TypeVar("ARRAY_INNER_TYPE")
|
|
42
|
-
|
|
43
|
-
OTHER_KEY_TYPE = TypeVar("OTHER_KEY_TYPE")
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
class ObjectVar(ImmutableVar[OBJECT_TYPE]):
|
|
47
|
-
"""Base class for immutable object vars."""
|
|
48
|
-
|
|
49
|
-
@overload
|
|
50
|
-
def _key_type(self: ObjectVar[Dict[KEY_TYPE, VALUE_TYPE]]) -> KEY_TYPE: ...
|
|
51
|
-
|
|
52
|
-
@overload
|
|
53
|
-
def _key_type(self) -> Type: ...
|
|
54
|
-
|
|
55
|
-
def _key_type(self) -> Type:
|
|
56
|
-
"""Get the type of the keys of the object.
|
|
57
|
-
|
|
58
|
-
Returns:
|
|
59
|
-
The type of the keys of the object.
|
|
60
|
-
"""
|
|
61
|
-
fixed_type = (
|
|
62
|
-
self._var_type if isclass(self._var_type) else get_origin(self._var_type)
|
|
63
|
-
)
|
|
64
|
-
args = get_args(self._var_type) if issubclass(fixed_type, dict) else ()
|
|
65
|
-
return args[0] if args else Any
|
|
66
|
-
|
|
67
|
-
@overload
|
|
68
|
-
def _value_type(self: ObjectVar[Dict[KEY_TYPE, VALUE_TYPE]]) -> VALUE_TYPE: ...
|
|
69
|
-
|
|
70
|
-
@overload
|
|
71
|
-
def _value_type(self) -> Type: ...
|
|
72
|
-
|
|
73
|
-
def _value_type(self) -> Type:
|
|
74
|
-
"""Get the type of the values of the object.
|
|
75
|
-
|
|
76
|
-
Returns:
|
|
77
|
-
The type of the values of the object.
|
|
78
|
-
"""
|
|
79
|
-
fixed_type = (
|
|
80
|
-
self._var_type if isclass(self._var_type) else get_origin(self._var_type)
|
|
81
|
-
)
|
|
82
|
-
args = get_args(self._var_type) if issubclass(fixed_type, dict) else ()
|
|
83
|
-
return args[1] if args else Any
|
|
84
|
-
|
|
85
|
-
@overload
|
|
86
|
-
def keys(
|
|
87
|
-
self: ObjectVar[Dict[KEY_TYPE, VALUE_TYPE]],
|
|
88
|
-
) -> ArrayVar[List[KEY_TYPE]]: ...
|
|
89
|
-
|
|
90
|
-
@overload
|
|
91
|
-
def keys(self) -> ArrayVar: ...
|
|
92
|
-
|
|
93
|
-
def keys(self) -> ArrayVar:
|
|
94
|
-
"""Get the keys of the object.
|
|
95
|
-
|
|
96
|
-
Returns:
|
|
97
|
-
The keys of the object.
|
|
98
|
-
"""
|
|
99
|
-
return ObjectKeysOperation(self)
|
|
100
|
-
|
|
101
|
-
@overload
|
|
102
|
-
def values(
|
|
103
|
-
self: ObjectVar[Dict[KEY_TYPE, VALUE_TYPE]],
|
|
104
|
-
) -> ArrayVar[List[VALUE_TYPE]]: ...
|
|
105
|
-
|
|
106
|
-
@overload
|
|
107
|
-
def values(self) -> ArrayVar: ...
|
|
108
|
-
|
|
109
|
-
def values(self) -> ArrayVar:
|
|
110
|
-
"""Get the values of the object.
|
|
111
|
-
|
|
112
|
-
Returns:
|
|
113
|
-
The values of the object.
|
|
114
|
-
"""
|
|
115
|
-
return ObjectValuesOperation(self)
|
|
116
|
-
|
|
117
|
-
@overload
|
|
118
|
-
def entries(
|
|
119
|
-
self: ObjectVar[Dict[KEY_TYPE, VALUE_TYPE]],
|
|
120
|
-
) -> ArrayVar[List[Tuple[KEY_TYPE, VALUE_TYPE]]]: ...
|
|
121
|
-
|
|
122
|
-
@overload
|
|
123
|
-
def entries(self) -> ArrayVar: ...
|
|
124
|
-
|
|
125
|
-
def entries(self) -> ArrayVar:
|
|
126
|
-
"""Get the entries of the object.
|
|
127
|
-
|
|
128
|
-
Returns:
|
|
129
|
-
The entries of the object.
|
|
130
|
-
"""
|
|
131
|
-
return ObjectEntriesOperation(self)
|
|
132
|
-
|
|
133
|
-
def merge(self, other: ObjectVar) -> ObjectMergeOperation:
|
|
134
|
-
"""Merge two objects.
|
|
135
|
-
|
|
136
|
-
Args:
|
|
137
|
-
other: The other object to merge.
|
|
138
|
-
|
|
139
|
-
Returns:
|
|
140
|
-
The merged object.
|
|
141
|
-
"""
|
|
142
|
-
return ObjectMergeOperation(self, other)
|
|
143
|
-
|
|
144
|
-
# NoReturn is used here to catch when key value is Any
|
|
145
|
-
@overload
|
|
146
|
-
def __getitem__(
|
|
147
|
-
self: ObjectVar[Dict[KEY_TYPE, NoReturn]],
|
|
148
|
-
key: Var | Any,
|
|
149
|
-
) -> ImmutableVar: ...
|
|
150
|
-
|
|
151
|
-
@overload
|
|
152
|
-
def __getitem__(
|
|
153
|
-
self: (
|
|
154
|
-
ObjectVar[Dict[KEY_TYPE, int]]
|
|
155
|
-
| ObjectVar[Dict[KEY_TYPE, float]]
|
|
156
|
-
| ObjectVar[Dict[KEY_TYPE, int | float]]
|
|
157
|
-
),
|
|
158
|
-
key: Var | Any,
|
|
159
|
-
) -> NumberVar: ...
|
|
160
|
-
|
|
161
|
-
@overload
|
|
162
|
-
def __getitem__(
|
|
163
|
-
self: ObjectVar[Dict[KEY_TYPE, str]],
|
|
164
|
-
key: Var | Any,
|
|
165
|
-
) -> StringVar: ...
|
|
166
|
-
|
|
167
|
-
@overload
|
|
168
|
-
def __getitem__(
|
|
169
|
-
self: ObjectVar[Dict[KEY_TYPE, list[ARRAY_INNER_TYPE]]],
|
|
170
|
-
key: Var | Any,
|
|
171
|
-
) -> ArrayVar[list[ARRAY_INNER_TYPE]]: ...
|
|
172
|
-
|
|
173
|
-
@overload
|
|
174
|
-
def __getitem__(
|
|
175
|
-
self: ObjectVar[Dict[KEY_TYPE, set[ARRAY_INNER_TYPE]]],
|
|
176
|
-
key: Var | Any,
|
|
177
|
-
) -> ArrayVar[set[ARRAY_INNER_TYPE]]: ...
|
|
178
|
-
|
|
179
|
-
@overload
|
|
180
|
-
def __getitem__(
|
|
181
|
-
self: ObjectVar[Dict[KEY_TYPE, tuple[ARRAY_INNER_TYPE, ...]]],
|
|
182
|
-
key: Var | Any,
|
|
183
|
-
) -> ArrayVar[tuple[ARRAY_INNER_TYPE, ...]]: ...
|
|
184
|
-
|
|
185
|
-
@overload
|
|
186
|
-
def __getitem__(
|
|
187
|
-
self: ObjectVar[Dict[KEY_TYPE, dict[OTHER_KEY_TYPE, VALUE_TYPE]]],
|
|
188
|
-
key: Var | Any,
|
|
189
|
-
) -> ObjectVar[dict[OTHER_KEY_TYPE, VALUE_TYPE]]: ...
|
|
190
|
-
|
|
191
|
-
def __getitem__(self, key: Var | Any) -> ImmutableVar:
|
|
192
|
-
"""Get an item from the object.
|
|
193
|
-
|
|
194
|
-
Args:
|
|
195
|
-
key: The key to get from the object.
|
|
196
|
-
|
|
197
|
-
Returns:
|
|
198
|
-
The item from the object.
|
|
199
|
-
"""
|
|
200
|
-
return ObjectItemOperation(self, key).guess_type()
|
|
201
|
-
|
|
202
|
-
# NoReturn is used here to catch when key value is Any
|
|
203
|
-
@overload
|
|
204
|
-
def __getattr__(
|
|
205
|
-
self: ObjectVar[Dict[KEY_TYPE, NoReturn]],
|
|
206
|
-
name: str,
|
|
207
|
-
) -> ImmutableVar: ...
|
|
208
|
-
|
|
209
|
-
@overload
|
|
210
|
-
def __getattr__(
|
|
211
|
-
self: (
|
|
212
|
-
ObjectVar[Dict[KEY_TYPE, int]]
|
|
213
|
-
| ObjectVar[Dict[KEY_TYPE, float]]
|
|
214
|
-
| ObjectVar[Dict[KEY_TYPE, int | float]]
|
|
215
|
-
),
|
|
216
|
-
name: str,
|
|
217
|
-
) -> NumberVar: ...
|
|
218
|
-
|
|
219
|
-
@overload
|
|
220
|
-
def __getattr__(
|
|
221
|
-
self: ObjectVar[Dict[KEY_TYPE, str]],
|
|
222
|
-
name: str,
|
|
223
|
-
) -> StringVar: ...
|
|
224
|
-
|
|
225
|
-
@overload
|
|
226
|
-
def __getattr__(
|
|
227
|
-
self: ObjectVar[Dict[KEY_TYPE, list[ARRAY_INNER_TYPE]]],
|
|
228
|
-
name: str,
|
|
229
|
-
) -> ArrayVar[list[ARRAY_INNER_TYPE]]: ...
|
|
230
|
-
|
|
231
|
-
@overload
|
|
232
|
-
def __getattr__(
|
|
233
|
-
self: ObjectVar[Dict[KEY_TYPE, set[ARRAY_INNER_TYPE]]],
|
|
234
|
-
name: str,
|
|
235
|
-
) -> ArrayVar[set[ARRAY_INNER_TYPE]]: ...
|
|
236
|
-
|
|
237
|
-
@overload
|
|
238
|
-
def __getattr__(
|
|
239
|
-
self: ObjectVar[Dict[KEY_TYPE, tuple[ARRAY_INNER_TYPE, ...]]],
|
|
240
|
-
name: str,
|
|
241
|
-
) -> ArrayVar[tuple[ARRAY_INNER_TYPE, ...]]: ...
|
|
242
|
-
|
|
243
|
-
@overload
|
|
244
|
-
def __getattr__(
|
|
245
|
-
self: ObjectVar[Dict[KEY_TYPE, dict[OTHER_KEY_TYPE, VALUE_TYPE]]],
|
|
246
|
-
name: str,
|
|
247
|
-
) -> ObjectVar[dict[OTHER_KEY_TYPE, VALUE_TYPE]]: ...
|
|
248
|
-
|
|
249
|
-
def __getattr__(self, name) -> ImmutableVar:
|
|
250
|
-
"""Get an attribute of the var.
|
|
251
|
-
|
|
252
|
-
Args:
|
|
253
|
-
name: The name of the attribute.
|
|
254
|
-
|
|
255
|
-
Raises:
|
|
256
|
-
VarAttributeError: The State var has no such attribute or may have been annotated wrongly.
|
|
257
|
-
|
|
258
|
-
Returns:
|
|
259
|
-
The attribute of the var.
|
|
260
|
-
"""
|
|
261
|
-
fixed_type = (
|
|
262
|
-
self._var_type if isclass(self._var_type) else get_origin(self._var_type)
|
|
263
|
-
)
|
|
264
|
-
if not issubclass(fixed_type, dict):
|
|
265
|
-
attribute_type = get_attribute_access_type(self._var_type, name)
|
|
266
|
-
if attribute_type is None:
|
|
267
|
-
raise VarAttributeError(
|
|
268
|
-
f"The State var `{self._var_name}` has no attribute '{name}' or may have been annotated "
|
|
269
|
-
f"wrongly."
|
|
270
|
-
)
|
|
271
|
-
return ObjectItemOperation(self, name, attribute_type).guess_type()
|
|
272
|
-
else:
|
|
273
|
-
return ObjectItemOperation(self, name).guess_type()
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
@dataclasses.dataclass(
|
|
277
|
-
eq=False,
|
|
278
|
-
frozen=True,
|
|
279
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
280
|
-
)
|
|
281
|
-
class LiteralObjectVar(LiteralVar, ObjectVar[OBJECT_TYPE]):
|
|
282
|
-
"""Base class for immutable literal object vars."""
|
|
283
|
-
|
|
284
|
-
_var_value: Dict[Union[Var, Any], Union[Var, Any]] = dataclasses.field(
|
|
285
|
-
default_factory=dict
|
|
286
|
-
)
|
|
287
|
-
|
|
288
|
-
def __init__(
|
|
289
|
-
self: LiteralObjectVar[OBJECT_TYPE],
|
|
290
|
-
_var_value: OBJECT_TYPE,
|
|
291
|
-
_var_type: Type[OBJECT_TYPE] | None = None,
|
|
292
|
-
_var_data: VarData | None = None,
|
|
293
|
-
):
|
|
294
|
-
"""Initialize the object var.
|
|
295
|
-
|
|
296
|
-
Args:
|
|
297
|
-
_var_value: The value of the var.
|
|
298
|
-
_var_type: The type of the var.
|
|
299
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
300
|
-
"""
|
|
301
|
-
super(LiteralObjectVar, self).__init__(
|
|
302
|
-
_var_name="",
|
|
303
|
-
_var_type=(figure_out_type(_var_value) if _var_type is None else _var_type),
|
|
304
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
305
|
-
)
|
|
306
|
-
object.__setattr__(
|
|
307
|
-
self,
|
|
308
|
-
"_var_value",
|
|
309
|
-
_var_value,
|
|
310
|
-
)
|
|
311
|
-
object.__delattr__(self, "_var_name")
|
|
312
|
-
|
|
313
|
-
def _key_type(self) -> Type:
|
|
314
|
-
"""Get the type of the keys of the object.
|
|
315
|
-
|
|
316
|
-
Returns:
|
|
317
|
-
The type of the keys of the object.
|
|
318
|
-
"""
|
|
319
|
-
args_list = typing.get_args(self._var_type)
|
|
320
|
-
return args_list[0] if args_list else Any
|
|
321
|
-
|
|
322
|
-
def _value_type(self) -> Type:
|
|
323
|
-
"""Get the type of the values of the object.
|
|
324
|
-
|
|
325
|
-
Returns:
|
|
326
|
-
The type of the values of the object.
|
|
327
|
-
"""
|
|
328
|
-
args_list = typing.get_args(self._var_type)
|
|
329
|
-
return args_list[1] if args_list else Any
|
|
330
|
-
|
|
331
|
-
def __getattr__(self, name):
|
|
332
|
-
"""Get an attribute of the var.
|
|
333
|
-
|
|
334
|
-
Args:
|
|
335
|
-
name: The name of the attribute.
|
|
336
|
-
|
|
337
|
-
Returns:
|
|
338
|
-
The attribute of the var.
|
|
339
|
-
"""
|
|
340
|
-
if name == "_var_name":
|
|
341
|
-
return self._cached_var_name
|
|
342
|
-
return super(type(self), self).__getattr__(name)
|
|
343
|
-
|
|
344
|
-
@cached_property
|
|
345
|
-
def _cached_var_name(self) -> str:
|
|
346
|
-
"""The name of the var.
|
|
347
|
-
|
|
348
|
-
Returns:
|
|
349
|
-
The name of the var.
|
|
350
|
-
"""
|
|
351
|
-
return (
|
|
352
|
-
"({ "
|
|
353
|
-
+ ", ".join(
|
|
354
|
-
[
|
|
355
|
-
f"[{str(LiteralVar.create(key))}] : {str(LiteralVar.create(value))}"
|
|
356
|
-
for key, value in self._var_value.items()
|
|
357
|
-
]
|
|
358
|
-
)
|
|
359
|
-
+ " })"
|
|
360
|
-
)
|
|
361
|
-
|
|
362
|
-
@cached_property
|
|
363
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
364
|
-
"""Get all VarData associated with the Var.
|
|
365
|
-
|
|
366
|
-
Returns:
|
|
367
|
-
The VarData of the components and all of its children.
|
|
368
|
-
"""
|
|
369
|
-
return ImmutableVarData.merge(
|
|
370
|
-
*[
|
|
371
|
-
value._get_all_var_data()
|
|
372
|
-
for key, value in self._var_value
|
|
373
|
-
if isinstance(value, Var)
|
|
374
|
-
],
|
|
375
|
-
*[
|
|
376
|
-
key._get_all_var_data()
|
|
377
|
-
for key, value in self._var_value
|
|
378
|
-
if isinstance(key, Var)
|
|
379
|
-
],
|
|
380
|
-
self._var_data,
|
|
381
|
-
)
|
|
382
|
-
|
|
383
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
384
|
-
"""Wrapper method for cached property.
|
|
385
|
-
|
|
386
|
-
Returns:
|
|
387
|
-
The VarData of the components and all of its children.
|
|
388
|
-
"""
|
|
389
|
-
return self._cached_get_all_var_data
|
|
390
|
-
|
|
391
|
-
def json(self) -> str:
|
|
392
|
-
"""Get the JSON representation of the object.
|
|
393
|
-
|
|
394
|
-
Returns:
|
|
395
|
-
The JSON representation of the object.
|
|
396
|
-
"""
|
|
397
|
-
return (
|
|
398
|
-
"{"
|
|
399
|
-
+ ", ".join(
|
|
400
|
-
[
|
|
401
|
-
f"{LiteralVar.create(key).json()}:{LiteralVar.create(value).json()}"
|
|
402
|
-
for key, value in self._var_value.items()
|
|
403
|
-
]
|
|
404
|
-
)
|
|
405
|
-
+ "}"
|
|
406
|
-
)
|
|
407
|
-
|
|
408
|
-
def __hash__(self) -> int:
|
|
409
|
-
"""Get the hash of the var.
|
|
410
|
-
|
|
411
|
-
Returns:
|
|
412
|
-
The hash of the var.
|
|
413
|
-
"""
|
|
414
|
-
return hash((self.__class__.__name__, self._var_name))
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
@dataclasses.dataclass(
|
|
418
|
-
eq=False,
|
|
419
|
-
frozen=True,
|
|
420
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
421
|
-
)
|
|
422
|
-
class ObjectToArrayOperation(ArrayVar):
|
|
423
|
-
"""Base class for object to array operations."""
|
|
424
|
-
|
|
425
|
-
value: ObjectVar = dataclasses.field(default_factory=lambda: LiteralObjectVar({}))
|
|
426
|
-
|
|
427
|
-
def __init__(
|
|
428
|
-
self,
|
|
429
|
-
_var_value: ObjectVar,
|
|
430
|
-
_var_type: Type = list,
|
|
431
|
-
_var_data: VarData | None = None,
|
|
432
|
-
):
|
|
433
|
-
"""Initialize the object to array operation.
|
|
434
|
-
|
|
435
|
-
Args:
|
|
436
|
-
_var_value: The value of the operation.
|
|
437
|
-
_var_data: Additional hooks and imports associated with the operation.
|
|
438
|
-
"""
|
|
439
|
-
super(ObjectToArrayOperation, self).__init__(
|
|
440
|
-
_var_name="",
|
|
441
|
-
_var_type=_var_type,
|
|
442
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
443
|
-
)
|
|
444
|
-
object.__setattr__(self, "value", _var_value)
|
|
445
|
-
object.__delattr__(self, "_var_name")
|
|
446
|
-
|
|
447
|
-
@cached_property
|
|
448
|
-
def _cached_var_name(self) -> str:
|
|
449
|
-
"""The name of the operation.
|
|
450
|
-
|
|
451
|
-
Raises:
|
|
452
|
-
NotImplementedError: Must implement _cached_var_name.
|
|
453
|
-
"""
|
|
454
|
-
raise NotImplementedError(
|
|
455
|
-
"ObjectToArrayOperation must implement _cached_var_name"
|
|
456
|
-
)
|
|
457
|
-
|
|
458
|
-
def __getattr__(self, name):
|
|
459
|
-
"""Get an attribute of the operation.
|
|
460
|
-
|
|
461
|
-
Args:
|
|
462
|
-
name: The name of the attribute.
|
|
463
|
-
|
|
464
|
-
Returns:
|
|
465
|
-
The attribute of the operation.
|
|
466
|
-
"""
|
|
467
|
-
if name == "_var_name":
|
|
468
|
-
return self._cached_var_name
|
|
469
|
-
return super(type(self), self).__getattr__(name)
|
|
470
|
-
|
|
471
|
-
@cached_property
|
|
472
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
473
|
-
"""Get all VarData associated with the operation.
|
|
474
|
-
|
|
475
|
-
Returns:
|
|
476
|
-
The VarData of the components and all of its children.
|
|
477
|
-
"""
|
|
478
|
-
return ImmutableVarData.merge(
|
|
479
|
-
self.value._get_all_var_data(),
|
|
480
|
-
self._var_data,
|
|
481
|
-
)
|
|
482
|
-
|
|
483
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
484
|
-
"""Wrapper method for cached property.
|
|
485
|
-
|
|
486
|
-
Returns:
|
|
487
|
-
The VarData of the components and all of its children.
|
|
488
|
-
"""
|
|
489
|
-
return self._cached_get_all_var_data
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
class ObjectKeysOperation(ObjectToArrayOperation):
|
|
493
|
-
"""Operation to get the keys of an object."""
|
|
494
|
-
|
|
495
|
-
def __init__(
|
|
496
|
-
self,
|
|
497
|
-
value: ObjectVar,
|
|
498
|
-
_var_data: VarData | None = None,
|
|
499
|
-
):
|
|
500
|
-
"""Initialize the object keys operation.
|
|
501
|
-
|
|
502
|
-
Args:
|
|
503
|
-
value: The value of the operation.
|
|
504
|
-
_var_data: Additional hooks and imports associated with the operation.
|
|
505
|
-
"""
|
|
506
|
-
super(ObjectKeysOperation, self).__init__(
|
|
507
|
-
value, List[value._key_type()], _var_data
|
|
508
|
-
)
|
|
509
|
-
|
|
510
|
-
@cached_property
|
|
511
|
-
def _cached_var_name(self) -> str:
|
|
512
|
-
"""The name of the operation.
|
|
513
|
-
|
|
514
|
-
Returns:
|
|
515
|
-
The name of the operation.
|
|
516
|
-
"""
|
|
517
|
-
return f"Object.keys({self.value._var_name})"
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
class ObjectValuesOperation(ObjectToArrayOperation):
|
|
521
|
-
"""Operation to get the values of an object."""
|
|
522
|
-
|
|
523
|
-
def __init__(
|
|
524
|
-
self,
|
|
525
|
-
value: ObjectVar,
|
|
526
|
-
_var_data: VarData | None = None,
|
|
527
|
-
):
|
|
528
|
-
"""Initialize the object values operation.
|
|
529
|
-
|
|
530
|
-
Args:
|
|
531
|
-
value: The value of the operation.
|
|
532
|
-
_var_data: Additional hooks and imports associated with the operation.
|
|
533
|
-
"""
|
|
534
|
-
super(ObjectValuesOperation, self).__init__(
|
|
535
|
-
value, List[value._value_type()], _var_data
|
|
536
|
-
)
|
|
537
|
-
|
|
538
|
-
@cached_property
|
|
539
|
-
def _cached_var_name(self) -> str:
|
|
540
|
-
"""The name of the operation.
|
|
541
|
-
|
|
542
|
-
Returns:
|
|
543
|
-
The name of the operation.
|
|
544
|
-
"""
|
|
545
|
-
return f"Object.values({self.value._var_name})"
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
class ObjectEntriesOperation(ObjectToArrayOperation):
|
|
549
|
-
"""Operation to get the entries of an object."""
|
|
550
|
-
|
|
551
|
-
def __init__(
|
|
552
|
-
self,
|
|
553
|
-
value: ObjectVar,
|
|
554
|
-
_var_data: VarData | None = None,
|
|
555
|
-
):
|
|
556
|
-
"""Initialize the object entries operation.
|
|
557
|
-
|
|
558
|
-
Args:
|
|
559
|
-
value: The value of the operation.
|
|
560
|
-
_var_data: Additional hooks and imports associated with the operation.
|
|
561
|
-
"""
|
|
562
|
-
super(ObjectEntriesOperation, self).__init__(
|
|
563
|
-
value, List[Tuple[value._key_type(), value._value_type()]], _var_data
|
|
564
|
-
)
|
|
565
|
-
|
|
566
|
-
@cached_property
|
|
567
|
-
def _cached_var_name(self) -> str:
|
|
568
|
-
"""The name of the operation.
|
|
569
|
-
|
|
570
|
-
Returns:
|
|
571
|
-
The name of the operation.
|
|
572
|
-
"""
|
|
573
|
-
return f"Object.entries({self.value._var_name})"
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
@dataclasses.dataclass(
|
|
577
|
-
eq=False,
|
|
578
|
-
frozen=True,
|
|
579
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
580
|
-
)
|
|
581
|
-
class ObjectMergeOperation(ObjectVar):
|
|
582
|
-
"""Operation to merge two objects."""
|
|
583
|
-
|
|
584
|
-
left: ObjectVar = dataclasses.field(default_factory=lambda: LiteralObjectVar({}))
|
|
585
|
-
right: ObjectVar = dataclasses.field(default_factory=lambda: LiteralObjectVar({}))
|
|
586
|
-
|
|
587
|
-
def __init__(
|
|
588
|
-
self,
|
|
589
|
-
left: ObjectVar,
|
|
590
|
-
right: ObjectVar,
|
|
591
|
-
_var_data: VarData | None = None,
|
|
592
|
-
):
|
|
593
|
-
"""Initialize the object merge operation.
|
|
594
|
-
|
|
595
|
-
Args:
|
|
596
|
-
left: The left object to merge.
|
|
597
|
-
right: The right object to merge.
|
|
598
|
-
_var_data: Additional hooks and imports associated with the operation.
|
|
599
|
-
"""
|
|
600
|
-
super(ObjectMergeOperation, self).__init__(
|
|
601
|
-
_var_name="",
|
|
602
|
-
_var_type=left._var_type,
|
|
603
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
604
|
-
)
|
|
605
|
-
object.__setattr__(self, "left", left)
|
|
606
|
-
object.__setattr__(self, "right", right)
|
|
607
|
-
object.__delattr__(self, "_var_name")
|
|
608
|
-
|
|
609
|
-
@cached_property
|
|
610
|
-
def _cached_var_name(self) -> str:
|
|
611
|
-
"""The name of the operation.
|
|
612
|
-
|
|
613
|
-
Returns:
|
|
614
|
-
The name of the operation.
|
|
615
|
-
"""
|
|
616
|
-
return f"Object.assign({self.left._var_name}, {self.right._var_name})"
|
|
617
|
-
|
|
618
|
-
def __getattr__(self, name):
|
|
619
|
-
"""Get an attribute of the operation.
|
|
620
|
-
|
|
621
|
-
Args:
|
|
622
|
-
name: The name of the attribute.
|
|
623
|
-
|
|
624
|
-
Returns:
|
|
625
|
-
The attribute of the operation.
|
|
626
|
-
"""
|
|
627
|
-
if name == "_var_name":
|
|
628
|
-
return self._cached_var_name
|
|
629
|
-
return super(type(self), self).__getattr__(name)
|
|
630
|
-
|
|
631
|
-
@cached_property
|
|
632
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
633
|
-
"""Get all VarData associated with the operation.
|
|
634
|
-
|
|
635
|
-
Returns:
|
|
636
|
-
The VarData of the components and all of its children.
|
|
637
|
-
"""
|
|
638
|
-
return ImmutableVarData.merge(
|
|
639
|
-
self.left._get_all_var_data(),
|
|
640
|
-
self.right._get_all_var_data(),
|
|
641
|
-
self._var_data,
|
|
642
|
-
)
|
|
643
|
-
|
|
644
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
645
|
-
"""Wrapper method for cached property.
|
|
646
|
-
|
|
647
|
-
Returns:
|
|
648
|
-
The VarData of the components and all of its children.
|
|
649
|
-
"""
|
|
650
|
-
return self._cached_get_all_var_data
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
@dataclasses.dataclass(
|
|
654
|
-
eq=False,
|
|
655
|
-
frozen=True,
|
|
656
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
657
|
-
)
|
|
658
|
-
class ObjectItemOperation(ImmutableVar):
|
|
659
|
-
"""Operation to get an item from an object."""
|
|
660
|
-
|
|
661
|
-
value: ObjectVar = dataclasses.field(default_factory=lambda: LiteralObjectVar({}))
|
|
662
|
-
key: Var | Any = dataclasses.field(default_factory=lambda: LiteralVar.create(None))
|
|
663
|
-
|
|
664
|
-
def __init__(
|
|
665
|
-
self,
|
|
666
|
-
value: ObjectVar,
|
|
667
|
-
key: Var | Any,
|
|
668
|
-
_var_type: GenericType | None = None,
|
|
669
|
-
_var_data: VarData | None = None,
|
|
670
|
-
):
|
|
671
|
-
"""Initialize the object item operation.
|
|
672
|
-
|
|
673
|
-
Args:
|
|
674
|
-
value: The value of the operation.
|
|
675
|
-
key: The key to get from the object.
|
|
676
|
-
_var_data: Additional hooks and imports associated with the operation.
|
|
677
|
-
"""
|
|
678
|
-
super(ObjectItemOperation, self).__init__(
|
|
679
|
-
_var_name="",
|
|
680
|
-
_var_type=value._value_type() if _var_type is None else _var_type,
|
|
681
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
682
|
-
)
|
|
683
|
-
object.__setattr__(self, "value", value)
|
|
684
|
-
object.__setattr__(
|
|
685
|
-
self, "key", key if isinstance(key, Var) else LiteralVar.create(key)
|
|
686
|
-
)
|
|
687
|
-
object.__delattr__(self, "_var_name")
|
|
688
|
-
|
|
689
|
-
@cached_property
|
|
690
|
-
def _cached_var_name(self) -> str:
|
|
691
|
-
"""The name of the operation.
|
|
692
|
-
|
|
693
|
-
Returns:
|
|
694
|
-
The name of the operation.
|
|
695
|
-
"""
|
|
696
|
-
return f"{str(self.value)}[{str(self.key)}]"
|
|
697
|
-
|
|
698
|
-
def __getattr__(self, name):
|
|
699
|
-
"""Get an attribute of the operation.
|
|
700
|
-
|
|
701
|
-
Args:
|
|
702
|
-
name: The name of the attribute.
|
|
703
|
-
|
|
704
|
-
Returns:
|
|
705
|
-
The attribute of the operation.
|
|
706
|
-
"""
|
|
707
|
-
if name == "_var_name":
|
|
708
|
-
return self._cached_var_name
|
|
709
|
-
return super(type(self), self).__getattr__(name)
|
|
710
|
-
|
|
711
|
-
@cached_property
|
|
712
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
713
|
-
"""Get all VarData associated with the operation.
|
|
714
|
-
|
|
715
|
-
Returns:
|
|
716
|
-
The VarData of the components and all of its children.
|
|
717
|
-
"""
|
|
718
|
-
return ImmutableVarData.merge(
|
|
719
|
-
self.value._get_all_var_data(),
|
|
720
|
-
self.key._get_all_var_data(),
|
|
721
|
-
self._var_data,
|
|
722
|
-
)
|
|
723
|
-
|
|
724
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
725
|
-
"""Wrapper method for cached property.
|
|
726
|
-
|
|
727
|
-
Returns:
|
|
728
|
-
The VarData of the components and all of its children.
|
|
729
|
-
"""
|
|
730
|
-
return self._cached_get_all_var_data
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
@dataclasses.dataclass(
|
|
734
|
-
eq=False,
|
|
735
|
-
frozen=True,
|
|
736
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
737
|
-
)
|
|
738
|
-
class ToObjectOperation(ObjectVar):
|
|
739
|
-
"""Operation to convert a var to an object."""
|
|
740
|
-
|
|
741
|
-
_original_var: Var = dataclasses.field(default_factory=lambda: LiteralObjectVar({}))
|
|
742
|
-
|
|
743
|
-
def __init__(
|
|
744
|
-
self,
|
|
745
|
-
_original_var: Var,
|
|
746
|
-
_var_type: Type = dict,
|
|
747
|
-
_var_data: VarData | None = None,
|
|
748
|
-
):
|
|
749
|
-
"""Initialize the to object operation.
|
|
750
|
-
|
|
751
|
-
Args:
|
|
752
|
-
_original_var: The original var to convert.
|
|
753
|
-
_var_type: The type of the var.
|
|
754
|
-
_var_data: Additional hooks and imports associated with the operation.
|
|
755
|
-
"""
|
|
756
|
-
super(ToObjectOperation, self).__init__(
|
|
757
|
-
_var_name="",
|
|
758
|
-
_var_type=_var_type,
|
|
759
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
760
|
-
)
|
|
761
|
-
object.__setattr__(self, "_original_var", _original_var)
|
|
762
|
-
object.__delattr__(self, "_var_name")
|
|
763
|
-
|
|
764
|
-
@cached_property
|
|
765
|
-
def _cached_var_name(self) -> str:
|
|
766
|
-
"""The name of the operation.
|
|
767
|
-
|
|
768
|
-
Returns:
|
|
769
|
-
The name of the operation.
|
|
770
|
-
"""
|
|
771
|
-
return str(self._original_var)
|
|
772
|
-
|
|
773
|
-
def __getattr__(self, name):
|
|
774
|
-
"""Get an attribute of the operation.
|
|
775
|
-
|
|
776
|
-
Args:
|
|
777
|
-
name: The name of the attribute.
|
|
778
|
-
|
|
779
|
-
Returns:
|
|
780
|
-
The attribute of the operation.
|
|
781
|
-
"""
|
|
782
|
-
if name == "_var_name":
|
|
783
|
-
return self._cached_var_name
|
|
784
|
-
return super(type(self), self).__getattr__(name)
|
|
785
|
-
|
|
786
|
-
@cached_property
|
|
787
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
788
|
-
"""Get all VarData associated with the operation.
|
|
789
|
-
|
|
790
|
-
Returns:
|
|
791
|
-
The VarData of the components and all of its children.
|
|
792
|
-
"""
|
|
793
|
-
return ImmutableVarData.merge(
|
|
794
|
-
self._original_var._get_all_var_data(),
|
|
795
|
-
self._var_data,
|
|
796
|
-
)
|
|
797
|
-
|
|
798
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
799
|
-
"""Wrapper method for cached property.
|
|
800
|
-
|
|
801
|
-
Returns:
|
|
802
|
-
The VarData of the components and all of its children.
|
|
803
|
-
"""
|
|
804
|
-
return self._cached_get_all_var_data
|