reflex 0.5.10a3__py3-none-any.whl → 0.6.0a1__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.

Files changed (237) hide show
  1. reflex/.templates/jinja/web/pages/utils.js.jinja2 +4 -4
  2. reflex/.templates/jinja/web/utils/context.js.jinja2 +1 -1
  3. reflex/.templates/jinja/web/utils/theme.js.jinja2 +1 -1
  4. reflex/__init__.py +3 -2
  5. reflex/__init__.pyi +2 -2
  6. reflex/app.py +43 -9
  7. reflex/base.py +3 -2
  8. reflex/compiler/compiler.py +6 -6
  9. reflex/compiler/utils.py +5 -3
  10. reflex/components/base/app_wrap.py +2 -4
  11. reflex/components/base/app_wrap.pyi +17 -17
  12. reflex/components/base/bare.py +7 -4
  13. reflex/components/base/body.pyi +17 -17
  14. reflex/components/base/document.pyi +81 -81
  15. reflex/components/base/error_boundary.py +10 -8
  16. reflex/components/base/error_boundary.pyi +20 -19
  17. reflex/components/base/fragment.pyi +17 -17
  18. reflex/components/base/head.pyi +33 -33
  19. reflex/components/base/link.pyi +34 -33
  20. reflex/components/base/meta.pyi +65 -65
  21. reflex/components/base/script.py +2 -1
  22. reflex/components/base/script.pyi +21 -20
  23. reflex/components/component.py +116 -145
  24. reflex/components/core/banner.py +59 -60
  25. reflex/components/core/banner.pyi +86 -150
  26. reflex/components/core/client_side_routing.py +2 -1
  27. reflex/components/core/client_side_routing.pyi +34 -33
  28. reflex/components/core/clipboard.py +2 -2
  29. reflex/components/core/clipboard.pyi +19 -18
  30. reflex/components/core/cond.py +21 -44
  31. reflex/components/core/debounce.py +6 -8
  32. reflex/components/core/debounce.pyi +19 -18
  33. reflex/components/core/foreach.py +5 -14
  34. reflex/components/core/html.pyi +18 -17
  35. reflex/components/core/match.py +36 -43
  36. reflex/components/core/upload.py +32 -25
  37. reflex/components/core/upload.pyi +84 -73
  38. reflex/components/datadisplay/code.py +55 -28
  39. reflex/components/datadisplay/code.pyi +20 -17
  40. reflex/components/datadisplay/dataeditor.py +17 -11
  41. reflex/components/datadisplay/dataeditor.pyi +34 -33
  42. reflex/components/el/__init__.py +0 -1
  43. reflex/components/el/__init__.pyi +0 -11
  44. reflex/components/el/element.pyi +17 -17
  45. reflex/components/el/elements/__init__.py +1 -7
  46. reflex/components/el/elements/__init__.pyi +1 -15
  47. reflex/components/el/elements/base.pyi +18 -17
  48. reflex/components/el/elements/forms.py +24 -31
  49. reflex/components/el/elements/forms.pyi +237 -236
  50. reflex/components/el/elements/inline.pyi +450 -449
  51. reflex/components/el/elements/media.py +0 -21
  52. reflex/components/el/elements/media.pyi +338 -337
  53. reflex/components/el/elements/metadata.py +3 -2
  54. reflex/components/el/elements/metadata.pyi +98 -97
  55. reflex/components/el/elements/other.pyi +114 -113
  56. reflex/components/el/elements/scripts.pyi +50 -49
  57. reflex/components/el/elements/sectioning.pyi +242 -241
  58. reflex/components/el/elements/tables.pyi +162 -161
  59. reflex/components/el/elements/typography.pyi +242 -241
  60. reflex/components/gridjs/datatable.py +13 -14
  61. reflex/components/gridjs/datatable.pyi +34 -33
  62. reflex/components/lucide/icon.py +2 -126
  63. reflex/components/lucide/icon.pyi +34 -142
  64. reflex/components/markdown/markdown.py +30 -35
  65. reflex/components/markdown/markdown.pyi +29 -32
  66. reflex/components/moment/moment.pyi +19 -18
  67. reflex/components/next/base.pyi +17 -17
  68. reflex/components/next/image.py +0 -4
  69. reflex/components/next/image.pyi +20 -19
  70. reflex/components/next/link.pyi +18 -17
  71. reflex/components/next/video.pyi +18 -17
  72. reflex/components/plotly/plotly.py +16 -28
  73. reflex/components/plotly/plotly.pyi +36 -35
  74. reflex/components/props.py +21 -10
  75. reflex/components/radix/__init__.pyi +1 -1
  76. reflex/components/radix/primitives/__init__.pyi +0 -1
  77. reflex/components/radix/primitives/accordion.py +7 -8
  78. reflex/components/radix/primitives/accordion.pyi +117 -116
  79. reflex/components/radix/primitives/base.pyi +34 -33
  80. reflex/components/radix/primitives/drawer.pyi +169 -168
  81. reflex/components/radix/primitives/form.pyi +168 -167
  82. reflex/components/radix/primitives/progress.pyi +82 -81
  83. reflex/components/radix/primitives/slider.pyi +84 -83
  84. reflex/components/radix/themes/base.py +8 -4
  85. reflex/components/radix/themes/base.pyi +114 -113
  86. reflex/components/radix/themes/color_mode.py +12 -21
  87. reflex/components/radix/themes/color_mode.pyi +67 -67
  88. reflex/components/radix/themes/components/__init__.pyi +1 -0
  89. reflex/components/radix/themes/components/alert_dialog.pyi +118 -117
  90. reflex/components/radix/themes/components/aspect_ratio.pyi +18 -17
  91. reflex/components/radix/themes/components/avatar.pyi +18 -17
  92. reflex/components/radix/themes/components/badge.pyi +18 -17
  93. reflex/components/radix/themes/components/button.pyi +18 -17
  94. reflex/components/radix/themes/components/callout.pyi +82 -81
  95. reflex/components/radix/themes/components/card.pyi +18 -17
  96. reflex/components/radix/themes/components/checkbox.py +2 -3
  97. reflex/components/radix/themes/components/checkbox.pyi +53 -52
  98. reflex/components/radix/themes/components/checkbox_cards.pyi +34 -33
  99. reflex/components/radix/themes/components/checkbox_group.pyi +34 -33
  100. reflex/components/radix/themes/components/context_menu.pyi +140 -139
  101. reflex/components/radix/themes/components/data_list.py +5 -0
  102. reflex/components/radix/themes/components/data_list.pyi +71 -65
  103. reflex/components/radix/themes/components/dialog.pyi +121 -120
  104. reflex/components/radix/themes/components/dropdown_menu.pyi +142 -141
  105. reflex/components/radix/themes/components/hover_card.pyi +68 -67
  106. reflex/components/radix/themes/components/icon_button.py +2 -1
  107. reflex/components/radix/themes/components/icon_button.pyi +18 -17
  108. reflex/components/radix/themes/components/inset.pyi +18 -17
  109. reflex/components/radix/themes/components/popover.pyi +73 -72
  110. reflex/components/radix/themes/components/progress.pyi +18 -17
  111. reflex/components/radix/themes/components/radio.pyi +18 -17
  112. reflex/components/radix/themes/components/radio_cards.pyi +35 -34
  113. reflex/components/radix/themes/components/radio_group.py +35 -31
  114. reflex/components/radix/themes/components/radio_group.pyi +73 -66
  115. reflex/components/radix/themes/components/scroll_area.pyi +18 -17
  116. reflex/components/radix/themes/components/segmented_control.pyi +35 -34
  117. reflex/components/radix/themes/components/select.py +2 -1
  118. reflex/components/radix/themes/components/select.pyi +155 -154
  119. reflex/components/radix/themes/components/separator.py +2 -3
  120. reflex/components/radix/themes/components/separator.pyi +18 -17
  121. reflex/components/radix/themes/components/skeleton.pyi +18 -17
  122. reflex/components/radix/themes/components/slider.py +2 -1
  123. reflex/components/radix/themes/components/slider.pyi +20 -19
  124. reflex/components/radix/themes/components/spinner.pyi +18 -17
  125. reflex/components/radix/themes/components/switch.pyi +19 -18
  126. reflex/components/radix/themes/components/table.pyi +114 -113
  127. reflex/components/radix/themes/components/tabs.pyi +84 -83
  128. reflex/components/radix/themes/components/text_area.pyi +21 -20
  129. reflex/components/radix/themes/components/text_field.py +0 -79
  130. reflex/components/radix/themes/components/text_field.pyi +57 -63
  131. reflex/components/radix/themes/components/tooltip.pyi +21 -20
  132. reflex/components/radix/themes/layout/base.pyi +18 -17
  133. reflex/components/radix/themes/layout/box.pyi +18 -17
  134. reflex/components/radix/themes/layout/center.pyi +18 -17
  135. reflex/components/radix/themes/layout/container.py +2 -3
  136. reflex/components/radix/themes/layout/container.pyi +18 -17
  137. reflex/components/radix/themes/layout/flex.pyi +18 -17
  138. reflex/components/radix/themes/layout/grid.pyi +18 -17
  139. reflex/components/radix/themes/layout/list.py +5 -4
  140. reflex/components/radix/themes/layout/list.pyi +86 -85
  141. reflex/components/radix/themes/layout/section.py +2 -3
  142. reflex/components/radix/themes/layout/section.pyi +18 -17
  143. reflex/components/radix/themes/layout/spacer.pyi +18 -17
  144. reflex/components/radix/themes/layout/stack.pyi +50 -49
  145. reflex/components/radix/themes/typography/blockquote.pyi +18 -17
  146. reflex/components/radix/themes/typography/code.pyi +18 -17
  147. reflex/components/radix/themes/typography/heading.pyi +18 -17
  148. reflex/components/radix/themes/typography/link.pyi +18 -17
  149. reflex/components/radix/themes/typography/text.pyi +114 -113
  150. reflex/components/react_player/audio.pyi +34 -33
  151. reflex/components/react_player/react_player.pyi +34 -33
  152. reflex/components/react_player/video.pyi +34 -33
  153. reflex/components/recharts/cartesian.py +23 -19
  154. reflex/components/recharts/cartesian.pyi +297 -296
  155. reflex/components/recharts/charts.py +6 -5
  156. reflex/components/recharts/charts.pyi +179 -178
  157. reflex/components/recharts/general.py +8 -7
  158. reflex/components/recharts/general.pyi +82 -81
  159. reflex/components/recharts/polar.py +14 -13
  160. reflex/components/recharts/polar.pyi +76 -75
  161. reflex/components/recharts/recharts.pyi +33 -33
  162. reflex/components/sonner/toast.py +30 -33
  163. reflex/components/sonner/toast.pyi +27 -25
  164. reflex/components/suneditor/editor.py +2 -1
  165. reflex/components/suneditor/editor.pyi +27 -26
  166. reflex/components/tags/iter_tag.py +16 -16
  167. reflex/components/tags/tag.py +8 -10
  168. reflex/constants/base.py +3 -1
  169. reflex/constants/event.py +1 -0
  170. reflex/event.py +89 -79
  171. reflex/experimental/__init__.py +25 -6
  172. reflex/experimental/client_state.py +34 -58
  173. reflex/experimental/hooks.py +13 -18
  174. reflex/experimental/layout.py +5 -5
  175. reflex/experimental/layout.pyi +84 -83
  176. reflex/{experimental/vars → ivars}/__init__.py +0 -1
  177. reflex/ivars/base.py +2180 -0
  178. reflex/ivars/function.py +200 -0
  179. reflex/ivars/number.py +1137 -0
  180. reflex/ivars/object.py +564 -0
  181. reflex/ivars/sequence.py +1601 -0
  182. reflex/model.py +22 -0
  183. reflex/reflex.py +4 -0
  184. reflex/state.py +388 -73
  185. reflex/style.py +52 -34
  186. reflex/testing.py +8 -3
  187. reflex/utils/exceptions.py +12 -0
  188. reflex/utils/exec.py +0 -14
  189. reflex/utils/format.py +74 -223
  190. reflex/utils/net.py +43 -0
  191. reflex/utils/path_ops.py +13 -1
  192. reflex/utils/prerequisites.py +46 -26
  193. reflex/utils/pyi_generator.py +5 -4
  194. reflex/utils/serializers.py +13 -31
  195. reflex/utils/types.py +44 -9
  196. reflex/vars.py +127 -2230
  197. {reflex-0.5.10a3.dist-info → reflex-0.6.0a1.dist-info}/METADATA +4 -6
  198. reflex-0.6.0a1.dist-info/RECORD +384 -0
  199. reflex/.templates/apps/demo/.gitignore +0 -4
  200. reflex/.templates/apps/demo/assets/favicon.ico +0 -0
  201. reflex/.templates/apps/demo/assets/github.svg +0 -10
  202. reflex/.templates/apps/demo/assets/icon.svg +0 -37
  203. reflex/.templates/apps/demo/assets/logo.svg +0 -68
  204. reflex/.templates/apps/demo/assets/paneleft.svg +0 -13
  205. reflex/.templates/apps/demo/code/__init__.py +0 -1
  206. reflex/.templates/apps/demo/code/demo.py +0 -127
  207. reflex/.templates/apps/demo/code/pages/__init__.py +0 -7
  208. reflex/.templates/apps/demo/code/pages/chatapp.py +0 -31
  209. reflex/.templates/apps/demo/code/pages/datatable.py +0 -360
  210. reflex/.templates/apps/demo/code/pages/forms.py +0 -257
  211. reflex/.templates/apps/demo/code/pages/graphing.py +0 -253
  212. reflex/.templates/apps/demo/code/pages/home.py +0 -56
  213. reflex/.templates/apps/demo/code/sidebar.py +0 -178
  214. reflex/.templates/apps/demo/code/state.py +0 -22
  215. reflex/.templates/apps/demo/code/states/form_state.py +0 -40
  216. reflex/.templates/apps/demo/code/states/pie_state.py +0 -47
  217. reflex/.templates/apps/demo/code/styles.py +0 -68
  218. reflex/.templates/apps/demo/code/webui/__init__.py +0 -0
  219. reflex/.templates/apps/demo/code/webui/components/__init__.py +0 -4
  220. reflex/.templates/apps/demo/code/webui/components/chat.py +0 -118
  221. reflex/.templates/apps/demo/code/webui/components/loading_icon.py +0 -19
  222. reflex/.templates/apps/demo/code/webui/components/modal.py +0 -56
  223. reflex/.templates/apps/demo/code/webui/components/navbar.py +0 -70
  224. reflex/.templates/apps/demo/code/webui/components/sidebar.py +0 -66
  225. reflex/.templates/apps/demo/code/webui/state.py +0 -146
  226. reflex/.templates/apps/demo/code/webui/styles.py +0 -88
  227. reflex/experimental/vars/base.py +0 -583
  228. reflex/experimental/vars/function.py +0 -290
  229. reflex/experimental/vars/number.py +0 -1458
  230. reflex/experimental/vars/object.py +0 -804
  231. reflex/experimental/vars/sequence.py +0 -1764
  232. reflex/utils/watch.py +0 -96
  233. reflex/vars.pyi +0 -218
  234. reflex-0.5.10a3.dist-info/RECORD +0 -413
  235. {reflex-0.5.10a3.dist-info → reflex-0.6.0a1.dist-info}/LICENSE +0 -0
  236. {reflex-0.5.10a3.dist-info → reflex-0.6.0a1.dist-info}/WHEEL +0 -0
  237. {reflex-0.5.10a3.dist-info → reflex-0.6.0a1.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