evalis 0.2.0__tar.gz → 0.2.1__tar.gz
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.
- {evalis-0.2.0/src/evalis.egg-info → evalis-0.2.1}/PKG-INFO +1 -1
- {evalis-0.2.0 → evalis-0.2.1}/src/evalis/constants.py +1 -1
- {evalis-0.2.0 → evalis-0.2.1}/src/evalis/eval.py +39 -5
- {evalis-0.2.0 → evalis-0.2.1}/src/evalis/utils.py +12 -0
- {evalis-0.2.0 → evalis-0.2.1/src/evalis.egg-info}/PKG-INFO +1 -1
- {evalis-0.2.0 → evalis-0.2.1}/LICENSE +0 -0
- {evalis-0.2.0 → evalis-0.2.1}/MANIFEST.in +0 -0
- {evalis-0.2.0 → evalis-0.2.1}/README.md +0 -0
- {evalis-0.2.0 → evalis-0.2.1}/pyproject.toml +0 -0
- {evalis-0.2.0 → evalis-0.2.1}/setup.cfg +0 -0
- {evalis-0.2.0 → evalis-0.2.1}/src/evalis/__gen__/EvalisLexer.py +0 -0
- {evalis-0.2.0 → evalis-0.2.1}/src/evalis/__gen__/EvalisListener.py +0 -0
- {evalis-0.2.0 → evalis-0.2.1}/src/evalis/__gen__/EvalisParser.py +0 -0
- {evalis-0.2.0 → evalis-0.2.1}/src/evalis/__gen__/EvalisVisitor.py +0 -0
- {evalis-0.2.0 → evalis-0.2.1}/src/evalis/__gen__/grammar.py +0 -0
- {evalis-0.2.0 → evalis-0.2.1}/src/evalis/__init__.py +0 -0
- {evalis-0.2.0 → evalis-0.2.1}/src/evalis/antlr4_adapter.py +0 -0
- {evalis-0.2.0 → evalis-0.2.1}/src/evalis/ast.py +0 -0
- {evalis-0.2.0 → evalis-0.2.1}/src/evalis/error.py +0 -0
- {evalis-0.2.0 → evalis-0.2.1}/src/evalis/evalis.py +0 -0
- {evalis-0.2.0 → evalis-0.2.1}/src/evalis/types.py +0 -0
- {evalis-0.2.0 → evalis-0.2.1}/src/evalis.egg-info/SOURCES.txt +0 -0
- {evalis-0.2.0 → evalis-0.2.1}/src/evalis.egg-info/dependency_links.txt +0 -0
- {evalis-0.2.0 → evalis-0.2.1}/src/evalis.egg-info/requires.txt +0 -0
- {evalis-0.2.0 → evalis-0.2.1}/src/evalis.egg-info/top_level.txt +0 -0
|
@@ -10,7 +10,13 @@ from evalis.ast import (
|
|
|
10
10
|
)
|
|
11
11
|
from evalis.error import EvalisError, CODE_TYPE_ERROR
|
|
12
12
|
from evalis.types import EvaluatorOptions
|
|
13
|
-
from evalis.utils import
|
|
13
|
+
from evalis.utils import (
|
|
14
|
+
as_str,
|
|
15
|
+
is_primitive,
|
|
16
|
+
should_str_concat,
|
|
17
|
+
as_num,
|
|
18
|
+
is_numeric_or_null,
|
|
19
|
+
)
|
|
14
20
|
|
|
15
21
|
|
|
16
22
|
def get_val_from_context(context: Any, key: Any) -> Any:
|
|
@@ -64,13 +70,41 @@ class Evaluator:
|
|
|
64
70
|
case BinaryOpType.EQUALS:
|
|
65
71
|
return left == right
|
|
66
72
|
case BinaryOpType.GT:
|
|
67
|
-
|
|
73
|
+
if is_numeric_or_null(left) and is_numeric_or_null(right):
|
|
74
|
+
return as_num(left) > as_num(right)
|
|
75
|
+
if isinstance(left, str) and isinstance(right, str):
|
|
76
|
+
return left > right
|
|
77
|
+
raise EvalisError(
|
|
78
|
+
f"Cannot use > operator with types {type(left).__name__} and {type(right).__name__}",
|
|
79
|
+
CODE_TYPE_ERROR,
|
|
80
|
+
)
|
|
68
81
|
case BinaryOpType.GTE:
|
|
69
|
-
|
|
82
|
+
if is_numeric_or_null(left) and is_numeric_or_null(right):
|
|
83
|
+
return as_num(left) >= as_num(right)
|
|
84
|
+
if isinstance(left, str) and isinstance(right, str):
|
|
85
|
+
return left >= right
|
|
86
|
+
raise EvalisError(
|
|
87
|
+
f"Cannot use >= operator with types {type(left).__name__} and {type(right).__name__}",
|
|
88
|
+
CODE_TYPE_ERROR,
|
|
89
|
+
)
|
|
70
90
|
case BinaryOpType.LT:
|
|
71
|
-
|
|
91
|
+
if is_numeric_or_null(left) and is_numeric_or_null(right):
|
|
92
|
+
return as_num(left) < as_num(right)
|
|
93
|
+
if isinstance(left, str) and isinstance(right, str):
|
|
94
|
+
return left < right
|
|
95
|
+
raise EvalisError(
|
|
96
|
+
f"Cannot use < operator with types {type(left).__name__} and {type(right).__name__}",
|
|
97
|
+
CODE_TYPE_ERROR,
|
|
98
|
+
)
|
|
72
99
|
case BinaryOpType.LTE:
|
|
73
|
-
|
|
100
|
+
if is_numeric_or_null(left) and is_numeric_or_null(right):
|
|
101
|
+
return as_num(left) <= as_num(right)
|
|
102
|
+
if isinstance(left, str) and isinstance(right, str):
|
|
103
|
+
return left <= right
|
|
104
|
+
raise EvalisError(
|
|
105
|
+
f"Cannot use <= operator with types {type(left).__name__} and {type(right).__name__}",
|
|
106
|
+
CODE_TYPE_ERROR,
|
|
107
|
+
)
|
|
74
108
|
case BinaryOpType.MULTIPLY:
|
|
75
109
|
return left * right
|
|
76
110
|
case BinaryOpType.OR:
|
|
@@ -26,3 +26,15 @@ def as_str(val: Any) -> str:
|
|
|
26
26
|
return ""
|
|
27
27
|
|
|
28
28
|
return str(val)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def is_numeric_or_null(val: Any) -> bool:
|
|
32
|
+
"""Check if a value is numeric or null."""
|
|
33
|
+
return val is None or isinstance(val, (int, float))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def as_num(val: Any) -> Any:
|
|
37
|
+
"""Coerce nullish values to 0 for numeric operations."""
|
|
38
|
+
if val is None:
|
|
39
|
+
return 0
|
|
40
|
+
return val
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|