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,1458 +0,0 @@
|
|
|
1
|
-
"""Immutable number vars."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
import dataclasses
|
|
6
|
-
import json
|
|
7
|
-
import sys
|
|
8
|
-
from functools import cached_property
|
|
9
|
-
from typing import Any, Union
|
|
10
|
-
|
|
11
|
-
from reflex.experimental.vars.base import (
|
|
12
|
-
ImmutableVar,
|
|
13
|
-
LiteralVar,
|
|
14
|
-
)
|
|
15
|
-
from reflex.vars import ImmutableVarData, Var, VarData
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class NumberVar(ImmutableVar[Union[int, float]]):
|
|
19
|
-
"""Base class for immutable number vars."""
|
|
20
|
-
|
|
21
|
-
def __add__(self, other: number_types | boolean_types) -> NumberAddOperation:
|
|
22
|
-
"""Add two numbers.
|
|
23
|
-
|
|
24
|
-
Args:
|
|
25
|
-
other: The other number.
|
|
26
|
-
|
|
27
|
-
Returns:
|
|
28
|
-
The number addition operation.
|
|
29
|
-
"""
|
|
30
|
-
return NumberAddOperation(self, +other)
|
|
31
|
-
|
|
32
|
-
def __radd__(self, other: number_types | boolean_types) -> NumberAddOperation:
|
|
33
|
-
"""Add two numbers.
|
|
34
|
-
|
|
35
|
-
Args:
|
|
36
|
-
other: The other number.
|
|
37
|
-
|
|
38
|
-
Returns:
|
|
39
|
-
The number addition operation.
|
|
40
|
-
"""
|
|
41
|
-
return NumberAddOperation(+other, self)
|
|
42
|
-
|
|
43
|
-
def __sub__(self, other: number_types | boolean_types) -> NumberSubtractOperation:
|
|
44
|
-
"""Subtract two numbers.
|
|
45
|
-
|
|
46
|
-
Args:
|
|
47
|
-
other: The other number.
|
|
48
|
-
|
|
49
|
-
Returns:
|
|
50
|
-
The number subtraction operation.
|
|
51
|
-
"""
|
|
52
|
-
return NumberSubtractOperation(self, +other)
|
|
53
|
-
|
|
54
|
-
def __rsub__(self, other: number_types | boolean_types) -> NumberSubtractOperation:
|
|
55
|
-
"""Subtract two numbers.
|
|
56
|
-
|
|
57
|
-
Args:
|
|
58
|
-
other: The other number.
|
|
59
|
-
|
|
60
|
-
Returns:
|
|
61
|
-
The number subtraction operation.
|
|
62
|
-
"""
|
|
63
|
-
return NumberSubtractOperation(+other, self)
|
|
64
|
-
|
|
65
|
-
def __abs__(self) -> NumberAbsoluteOperation:
|
|
66
|
-
"""Get the absolute value of the number.
|
|
67
|
-
|
|
68
|
-
Returns:
|
|
69
|
-
The number absolute operation.
|
|
70
|
-
"""
|
|
71
|
-
return NumberAbsoluteOperation(self)
|
|
72
|
-
|
|
73
|
-
def __mul__(self, other: number_types | boolean_types) -> NumberMultiplyOperation:
|
|
74
|
-
"""Multiply two numbers.
|
|
75
|
-
|
|
76
|
-
Args:
|
|
77
|
-
other: The other number.
|
|
78
|
-
|
|
79
|
-
Returns:
|
|
80
|
-
The number multiplication operation.
|
|
81
|
-
"""
|
|
82
|
-
return NumberMultiplyOperation(self, +other)
|
|
83
|
-
|
|
84
|
-
def __rmul__(self, other: number_types | boolean_types) -> NumberMultiplyOperation:
|
|
85
|
-
"""Multiply two numbers.
|
|
86
|
-
|
|
87
|
-
Args:
|
|
88
|
-
other: The other number.
|
|
89
|
-
|
|
90
|
-
Returns:
|
|
91
|
-
The number multiplication operation.
|
|
92
|
-
"""
|
|
93
|
-
return NumberMultiplyOperation(+other, self)
|
|
94
|
-
|
|
95
|
-
def __truediv__(self, other: number_types | boolean_types) -> NumberTrueDivision:
|
|
96
|
-
"""Divide two numbers.
|
|
97
|
-
|
|
98
|
-
Args:
|
|
99
|
-
other: The other number.
|
|
100
|
-
|
|
101
|
-
Returns:
|
|
102
|
-
The number true division operation.
|
|
103
|
-
"""
|
|
104
|
-
return NumberTrueDivision(self, +other)
|
|
105
|
-
|
|
106
|
-
def __rtruediv__(self, other: number_types | boolean_types) -> NumberTrueDivision:
|
|
107
|
-
"""Divide two numbers.
|
|
108
|
-
|
|
109
|
-
Args:
|
|
110
|
-
other: The other number.
|
|
111
|
-
|
|
112
|
-
Returns:
|
|
113
|
-
The number true division operation.
|
|
114
|
-
"""
|
|
115
|
-
return NumberTrueDivision(+other, self)
|
|
116
|
-
|
|
117
|
-
def __floordiv__(self, other: number_types | boolean_types) -> NumberFloorDivision:
|
|
118
|
-
"""Floor divide two numbers.
|
|
119
|
-
|
|
120
|
-
Args:
|
|
121
|
-
other: The other number.
|
|
122
|
-
|
|
123
|
-
Returns:
|
|
124
|
-
The number floor division operation.
|
|
125
|
-
"""
|
|
126
|
-
return NumberFloorDivision(self, +other)
|
|
127
|
-
|
|
128
|
-
def __rfloordiv__(self, other: number_types | boolean_types) -> NumberFloorDivision:
|
|
129
|
-
"""Floor divide two numbers.
|
|
130
|
-
|
|
131
|
-
Args:
|
|
132
|
-
other: The other number.
|
|
133
|
-
|
|
134
|
-
Returns:
|
|
135
|
-
The number floor division operation.
|
|
136
|
-
"""
|
|
137
|
-
return NumberFloorDivision(+other, self)
|
|
138
|
-
|
|
139
|
-
def __mod__(self, other: number_types | boolean_types) -> NumberModuloOperation:
|
|
140
|
-
"""Modulo two numbers.
|
|
141
|
-
|
|
142
|
-
Args:
|
|
143
|
-
other: The other number.
|
|
144
|
-
|
|
145
|
-
Returns:
|
|
146
|
-
The number modulo operation.
|
|
147
|
-
"""
|
|
148
|
-
return NumberModuloOperation(self, +other)
|
|
149
|
-
|
|
150
|
-
def __rmod__(self, other: number_types | boolean_types) -> NumberModuloOperation:
|
|
151
|
-
"""Modulo two numbers.
|
|
152
|
-
|
|
153
|
-
Args:
|
|
154
|
-
other: The other number.
|
|
155
|
-
|
|
156
|
-
Returns:
|
|
157
|
-
The number modulo operation.
|
|
158
|
-
"""
|
|
159
|
-
return NumberModuloOperation(+other, self)
|
|
160
|
-
|
|
161
|
-
def __pow__(self, other: number_types | boolean_types) -> NumberExponentOperation:
|
|
162
|
-
"""Exponentiate two numbers.
|
|
163
|
-
|
|
164
|
-
Args:
|
|
165
|
-
other: The other number.
|
|
166
|
-
|
|
167
|
-
Returns:
|
|
168
|
-
The number exponent operation.
|
|
169
|
-
"""
|
|
170
|
-
return NumberExponentOperation(self, +other)
|
|
171
|
-
|
|
172
|
-
def __rpow__(self, other: number_types | boolean_types) -> NumberExponentOperation:
|
|
173
|
-
"""Exponentiate two numbers.
|
|
174
|
-
|
|
175
|
-
Args:
|
|
176
|
-
other: The other number.
|
|
177
|
-
|
|
178
|
-
Returns:
|
|
179
|
-
The number exponent operation.
|
|
180
|
-
"""
|
|
181
|
-
return NumberExponentOperation(+other, self)
|
|
182
|
-
|
|
183
|
-
def __neg__(self) -> NumberNegateOperation:
|
|
184
|
-
"""Negate the number.
|
|
185
|
-
|
|
186
|
-
Returns:
|
|
187
|
-
The number negation operation.
|
|
188
|
-
"""
|
|
189
|
-
return NumberNegateOperation(self)
|
|
190
|
-
|
|
191
|
-
def __and__(self, other: number_types | boolean_types) -> BooleanAndOperation:
|
|
192
|
-
"""Boolean AND two numbers.
|
|
193
|
-
|
|
194
|
-
Args:
|
|
195
|
-
other: The other number.
|
|
196
|
-
|
|
197
|
-
Returns:
|
|
198
|
-
The boolean AND operation.
|
|
199
|
-
"""
|
|
200
|
-
boolified_other = other.bool() if isinstance(other, Var) else bool(other)
|
|
201
|
-
return BooleanAndOperation(self.bool(), boolified_other)
|
|
202
|
-
|
|
203
|
-
def __rand__(self, other: number_types | boolean_types) -> BooleanAndOperation:
|
|
204
|
-
"""Boolean AND two numbers.
|
|
205
|
-
|
|
206
|
-
Args:
|
|
207
|
-
other: The other number.
|
|
208
|
-
|
|
209
|
-
Returns:
|
|
210
|
-
The boolean AND operation.
|
|
211
|
-
"""
|
|
212
|
-
boolified_other = other.bool() if isinstance(other, Var) else bool(other)
|
|
213
|
-
return BooleanAndOperation(boolified_other, self.bool())
|
|
214
|
-
|
|
215
|
-
def __or__(self, other: number_types | boolean_types) -> BooleanOrOperation:
|
|
216
|
-
"""Boolean OR two numbers.
|
|
217
|
-
|
|
218
|
-
Args:
|
|
219
|
-
other: The other number.
|
|
220
|
-
|
|
221
|
-
Returns:
|
|
222
|
-
The boolean OR operation.
|
|
223
|
-
"""
|
|
224
|
-
boolified_other = other.bool() if isinstance(other, Var) else bool(other)
|
|
225
|
-
return BooleanOrOperation(self.bool(), boolified_other)
|
|
226
|
-
|
|
227
|
-
def __ror__(self, other: number_types | boolean_types) -> BooleanOrOperation:
|
|
228
|
-
"""Boolean OR two numbers.
|
|
229
|
-
|
|
230
|
-
Args:
|
|
231
|
-
other: The other number.
|
|
232
|
-
|
|
233
|
-
Returns:
|
|
234
|
-
The boolean OR operation.
|
|
235
|
-
"""
|
|
236
|
-
boolified_other = other.bool() if isinstance(other, Var) else bool(other)
|
|
237
|
-
return BooleanOrOperation(boolified_other, self.bool())
|
|
238
|
-
|
|
239
|
-
def __invert__(self) -> BooleanNotOperation:
|
|
240
|
-
"""Boolean NOT the number.
|
|
241
|
-
|
|
242
|
-
Returns:
|
|
243
|
-
The boolean NOT operation.
|
|
244
|
-
"""
|
|
245
|
-
return BooleanNotOperation(self.bool())
|
|
246
|
-
|
|
247
|
-
def __pos__(self) -> NumberVar:
|
|
248
|
-
"""Positive the number.
|
|
249
|
-
|
|
250
|
-
Returns:
|
|
251
|
-
The number.
|
|
252
|
-
"""
|
|
253
|
-
return self
|
|
254
|
-
|
|
255
|
-
def __round__(self) -> NumberRoundOperation:
|
|
256
|
-
"""Round the number.
|
|
257
|
-
|
|
258
|
-
Returns:
|
|
259
|
-
The number round operation.
|
|
260
|
-
"""
|
|
261
|
-
return NumberRoundOperation(self)
|
|
262
|
-
|
|
263
|
-
def __ceil__(self) -> NumberCeilOperation:
|
|
264
|
-
"""Ceil the number.
|
|
265
|
-
|
|
266
|
-
Returns:
|
|
267
|
-
The number ceil operation.
|
|
268
|
-
"""
|
|
269
|
-
return NumberCeilOperation(self)
|
|
270
|
-
|
|
271
|
-
def __floor__(self) -> NumberFloorOperation:
|
|
272
|
-
"""Floor the number.
|
|
273
|
-
|
|
274
|
-
Returns:
|
|
275
|
-
The number floor operation.
|
|
276
|
-
"""
|
|
277
|
-
return NumberFloorOperation(self)
|
|
278
|
-
|
|
279
|
-
def __trunc__(self) -> NumberTruncOperation:
|
|
280
|
-
"""Trunc the number.
|
|
281
|
-
|
|
282
|
-
Returns:
|
|
283
|
-
The number trunc operation.
|
|
284
|
-
"""
|
|
285
|
-
return NumberTruncOperation(self)
|
|
286
|
-
|
|
287
|
-
def __lt__(self, other: number_types | boolean_types) -> LessThanOperation:
|
|
288
|
-
"""Less than comparison.
|
|
289
|
-
|
|
290
|
-
Args:
|
|
291
|
-
other: The other number.
|
|
292
|
-
|
|
293
|
-
Returns:
|
|
294
|
-
The result of the comparison.
|
|
295
|
-
"""
|
|
296
|
-
return LessThanOperation(self, +other)
|
|
297
|
-
|
|
298
|
-
def __le__(self, other: number_types | boolean_types) -> LessThanOrEqualOperation:
|
|
299
|
-
"""Less than or equal comparison.
|
|
300
|
-
|
|
301
|
-
Args:
|
|
302
|
-
other: The other number.
|
|
303
|
-
|
|
304
|
-
Returns:
|
|
305
|
-
The result of the comparison.
|
|
306
|
-
"""
|
|
307
|
-
return LessThanOrEqualOperation(self, +other)
|
|
308
|
-
|
|
309
|
-
def __eq__(self, other: number_types | boolean_types) -> EqualOperation:
|
|
310
|
-
"""Equal comparison.
|
|
311
|
-
|
|
312
|
-
Args:
|
|
313
|
-
other: The other number.
|
|
314
|
-
|
|
315
|
-
Returns:
|
|
316
|
-
The result of the comparison.
|
|
317
|
-
"""
|
|
318
|
-
return EqualOperation(self, +other)
|
|
319
|
-
|
|
320
|
-
def __ne__(self, other: number_types | boolean_types) -> NotEqualOperation:
|
|
321
|
-
"""Not equal comparison.
|
|
322
|
-
|
|
323
|
-
Args:
|
|
324
|
-
other: The other number.
|
|
325
|
-
|
|
326
|
-
Returns:
|
|
327
|
-
The result of the comparison.
|
|
328
|
-
"""
|
|
329
|
-
return NotEqualOperation(self, +other)
|
|
330
|
-
|
|
331
|
-
def __gt__(self, other: number_types | boolean_types) -> GreaterThanOperation:
|
|
332
|
-
"""Greater than comparison.
|
|
333
|
-
|
|
334
|
-
Args:
|
|
335
|
-
other: The other number.
|
|
336
|
-
|
|
337
|
-
Returns:
|
|
338
|
-
The result of the comparison.
|
|
339
|
-
"""
|
|
340
|
-
return GreaterThanOperation(self, +other)
|
|
341
|
-
|
|
342
|
-
def __ge__(
|
|
343
|
-
self, other: number_types | boolean_types
|
|
344
|
-
) -> GreaterThanOrEqualOperation:
|
|
345
|
-
"""Greater than or equal comparison.
|
|
346
|
-
|
|
347
|
-
Args:
|
|
348
|
-
other: The other number.
|
|
349
|
-
|
|
350
|
-
Returns:
|
|
351
|
-
The result of the comparison.
|
|
352
|
-
"""
|
|
353
|
-
return GreaterThanOrEqualOperation(self, +other)
|
|
354
|
-
|
|
355
|
-
def bool(self) -> NotEqualOperation:
|
|
356
|
-
"""Boolean conversion.
|
|
357
|
-
|
|
358
|
-
Returns:
|
|
359
|
-
The boolean value of the number.
|
|
360
|
-
"""
|
|
361
|
-
return NotEqualOperation(self, 0)
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
@dataclasses.dataclass(
|
|
365
|
-
eq=False,
|
|
366
|
-
frozen=True,
|
|
367
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
368
|
-
)
|
|
369
|
-
class BinaryNumberOperation(NumberVar):
|
|
370
|
-
"""Base class for immutable number vars that are the result of a binary operation."""
|
|
371
|
-
|
|
372
|
-
a: number_types = dataclasses.field(default=0)
|
|
373
|
-
b: number_types = dataclasses.field(default=0)
|
|
374
|
-
|
|
375
|
-
def __init__(
|
|
376
|
-
self,
|
|
377
|
-
a: number_types,
|
|
378
|
-
b: number_types,
|
|
379
|
-
_var_data: VarData | None = None,
|
|
380
|
-
):
|
|
381
|
-
"""Initialize the binary number operation var.
|
|
382
|
-
|
|
383
|
-
Args:
|
|
384
|
-
a: The first number.
|
|
385
|
-
b: The second number.
|
|
386
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
387
|
-
"""
|
|
388
|
-
super(BinaryNumberOperation, self).__init__(
|
|
389
|
-
_var_name="",
|
|
390
|
-
_var_type=float,
|
|
391
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
392
|
-
)
|
|
393
|
-
object.__setattr__(self, "a", a)
|
|
394
|
-
object.__setattr__(self, "b", b)
|
|
395
|
-
object.__delattr__(self, "_var_name")
|
|
396
|
-
|
|
397
|
-
@cached_property
|
|
398
|
-
def _cached_var_name(self) -> str:
|
|
399
|
-
"""The name of the var.
|
|
400
|
-
|
|
401
|
-
Raises:
|
|
402
|
-
NotImplementedError: Must be implemented by subclasses
|
|
403
|
-
"""
|
|
404
|
-
raise NotImplementedError(
|
|
405
|
-
"BinaryNumberOperation must implement _cached_var_name"
|
|
406
|
-
)
|
|
407
|
-
|
|
408
|
-
def __getattr__(self, name: str) -> Any:
|
|
409
|
-
"""Get an attribute of the var.
|
|
410
|
-
|
|
411
|
-
Args:
|
|
412
|
-
name: The name of the attribute.
|
|
413
|
-
|
|
414
|
-
Returns:
|
|
415
|
-
The attribute value.
|
|
416
|
-
"""
|
|
417
|
-
if name == "_var_name":
|
|
418
|
-
return self._cached_var_name
|
|
419
|
-
getattr(super(BinaryNumberOperation, self), name)
|
|
420
|
-
|
|
421
|
-
@cached_property
|
|
422
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
423
|
-
"""Get all VarData associated with the Var.
|
|
424
|
-
|
|
425
|
-
Returns:
|
|
426
|
-
The VarData of the components and all of its children.
|
|
427
|
-
"""
|
|
428
|
-
first_value = self.a if isinstance(self.a, Var) else LiteralNumberVar(self.a)
|
|
429
|
-
second_value = self.b if isinstance(self.b, Var) else LiteralNumberVar(self.b)
|
|
430
|
-
return ImmutableVarData.merge(
|
|
431
|
-
first_value._get_all_var_data(),
|
|
432
|
-
second_value._get_all_var_data(),
|
|
433
|
-
self._var_data,
|
|
434
|
-
)
|
|
435
|
-
|
|
436
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
437
|
-
return self._cached_get_all_var_data
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
@dataclasses.dataclass(
|
|
441
|
-
eq=False,
|
|
442
|
-
frozen=True,
|
|
443
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
444
|
-
)
|
|
445
|
-
class UnaryNumberOperation(NumberVar):
|
|
446
|
-
"""Base class for immutable number vars that are the result of a unary operation."""
|
|
447
|
-
|
|
448
|
-
a: number_types = dataclasses.field(default=0)
|
|
449
|
-
|
|
450
|
-
def __init__(
|
|
451
|
-
self,
|
|
452
|
-
a: number_types,
|
|
453
|
-
_var_data: VarData | None = None,
|
|
454
|
-
):
|
|
455
|
-
"""Initialize the unary number operation var.
|
|
456
|
-
|
|
457
|
-
Args:
|
|
458
|
-
a: The number.
|
|
459
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
460
|
-
"""
|
|
461
|
-
super(UnaryNumberOperation, self).__init__(
|
|
462
|
-
_var_name="",
|
|
463
|
-
_var_type=float,
|
|
464
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
465
|
-
)
|
|
466
|
-
object.__setattr__(self, "a", a)
|
|
467
|
-
object.__delattr__(self, "_var_name")
|
|
468
|
-
|
|
469
|
-
@cached_property
|
|
470
|
-
def _cached_var_name(self) -> str:
|
|
471
|
-
"""The name of the var.
|
|
472
|
-
|
|
473
|
-
Raises:
|
|
474
|
-
NotImplementedError: Must be implemented by subclasses.
|
|
475
|
-
"""
|
|
476
|
-
raise NotImplementedError(
|
|
477
|
-
"UnaryNumberOperation must implement _cached_var_name"
|
|
478
|
-
)
|
|
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(UnaryNumberOperation, 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
|
-
value = self.a if isinstance(self.a, Var) else LiteralNumberVar(self.a)
|
|
501
|
-
return ImmutableVarData.merge(value._get_all_var_data(), self._var_data)
|
|
502
|
-
|
|
503
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
504
|
-
return self._cached_get_all_var_data
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
class NumberAddOperation(BinaryNumberOperation):
|
|
508
|
-
"""Base class for immutable number vars that are the result of an addition operation."""
|
|
509
|
-
|
|
510
|
-
@cached_property
|
|
511
|
-
def _cached_var_name(self) -> str:
|
|
512
|
-
"""The name of the var.
|
|
513
|
-
|
|
514
|
-
Returns:
|
|
515
|
-
The name of the var.
|
|
516
|
-
"""
|
|
517
|
-
first_value = self.a if isinstance(self.a, Var) else LiteralNumberVar(self.a)
|
|
518
|
-
second_value = self.b if isinstance(self.b, Var) else LiteralNumberVar(self.b)
|
|
519
|
-
return f"({str(first_value)} + {str(second_value)})"
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
class NumberSubtractOperation(BinaryNumberOperation):
|
|
523
|
-
"""Base class for immutable number vars that are the result of a subtraction operation."""
|
|
524
|
-
|
|
525
|
-
@cached_property
|
|
526
|
-
def _cached_var_name(self) -> str:
|
|
527
|
-
"""The name of the var.
|
|
528
|
-
|
|
529
|
-
Returns:
|
|
530
|
-
The name of the var.
|
|
531
|
-
"""
|
|
532
|
-
first_value = self.a if isinstance(self.a, Var) else LiteralNumberVar(self.a)
|
|
533
|
-
second_value = self.b if isinstance(self.b, Var) else LiteralNumberVar(self.b)
|
|
534
|
-
return f"({str(first_value)} - {str(second_value)})"
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
class NumberAbsoluteOperation(UnaryNumberOperation):
|
|
538
|
-
"""Base class for immutable number vars that are the result of an absolute operation."""
|
|
539
|
-
|
|
540
|
-
@cached_property
|
|
541
|
-
def _cached_var_name(self) -> str:
|
|
542
|
-
"""The name of the var.
|
|
543
|
-
|
|
544
|
-
Returns:
|
|
545
|
-
The name of the var.
|
|
546
|
-
"""
|
|
547
|
-
value = self.a if isinstance(self.a, Var) else LiteralNumberVar(self.a)
|
|
548
|
-
return f"Math.abs({str(value)})"
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
class NumberMultiplyOperation(BinaryNumberOperation):
|
|
552
|
-
"""Base class for immutable number vars that are the result of a multiplication operation."""
|
|
553
|
-
|
|
554
|
-
@cached_property
|
|
555
|
-
def _cached_var_name(self) -> str:
|
|
556
|
-
"""The name of the var.
|
|
557
|
-
|
|
558
|
-
Returns:
|
|
559
|
-
The name of the var.
|
|
560
|
-
"""
|
|
561
|
-
first_value = self.a if isinstance(self.a, Var) else LiteralNumberVar(self.a)
|
|
562
|
-
second_value = self.b if isinstance(self.b, Var) else LiteralNumberVar(self.b)
|
|
563
|
-
return f"({str(first_value)} * {str(second_value)})"
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
class NumberNegateOperation(UnaryNumberOperation):
|
|
567
|
-
"""Base class for immutable number vars that are the result of a negation operation."""
|
|
568
|
-
|
|
569
|
-
@cached_property
|
|
570
|
-
def _cached_var_name(self) -> str:
|
|
571
|
-
"""The name of the var.
|
|
572
|
-
|
|
573
|
-
Returns:
|
|
574
|
-
The name of the var.
|
|
575
|
-
"""
|
|
576
|
-
value = self.a if isinstance(self.a, Var) else LiteralNumberVar(self.a)
|
|
577
|
-
return f"-({str(value)})"
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
class NumberTrueDivision(BinaryNumberOperation):
|
|
581
|
-
"""Base class for immutable number vars that are the result of a true division operation."""
|
|
582
|
-
|
|
583
|
-
@cached_property
|
|
584
|
-
def _cached_var_name(self) -> str:
|
|
585
|
-
"""The name of the var.
|
|
586
|
-
|
|
587
|
-
Returns:
|
|
588
|
-
The name of the var.
|
|
589
|
-
"""
|
|
590
|
-
first_value = self.a if isinstance(self.a, Var) else LiteralNumberVar(self.a)
|
|
591
|
-
second_value = self.b if isinstance(self.b, Var) else LiteralNumberVar(self.b)
|
|
592
|
-
return f"({str(first_value)} / {str(second_value)})"
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
class NumberFloorDivision(BinaryNumberOperation):
|
|
596
|
-
"""Base class for immutable number vars that are the result of a floor division operation."""
|
|
597
|
-
|
|
598
|
-
@cached_property
|
|
599
|
-
def _cached_var_name(self) -> str:
|
|
600
|
-
"""The name of the var.
|
|
601
|
-
|
|
602
|
-
Returns:
|
|
603
|
-
The name of the var.
|
|
604
|
-
"""
|
|
605
|
-
first_value = self.a if isinstance(self.a, Var) else LiteralNumberVar(self.a)
|
|
606
|
-
second_value = self.b if isinstance(self.b, Var) else LiteralNumberVar(self.b)
|
|
607
|
-
return f"Math.floor({str(first_value)} / {str(second_value)})"
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
class NumberModuloOperation(BinaryNumberOperation):
|
|
611
|
-
"""Base class for immutable number vars that are the result of a modulo operation."""
|
|
612
|
-
|
|
613
|
-
@cached_property
|
|
614
|
-
def _cached_var_name(self) -> str:
|
|
615
|
-
"""The name of the var.
|
|
616
|
-
|
|
617
|
-
Returns:
|
|
618
|
-
The name of the var.
|
|
619
|
-
"""
|
|
620
|
-
first_value = self.a if isinstance(self.a, Var) else LiteralNumberVar(self.a)
|
|
621
|
-
second_value = self.b if isinstance(self.b, Var) else LiteralNumberVar(self.b)
|
|
622
|
-
return f"({str(first_value)} % {str(second_value)})"
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
class NumberExponentOperation(BinaryNumberOperation):
|
|
626
|
-
"""Base class for immutable number vars that are the result of an exponent operation."""
|
|
627
|
-
|
|
628
|
-
@cached_property
|
|
629
|
-
def _cached_var_name(self) -> str:
|
|
630
|
-
"""The name of the var.
|
|
631
|
-
|
|
632
|
-
Returns:
|
|
633
|
-
The name of the var.
|
|
634
|
-
"""
|
|
635
|
-
first_value = self.a if isinstance(self.a, Var) else LiteralNumberVar(self.a)
|
|
636
|
-
second_value = self.b if isinstance(self.b, Var) else LiteralNumberVar(self.b)
|
|
637
|
-
return f"({str(first_value)} ** {str(second_value)})"
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
class NumberRoundOperation(UnaryNumberOperation):
|
|
641
|
-
"""Base class for immutable number vars that are the result of a round operation."""
|
|
642
|
-
|
|
643
|
-
@cached_property
|
|
644
|
-
def _cached_var_name(self) -> str:
|
|
645
|
-
"""The name of the var.
|
|
646
|
-
|
|
647
|
-
Returns:
|
|
648
|
-
The name of the var.
|
|
649
|
-
"""
|
|
650
|
-
value = self.a if isinstance(self.a, Var) else LiteralNumberVar(self.a)
|
|
651
|
-
return f"Math.round({str(value)})"
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
class NumberCeilOperation(UnaryNumberOperation):
|
|
655
|
-
"""Base class for immutable number vars that are the result of a ceil operation."""
|
|
656
|
-
|
|
657
|
-
@cached_property
|
|
658
|
-
def _cached_var_name(self) -> str:
|
|
659
|
-
"""The name of the var.
|
|
660
|
-
|
|
661
|
-
Returns:
|
|
662
|
-
The name of the var.
|
|
663
|
-
"""
|
|
664
|
-
value = self.a if isinstance(self.a, Var) else LiteralNumberVar(self.a)
|
|
665
|
-
return f"Math.ceil({str(value)})"
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
class NumberFloorOperation(UnaryNumberOperation):
|
|
669
|
-
"""Base class for immutable number vars that are the result of a floor operation."""
|
|
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
|
-
value = self.a if isinstance(self.a, Var) else LiteralNumberVar(self.a)
|
|
679
|
-
return f"Math.floor({str(value)})"
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
class NumberTruncOperation(UnaryNumberOperation):
|
|
683
|
-
"""Base class for immutable number vars that are the result of a trunc operation."""
|
|
684
|
-
|
|
685
|
-
@cached_property
|
|
686
|
-
def _cached_var_name(self) -> str:
|
|
687
|
-
"""The name of the var.
|
|
688
|
-
|
|
689
|
-
Returns:
|
|
690
|
-
The name of the var.
|
|
691
|
-
"""
|
|
692
|
-
value = self.a if isinstance(self.a, Var) else LiteralNumberVar(self.a)
|
|
693
|
-
return f"Math.trunc({str(value)})"
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
class BooleanVar(ImmutableVar[bool]):
|
|
697
|
-
"""Base class for immutable boolean vars."""
|
|
698
|
-
|
|
699
|
-
def __and__(self, other: bool) -> BooleanAndOperation:
|
|
700
|
-
"""AND two booleans.
|
|
701
|
-
|
|
702
|
-
Args:
|
|
703
|
-
other: The other boolean.
|
|
704
|
-
|
|
705
|
-
Returns:
|
|
706
|
-
The boolean AND operation.
|
|
707
|
-
"""
|
|
708
|
-
return BooleanAndOperation(self, other)
|
|
709
|
-
|
|
710
|
-
def __rand__(self, other: bool) -> BooleanAndOperation:
|
|
711
|
-
"""AND two booleans.
|
|
712
|
-
|
|
713
|
-
Args:
|
|
714
|
-
other: The other boolean.
|
|
715
|
-
|
|
716
|
-
Returns:
|
|
717
|
-
The boolean AND operation.
|
|
718
|
-
"""
|
|
719
|
-
return BooleanAndOperation(other, self)
|
|
720
|
-
|
|
721
|
-
def __or__(self, other: bool) -> BooleanOrOperation:
|
|
722
|
-
"""OR two booleans.
|
|
723
|
-
|
|
724
|
-
Args:
|
|
725
|
-
other: The other boolean.
|
|
726
|
-
|
|
727
|
-
Returns:
|
|
728
|
-
The boolean OR operation.
|
|
729
|
-
"""
|
|
730
|
-
return BooleanOrOperation(self, other)
|
|
731
|
-
|
|
732
|
-
def __ror__(self, other: bool) -> BooleanOrOperation:
|
|
733
|
-
"""OR two booleans.
|
|
734
|
-
|
|
735
|
-
Args:
|
|
736
|
-
other: The other boolean.
|
|
737
|
-
|
|
738
|
-
Returns:
|
|
739
|
-
The boolean OR operation.
|
|
740
|
-
"""
|
|
741
|
-
return BooleanOrOperation(other, self)
|
|
742
|
-
|
|
743
|
-
def __invert__(self) -> BooleanNotOperation:
|
|
744
|
-
"""NOT the boolean.
|
|
745
|
-
|
|
746
|
-
Returns:
|
|
747
|
-
The boolean NOT operation.
|
|
748
|
-
"""
|
|
749
|
-
return BooleanNotOperation(self)
|
|
750
|
-
|
|
751
|
-
def __int__(self) -> BooleanToIntOperation:
|
|
752
|
-
"""Convert the boolean to an int.
|
|
753
|
-
|
|
754
|
-
Returns:
|
|
755
|
-
The boolean to int operation.
|
|
756
|
-
"""
|
|
757
|
-
return BooleanToIntOperation(self)
|
|
758
|
-
|
|
759
|
-
def __pos__(self) -> BooleanToIntOperation:
|
|
760
|
-
"""Convert the boolean to an int.
|
|
761
|
-
|
|
762
|
-
Returns:
|
|
763
|
-
The boolean to int operation.
|
|
764
|
-
"""
|
|
765
|
-
return BooleanToIntOperation(self)
|
|
766
|
-
|
|
767
|
-
def bool(self) -> BooleanVar:
|
|
768
|
-
"""Boolean conversion.
|
|
769
|
-
|
|
770
|
-
Returns:
|
|
771
|
-
The boolean value of the boolean.
|
|
772
|
-
"""
|
|
773
|
-
return self
|
|
774
|
-
|
|
775
|
-
def __lt__(self, other: boolean_types | number_types) -> LessThanOperation:
|
|
776
|
-
"""Less than comparison.
|
|
777
|
-
|
|
778
|
-
Args:
|
|
779
|
-
other: The other boolean.
|
|
780
|
-
|
|
781
|
-
Returns:
|
|
782
|
-
The result of the comparison.
|
|
783
|
-
"""
|
|
784
|
-
return LessThanOperation(+self, +other)
|
|
785
|
-
|
|
786
|
-
def __le__(self, other: boolean_types | number_types) -> LessThanOrEqualOperation:
|
|
787
|
-
"""Less than or equal comparison.
|
|
788
|
-
|
|
789
|
-
Args:
|
|
790
|
-
other: The other boolean.
|
|
791
|
-
|
|
792
|
-
Returns:
|
|
793
|
-
The result of the comparison.
|
|
794
|
-
"""
|
|
795
|
-
return LessThanOrEqualOperation(+self, +other)
|
|
796
|
-
|
|
797
|
-
def __eq__(self, other: boolean_types | number_types) -> EqualOperation:
|
|
798
|
-
"""Equal comparison.
|
|
799
|
-
|
|
800
|
-
Args:
|
|
801
|
-
other: The other boolean.
|
|
802
|
-
|
|
803
|
-
Returns:
|
|
804
|
-
The result of the comparison.
|
|
805
|
-
"""
|
|
806
|
-
return EqualOperation(+self, +other)
|
|
807
|
-
|
|
808
|
-
def __ne__(self, other: boolean_types | number_types) -> NotEqualOperation:
|
|
809
|
-
"""Not equal comparison.
|
|
810
|
-
|
|
811
|
-
Args:
|
|
812
|
-
other: The other boolean.
|
|
813
|
-
|
|
814
|
-
Returns:
|
|
815
|
-
The result of the comparison.
|
|
816
|
-
"""
|
|
817
|
-
return NotEqualOperation(+self, +other)
|
|
818
|
-
|
|
819
|
-
def __gt__(self, other: boolean_types | number_types) -> GreaterThanOperation:
|
|
820
|
-
"""Greater than comparison.
|
|
821
|
-
|
|
822
|
-
Args:
|
|
823
|
-
other: The other boolean.
|
|
824
|
-
|
|
825
|
-
Returns:
|
|
826
|
-
The result of the comparison.
|
|
827
|
-
"""
|
|
828
|
-
return GreaterThanOperation(+self, +other)
|
|
829
|
-
|
|
830
|
-
def __ge__(
|
|
831
|
-
self, other: boolean_types | number_types
|
|
832
|
-
) -> GreaterThanOrEqualOperation:
|
|
833
|
-
"""Greater than or equal comparison.
|
|
834
|
-
|
|
835
|
-
Args:
|
|
836
|
-
other: The other boolean.
|
|
837
|
-
|
|
838
|
-
Returns:
|
|
839
|
-
The result of the comparison.
|
|
840
|
-
"""
|
|
841
|
-
return GreaterThanOrEqualOperation(+self, +other)
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
@dataclasses.dataclass(
|
|
845
|
-
eq=False,
|
|
846
|
-
frozen=True,
|
|
847
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
848
|
-
)
|
|
849
|
-
class BooleanToIntOperation(NumberVar):
|
|
850
|
-
"""Base class for immutable number vars that are the result of a boolean to int operation."""
|
|
851
|
-
|
|
852
|
-
a: boolean_types = dataclasses.field(default=False)
|
|
853
|
-
|
|
854
|
-
def __init__(
|
|
855
|
-
self,
|
|
856
|
-
a: boolean_types,
|
|
857
|
-
_var_data: VarData | None = None,
|
|
858
|
-
):
|
|
859
|
-
"""Initialize the boolean to int operation var.
|
|
860
|
-
|
|
861
|
-
Args:
|
|
862
|
-
a: The boolean.
|
|
863
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
864
|
-
"""
|
|
865
|
-
super(BooleanToIntOperation, self).__init__(
|
|
866
|
-
_var_name="",
|
|
867
|
-
_var_type=int,
|
|
868
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
869
|
-
)
|
|
870
|
-
object.__setattr__(self, "a", a)
|
|
871
|
-
object.__delattr__(self, "_var_name")
|
|
872
|
-
|
|
873
|
-
@cached_property
|
|
874
|
-
def _cached_var_name(self) -> str:
|
|
875
|
-
"""The name of the var.
|
|
876
|
-
|
|
877
|
-
Returns:
|
|
878
|
-
The name of the var.
|
|
879
|
-
"""
|
|
880
|
-
return f"({str(self.a)} ? 1 : 0)"
|
|
881
|
-
|
|
882
|
-
def __getattr__(self, name: str) -> Any:
|
|
883
|
-
"""Get an attribute of the var.
|
|
884
|
-
|
|
885
|
-
Args:
|
|
886
|
-
name: The name of the attribute.
|
|
887
|
-
|
|
888
|
-
Returns:
|
|
889
|
-
The attribute value.
|
|
890
|
-
"""
|
|
891
|
-
if name == "_var_name":
|
|
892
|
-
return self._cached_var_name
|
|
893
|
-
getattr(super(BooleanToIntOperation, self), name)
|
|
894
|
-
|
|
895
|
-
@cached_property
|
|
896
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
897
|
-
"""Get all VarData associated with the Var.
|
|
898
|
-
|
|
899
|
-
Returns:
|
|
900
|
-
The VarData of the components and all of its children.
|
|
901
|
-
"""
|
|
902
|
-
return ImmutableVarData.merge(
|
|
903
|
-
self.a._get_all_var_data() if isinstance(self.a, Var) else None,
|
|
904
|
-
self._var_data,
|
|
905
|
-
)
|
|
906
|
-
|
|
907
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
908
|
-
return self._cached_get_all_var_data
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
@dataclasses.dataclass(
|
|
912
|
-
eq=False,
|
|
913
|
-
frozen=True,
|
|
914
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
915
|
-
)
|
|
916
|
-
class NumberComparisonOperation(BooleanVar):
|
|
917
|
-
"""Base class for immutable boolean vars that are the result of a comparison operation."""
|
|
918
|
-
|
|
919
|
-
a: number_types = dataclasses.field(default=0)
|
|
920
|
-
b: number_types = dataclasses.field(default=0)
|
|
921
|
-
|
|
922
|
-
def __init__(
|
|
923
|
-
self,
|
|
924
|
-
a: number_types,
|
|
925
|
-
b: number_types,
|
|
926
|
-
_var_data: VarData | None = None,
|
|
927
|
-
):
|
|
928
|
-
"""Initialize the comparison operation var.
|
|
929
|
-
|
|
930
|
-
Args:
|
|
931
|
-
a: The first value.
|
|
932
|
-
b: The second value.
|
|
933
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
934
|
-
"""
|
|
935
|
-
super(NumberComparisonOperation, self).__init__(
|
|
936
|
-
_var_name="",
|
|
937
|
-
_var_type=bool,
|
|
938
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
939
|
-
)
|
|
940
|
-
object.__setattr__(self, "a", a)
|
|
941
|
-
object.__setattr__(self, "b", b)
|
|
942
|
-
object.__delattr__(self, "_var_name")
|
|
943
|
-
|
|
944
|
-
@cached_property
|
|
945
|
-
def _cached_var_name(self) -> str:
|
|
946
|
-
"""The name of the var.
|
|
947
|
-
|
|
948
|
-
Raises:
|
|
949
|
-
NotImplementedError: Must be implemented by subclasses.
|
|
950
|
-
"""
|
|
951
|
-
raise NotImplementedError("ComparisonOperation must implement _cached_var_name")
|
|
952
|
-
|
|
953
|
-
def __getattr__(self, name: str) -> Any:
|
|
954
|
-
"""Get an attribute of the var.
|
|
955
|
-
|
|
956
|
-
Args:
|
|
957
|
-
name: The name of the attribute.
|
|
958
|
-
|
|
959
|
-
Returns:
|
|
960
|
-
The attribute value.
|
|
961
|
-
"""
|
|
962
|
-
if name == "_var_name":
|
|
963
|
-
return self._cached_var_name
|
|
964
|
-
getattr(super(NumberComparisonOperation, self), name)
|
|
965
|
-
|
|
966
|
-
@cached_property
|
|
967
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
968
|
-
"""Get all VarData associated with the Var.
|
|
969
|
-
|
|
970
|
-
Returns:
|
|
971
|
-
The VarData of the components and all of its children.
|
|
972
|
-
"""
|
|
973
|
-
first_value = self.a if isinstance(self.a, Var) else LiteralVar.create(self.a)
|
|
974
|
-
second_value = self.b if isinstance(self.b, Var) else LiteralVar.create(self.b)
|
|
975
|
-
return ImmutableVarData.merge(
|
|
976
|
-
first_value._get_all_var_data(), second_value._get_all_var_data()
|
|
977
|
-
)
|
|
978
|
-
|
|
979
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
980
|
-
return self._cached_get_all_var_data
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
class GreaterThanOperation(NumberComparisonOperation):
|
|
984
|
-
"""Base class for immutable boolean vars that are the result of a greater than operation."""
|
|
985
|
-
|
|
986
|
-
@cached_property
|
|
987
|
-
def _cached_var_name(self) -> str:
|
|
988
|
-
"""The name of the var.
|
|
989
|
-
|
|
990
|
-
Returns:
|
|
991
|
-
The name of the var.
|
|
992
|
-
"""
|
|
993
|
-
first_value = self.a if isinstance(self.a, Var) else LiteralVar.create(self.a)
|
|
994
|
-
second_value = self.b if isinstance(self.b, Var) else LiteralVar.create(self.b)
|
|
995
|
-
return f"({str(first_value)} > {str(second_value)})"
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
class GreaterThanOrEqualOperation(NumberComparisonOperation):
|
|
999
|
-
"""Base class for immutable boolean vars that are the result of a greater than or equal operation."""
|
|
1000
|
-
|
|
1001
|
-
@cached_property
|
|
1002
|
-
def _cached_var_name(self) -> str:
|
|
1003
|
-
"""The name of the var.
|
|
1004
|
-
|
|
1005
|
-
Returns:
|
|
1006
|
-
The name of the var.
|
|
1007
|
-
"""
|
|
1008
|
-
first_value = self.a if isinstance(self.a, Var) else LiteralVar.create(self.a)
|
|
1009
|
-
second_value = self.b if isinstance(self.b, Var) else LiteralVar.create(self.b)
|
|
1010
|
-
return f"({str(first_value)} >= {str(second_value)})"
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
class LessThanOperation(NumberComparisonOperation):
|
|
1014
|
-
"""Base class for immutable boolean vars that are the result of a less than operation."""
|
|
1015
|
-
|
|
1016
|
-
@cached_property
|
|
1017
|
-
def _cached_var_name(self) -> str:
|
|
1018
|
-
"""The name of the var.
|
|
1019
|
-
|
|
1020
|
-
Returns:
|
|
1021
|
-
The name of the var.
|
|
1022
|
-
"""
|
|
1023
|
-
first_value = self.a if isinstance(self.a, Var) else LiteralVar.create(self.a)
|
|
1024
|
-
second_value = self.b if isinstance(self.b, Var) else LiteralVar.create(self.b)
|
|
1025
|
-
return f"({str(first_value)} < {str(second_value)})"
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
class LessThanOrEqualOperation(NumberComparisonOperation):
|
|
1029
|
-
"""Base class for immutable boolean vars that are the result of a less than or equal operation."""
|
|
1030
|
-
|
|
1031
|
-
@cached_property
|
|
1032
|
-
def _cached_var_name(self) -> str:
|
|
1033
|
-
"""The name of the var.
|
|
1034
|
-
|
|
1035
|
-
Returns:
|
|
1036
|
-
The name of the var.
|
|
1037
|
-
"""
|
|
1038
|
-
first_value = self.a if isinstance(self.a, Var) else LiteralVar.create(self.a)
|
|
1039
|
-
second_value = self.b if isinstance(self.b, Var) else LiteralVar.create(self.b)
|
|
1040
|
-
return f"({str(first_value)} <= {str(second_value)})"
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
class EqualOperation(NumberComparisonOperation):
|
|
1044
|
-
"""Base class for immutable boolean vars that are the result of an equal operation."""
|
|
1045
|
-
|
|
1046
|
-
@cached_property
|
|
1047
|
-
def _cached_var_name(self) -> str:
|
|
1048
|
-
"""The name of the var.
|
|
1049
|
-
|
|
1050
|
-
Returns:
|
|
1051
|
-
The name of the var.
|
|
1052
|
-
"""
|
|
1053
|
-
first_value = self.a if isinstance(self.a, Var) else LiteralVar.create(self.a)
|
|
1054
|
-
second_value = self.b if isinstance(self.b, Var) else LiteralVar.create(self.b)
|
|
1055
|
-
return f"({str(first_value)} == {str(second_value)})"
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
class NotEqualOperation(NumberComparisonOperation):
|
|
1059
|
-
"""Base class for immutable boolean vars that are the result of a not equal operation."""
|
|
1060
|
-
|
|
1061
|
-
@cached_property
|
|
1062
|
-
def _cached_var_name(self) -> str:
|
|
1063
|
-
"""The name of the var.
|
|
1064
|
-
|
|
1065
|
-
Returns:
|
|
1066
|
-
The name of the var.
|
|
1067
|
-
"""
|
|
1068
|
-
first_value = self.a if isinstance(self.a, Var) else LiteralVar.create(self.a)
|
|
1069
|
-
second_value = self.b if isinstance(self.b, Var) else LiteralVar.create(self.b)
|
|
1070
|
-
return f"({str(first_value)} != {str(second_value)})"
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
@dataclasses.dataclass(
|
|
1074
|
-
eq=False,
|
|
1075
|
-
frozen=True,
|
|
1076
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
1077
|
-
)
|
|
1078
|
-
class LogicalOperation(BooleanVar):
|
|
1079
|
-
"""Base class for immutable boolean vars that are the result of a logical operation."""
|
|
1080
|
-
|
|
1081
|
-
a: boolean_types = dataclasses.field(default=False)
|
|
1082
|
-
b: boolean_types = dataclasses.field(default=False)
|
|
1083
|
-
|
|
1084
|
-
def __init__(
|
|
1085
|
-
self, a: boolean_types, b: boolean_types, _var_data: VarData | None = None
|
|
1086
|
-
):
|
|
1087
|
-
"""Initialize the logical operation var.
|
|
1088
|
-
|
|
1089
|
-
Args:
|
|
1090
|
-
a: The first value.
|
|
1091
|
-
b: The second value.
|
|
1092
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
1093
|
-
"""
|
|
1094
|
-
super(LogicalOperation, self).__init__(
|
|
1095
|
-
_var_name="",
|
|
1096
|
-
_var_type=bool,
|
|
1097
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
1098
|
-
)
|
|
1099
|
-
object.__setattr__(self, "a", a)
|
|
1100
|
-
object.__setattr__(self, "b", b)
|
|
1101
|
-
object.__delattr__(self, "_var_name")
|
|
1102
|
-
|
|
1103
|
-
@cached_property
|
|
1104
|
-
def _cached_var_name(self) -> str:
|
|
1105
|
-
"""The name of the var.
|
|
1106
|
-
|
|
1107
|
-
Raises:
|
|
1108
|
-
NotImplementedError: Must be implemented by subclasses.
|
|
1109
|
-
"""
|
|
1110
|
-
raise NotImplementedError("LogicalOperation must implement _cached_var_name")
|
|
1111
|
-
|
|
1112
|
-
def __getattr__(self, name: str) -> Any:
|
|
1113
|
-
"""Get an attribute of the var.
|
|
1114
|
-
|
|
1115
|
-
Args:
|
|
1116
|
-
name: The name of the attribute.
|
|
1117
|
-
|
|
1118
|
-
Returns:
|
|
1119
|
-
The attribute value.
|
|
1120
|
-
"""
|
|
1121
|
-
if name == "_var_name":
|
|
1122
|
-
return self._cached_var_name
|
|
1123
|
-
getattr(super(LogicalOperation, self), name)
|
|
1124
|
-
|
|
1125
|
-
@cached_property
|
|
1126
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
1127
|
-
"""Get all VarData associated with the Var.
|
|
1128
|
-
|
|
1129
|
-
Returns:
|
|
1130
|
-
The VarData of the components and all of its children.
|
|
1131
|
-
"""
|
|
1132
|
-
first_value = self.a if isinstance(self.a, Var) else LiteralVar.create(self.a)
|
|
1133
|
-
second_value = self.b if isinstance(self.b, Var) else LiteralVar.create(self.b)
|
|
1134
|
-
return ImmutableVarData.merge(
|
|
1135
|
-
first_value._get_all_var_data(), second_value._get_all_var_data()
|
|
1136
|
-
)
|
|
1137
|
-
|
|
1138
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
1139
|
-
return self._cached_get_all_var_data
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
class BooleanAndOperation(LogicalOperation):
|
|
1143
|
-
"""Base class for immutable boolean vars that are the result of a logical AND operation."""
|
|
1144
|
-
|
|
1145
|
-
@cached_property
|
|
1146
|
-
def _cached_var_name(self) -> str:
|
|
1147
|
-
"""The name of the var.
|
|
1148
|
-
|
|
1149
|
-
Returns:
|
|
1150
|
-
The name of the var.
|
|
1151
|
-
"""
|
|
1152
|
-
first_value = self.a if isinstance(self.a, Var) else LiteralVar.create(self.a)
|
|
1153
|
-
second_value = self.b if isinstance(self.b, Var) else LiteralVar.create(self.b)
|
|
1154
|
-
return f"({str(first_value)} && {str(second_value)})"
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
class BooleanOrOperation(LogicalOperation):
|
|
1158
|
-
"""Base class for immutable boolean vars that are the result of a logical OR operation."""
|
|
1159
|
-
|
|
1160
|
-
@cached_property
|
|
1161
|
-
def _cached_var_name(self) -> str:
|
|
1162
|
-
"""The name of the var.
|
|
1163
|
-
|
|
1164
|
-
Returns:
|
|
1165
|
-
The name of the var.
|
|
1166
|
-
"""
|
|
1167
|
-
first_value = self.a if isinstance(self.a, Var) else LiteralVar.create(self.a)
|
|
1168
|
-
second_value = self.b if isinstance(self.b, Var) else LiteralVar.create(self.b)
|
|
1169
|
-
return f"({str(first_value)} || {str(second_value)})"
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
class BooleanNotOperation(BooleanVar):
|
|
1173
|
-
"""Base class for immutable boolean vars that are the result of a logical NOT operation."""
|
|
1174
|
-
|
|
1175
|
-
a: boolean_types = dataclasses.field()
|
|
1176
|
-
|
|
1177
|
-
def __init__(self, a: boolean_types, _var_data: VarData | None = None):
|
|
1178
|
-
"""Initialize the logical NOT operation var.
|
|
1179
|
-
|
|
1180
|
-
Args:
|
|
1181
|
-
a: The value.
|
|
1182
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
1183
|
-
"""
|
|
1184
|
-
super(BooleanNotOperation, self).__init__(
|
|
1185
|
-
_var_name="",
|
|
1186
|
-
_var_type=bool,
|
|
1187
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
1188
|
-
)
|
|
1189
|
-
object.__setattr__(self, "a", a)
|
|
1190
|
-
object.__delattr__(self, "_var_name")
|
|
1191
|
-
|
|
1192
|
-
@cached_property
|
|
1193
|
-
def _cached_var_name(self) -> str:
|
|
1194
|
-
"""The name of the var.
|
|
1195
|
-
|
|
1196
|
-
Returns:
|
|
1197
|
-
The name of the var.
|
|
1198
|
-
"""
|
|
1199
|
-
value = self.a if isinstance(self.a, Var) else LiteralVar.create(self.a)
|
|
1200
|
-
return f"!({str(value)})"
|
|
1201
|
-
|
|
1202
|
-
def __getattr__(self, name: str) -> Any:
|
|
1203
|
-
"""Get an attribute of the var.
|
|
1204
|
-
|
|
1205
|
-
Args:
|
|
1206
|
-
name: The name of the attribute.
|
|
1207
|
-
|
|
1208
|
-
Returns:
|
|
1209
|
-
The attribute value.
|
|
1210
|
-
"""
|
|
1211
|
-
if name == "_var_name":
|
|
1212
|
-
return self._cached_var_name
|
|
1213
|
-
getattr(super(BooleanNotOperation, self), name)
|
|
1214
|
-
|
|
1215
|
-
@cached_property
|
|
1216
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
1217
|
-
"""Get all VarData associated with the Var.
|
|
1218
|
-
|
|
1219
|
-
Returns:
|
|
1220
|
-
The VarData of the components and all of its children.
|
|
1221
|
-
"""
|
|
1222
|
-
value = self.a if isinstance(self.a, Var) else LiteralVar.create(self.a)
|
|
1223
|
-
return ImmutableVarData.merge(value._get_all_var_data())
|
|
1224
|
-
|
|
1225
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
1226
|
-
return self._cached_get_all_var_data
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
@dataclasses.dataclass(
|
|
1230
|
-
eq=False,
|
|
1231
|
-
frozen=True,
|
|
1232
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
1233
|
-
)
|
|
1234
|
-
class LiteralBooleanVar(LiteralVar, BooleanVar):
|
|
1235
|
-
"""Base class for immutable literal boolean vars."""
|
|
1236
|
-
|
|
1237
|
-
_var_value: bool = dataclasses.field(default=False)
|
|
1238
|
-
|
|
1239
|
-
def __init__(
|
|
1240
|
-
self,
|
|
1241
|
-
_var_value: bool,
|
|
1242
|
-
_var_data: VarData | None = None,
|
|
1243
|
-
):
|
|
1244
|
-
"""Initialize the boolean var.
|
|
1245
|
-
|
|
1246
|
-
Args:
|
|
1247
|
-
_var_value: The value of the var.
|
|
1248
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
1249
|
-
"""
|
|
1250
|
-
super(LiteralBooleanVar, self).__init__(
|
|
1251
|
-
_var_name="true" if _var_value else "false",
|
|
1252
|
-
_var_type=bool,
|
|
1253
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
1254
|
-
)
|
|
1255
|
-
object.__setattr__(self, "_var_value", _var_value)
|
|
1256
|
-
|
|
1257
|
-
def __hash__(self) -> int:
|
|
1258
|
-
"""Hash the var.
|
|
1259
|
-
|
|
1260
|
-
Returns:
|
|
1261
|
-
The hash of the var.
|
|
1262
|
-
"""
|
|
1263
|
-
return hash((self.__class__.__name__, self._var_value))
|
|
1264
|
-
|
|
1265
|
-
def json(self) -> str:
|
|
1266
|
-
"""Get the JSON representation of the var.
|
|
1267
|
-
|
|
1268
|
-
Returns:
|
|
1269
|
-
The JSON representation of the var.
|
|
1270
|
-
"""
|
|
1271
|
-
return "true" if self._var_value else "false"
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
@dataclasses.dataclass(
|
|
1275
|
-
eq=False,
|
|
1276
|
-
frozen=True,
|
|
1277
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
1278
|
-
)
|
|
1279
|
-
class LiteralNumberVar(LiteralVar, NumberVar):
|
|
1280
|
-
"""Base class for immutable literal number vars."""
|
|
1281
|
-
|
|
1282
|
-
_var_value: float | int = dataclasses.field(default=0)
|
|
1283
|
-
|
|
1284
|
-
def __init__(
|
|
1285
|
-
self,
|
|
1286
|
-
_var_value: float | int,
|
|
1287
|
-
_var_data: VarData | None = None,
|
|
1288
|
-
):
|
|
1289
|
-
"""Initialize the number var.
|
|
1290
|
-
|
|
1291
|
-
Args:
|
|
1292
|
-
_var_value: The value of the var.
|
|
1293
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
1294
|
-
"""
|
|
1295
|
-
super(LiteralNumberVar, self).__init__(
|
|
1296
|
-
_var_name=str(_var_value),
|
|
1297
|
-
_var_type=type(_var_value),
|
|
1298
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
1299
|
-
)
|
|
1300
|
-
object.__setattr__(self, "_var_value", _var_value)
|
|
1301
|
-
|
|
1302
|
-
def __hash__(self) -> int:
|
|
1303
|
-
"""Hash the var.
|
|
1304
|
-
|
|
1305
|
-
Returns:
|
|
1306
|
-
The hash of the var.
|
|
1307
|
-
"""
|
|
1308
|
-
return hash((self.__class__.__name__, self._var_value))
|
|
1309
|
-
|
|
1310
|
-
def json(self) -> str:
|
|
1311
|
-
"""Get the JSON representation of the var.
|
|
1312
|
-
|
|
1313
|
-
Returns:
|
|
1314
|
-
The JSON representation of the var.
|
|
1315
|
-
"""
|
|
1316
|
-
return json.dumps(self._var_value)
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
number_types = Union[NumberVar, LiteralNumberVar, int, float]
|
|
1320
|
-
boolean_types = Union[BooleanVar, LiteralBooleanVar, bool]
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
@dataclasses.dataclass(
|
|
1324
|
-
eq=False,
|
|
1325
|
-
frozen=True,
|
|
1326
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
1327
|
-
)
|
|
1328
|
-
class ToNumberVarOperation(NumberVar):
|
|
1329
|
-
"""Base class for immutable number vars that are the result of a number operation."""
|
|
1330
|
-
|
|
1331
|
-
_original_value: Var = dataclasses.field(
|
|
1332
|
-
default_factory=lambda: LiteralNumberVar(0)
|
|
1333
|
-
)
|
|
1334
|
-
|
|
1335
|
-
def __init__(
|
|
1336
|
-
self,
|
|
1337
|
-
_original_value: Var,
|
|
1338
|
-
_var_type: type[int] | type[float] = float,
|
|
1339
|
-
_var_data: VarData | None = None,
|
|
1340
|
-
):
|
|
1341
|
-
"""Initialize the number var.
|
|
1342
|
-
|
|
1343
|
-
Args:
|
|
1344
|
-
_original_value: The original value.
|
|
1345
|
-
_var_type: The type of the Var.
|
|
1346
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
1347
|
-
"""
|
|
1348
|
-
super(ToNumberVarOperation, self).__init__(
|
|
1349
|
-
_var_name="",
|
|
1350
|
-
_var_type=_var_type,
|
|
1351
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
1352
|
-
)
|
|
1353
|
-
object.__setattr__(self, "_original_value", _original_value)
|
|
1354
|
-
object.__delattr__(self, "_var_name")
|
|
1355
|
-
|
|
1356
|
-
@cached_property
|
|
1357
|
-
def _cached_var_name(self) -> str:
|
|
1358
|
-
"""The name of the var.
|
|
1359
|
-
|
|
1360
|
-
Returns:
|
|
1361
|
-
The name of the var.
|
|
1362
|
-
"""
|
|
1363
|
-
return str(self._original_value)
|
|
1364
|
-
|
|
1365
|
-
def __getattr__(self, name: str) -> Any:
|
|
1366
|
-
"""Get an attribute of the var.
|
|
1367
|
-
|
|
1368
|
-
Args:
|
|
1369
|
-
name: The name of the attribute.
|
|
1370
|
-
|
|
1371
|
-
Returns:
|
|
1372
|
-
The attribute value.
|
|
1373
|
-
"""
|
|
1374
|
-
if name == "_var_name":
|
|
1375
|
-
return self._cached_var_name
|
|
1376
|
-
getattr(super(ToNumberVarOperation, self), name)
|
|
1377
|
-
|
|
1378
|
-
@cached_property
|
|
1379
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
1380
|
-
"""Get all VarData associated with the Var.
|
|
1381
|
-
|
|
1382
|
-
Returns:
|
|
1383
|
-
The VarData of the components and all of its children.
|
|
1384
|
-
"""
|
|
1385
|
-
return ImmutableVarData.merge(
|
|
1386
|
-
self._original_value._get_all_var_data(), self._var_data
|
|
1387
|
-
)
|
|
1388
|
-
|
|
1389
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
1390
|
-
return self._cached_get_all_var_data
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
@dataclasses.dataclass(
|
|
1394
|
-
eq=False,
|
|
1395
|
-
frozen=True,
|
|
1396
|
-
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
1397
|
-
)
|
|
1398
|
-
class ToBooleanVarOperation(BooleanVar):
|
|
1399
|
-
"""Base class for immutable boolean vars that are the result of a boolean operation."""
|
|
1400
|
-
|
|
1401
|
-
_original_value: Var = dataclasses.field(
|
|
1402
|
-
default_factory=lambda: LiteralBooleanVar(False)
|
|
1403
|
-
)
|
|
1404
|
-
|
|
1405
|
-
def __init__(
|
|
1406
|
-
self,
|
|
1407
|
-
_original_value: Var,
|
|
1408
|
-
_var_data: VarData | None = None,
|
|
1409
|
-
):
|
|
1410
|
-
"""Initialize the boolean var.
|
|
1411
|
-
|
|
1412
|
-
Args:
|
|
1413
|
-
_original_value: The original value.
|
|
1414
|
-
_var_data: Additional hooks and imports associated with the Var.
|
|
1415
|
-
"""
|
|
1416
|
-
super(ToBooleanVarOperation, self).__init__(
|
|
1417
|
-
_var_name="",
|
|
1418
|
-
_var_type=bool,
|
|
1419
|
-
_var_data=ImmutableVarData.merge(_var_data),
|
|
1420
|
-
)
|
|
1421
|
-
object.__setattr__(self, "_original_value", _original_value)
|
|
1422
|
-
object.__delattr__(self, "_var_name")
|
|
1423
|
-
|
|
1424
|
-
@cached_property
|
|
1425
|
-
def _cached_var_name(self) -> str:
|
|
1426
|
-
"""The name of the var.
|
|
1427
|
-
|
|
1428
|
-
Returns:
|
|
1429
|
-
The name of the var.
|
|
1430
|
-
"""
|
|
1431
|
-
return str(self._original_value)
|
|
1432
|
-
|
|
1433
|
-
def __getattr__(self, name: str) -> Any:
|
|
1434
|
-
"""Get an attribute of the var.
|
|
1435
|
-
|
|
1436
|
-
Args:
|
|
1437
|
-
name: The name of the attribute.
|
|
1438
|
-
|
|
1439
|
-
Returns:
|
|
1440
|
-
The attribute value.
|
|
1441
|
-
"""
|
|
1442
|
-
if name == "_var_name":
|
|
1443
|
-
return self._cached_var_name
|
|
1444
|
-
getattr(super(ToBooleanVarOperation, self), name)
|
|
1445
|
-
|
|
1446
|
-
@cached_property
|
|
1447
|
-
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
1448
|
-
"""Get all VarData associated with the Var.
|
|
1449
|
-
|
|
1450
|
-
Returns:
|
|
1451
|
-
The VarData of the components and all of its children.
|
|
1452
|
-
"""
|
|
1453
|
-
return ImmutableVarData.merge(
|
|
1454
|
-
self._original_value._get_all_var_data(), self._var_data
|
|
1455
|
-
)
|
|
1456
|
-
|
|
1457
|
-
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
1458
|
-
return self._cached_get_all_var_data
|