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.
Files changed (25) hide show
  1. {evalis-0.2.0/src/evalis.egg-info → evalis-0.2.1}/PKG-INFO +1 -1
  2. {evalis-0.2.0 → evalis-0.2.1}/src/evalis/constants.py +1 -1
  3. {evalis-0.2.0 → evalis-0.2.1}/src/evalis/eval.py +39 -5
  4. {evalis-0.2.0 → evalis-0.2.1}/src/evalis/utils.py +12 -0
  5. {evalis-0.2.0 → evalis-0.2.1/src/evalis.egg-info}/PKG-INFO +1 -1
  6. {evalis-0.2.0 → evalis-0.2.1}/LICENSE +0 -0
  7. {evalis-0.2.0 → evalis-0.2.1}/MANIFEST.in +0 -0
  8. {evalis-0.2.0 → evalis-0.2.1}/README.md +0 -0
  9. {evalis-0.2.0 → evalis-0.2.1}/pyproject.toml +0 -0
  10. {evalis-0.2.0 → evalis-0.2.1}/setup.cfg +0 -0
  11. {evalis-0.2.0 → evalis-0.2.1}/src/evalis/__gen__/EvalisLexer.py +0 -0
  12. {evalis-0.2.0 → evalis-0.2.1}/src/evalis/__gen__/EvalisListener.py +0 -0
  13. {evalis-0.2.0 → evalis-0.2.1}/src/evalis/__gen__/EvalisParser.py +0 -0
  14. {evalis-0.2.0 → evalis-0.2.1}/src/evalis/__gen__/EvalisVisitor.py +0 -0
  15. {evalis-0.2.0 → evalis-0.2.1}/src/evalis/__gen__/grammar.py +0 -0
  16. {evalis-0.2.0 → evalis-0.2.1}/src/evalis/__init__.py +0 -0
  17. {evalis-0.2.0 → evalis-0.2.1}/src/evalis/antlr4_adapter.py +0 -0
  18. {evalis-0.2.0 → evalis-0.2.1}/src/evalis/ast.py +0 -0
  19. {evalis-0.2.0 → evalis-0.2.1}/src/evalis/error.py +0 -0
  20. {evalis-0.2.0 → evalis-0.2.1}/src/evalis/evalis.py +0 -0
  21. {evalis-0.2.0 → evalis-0.2.1}/src/evalis/types.py +0 -0
  22. {evalis-0.2.0 → evalis-0.2.1}/src/evalis.egg-info/SOURCES.txt +0 -0
  23. {evalis-0.2.0 → evalis-0.2.1}/src/evalis.egg-info/dependency_links.txt +0 -0
  24. {evalis-0.2.0 → evalis-0.2.1}/src/evalis.egg-info/requires.txt +0 -0
  25. {evalis-0.2.0 → evalis-0.2.1}/src/evalis.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: evalis
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: A polyglot, safe, user-friendly expression evaluator.
5
5
  Author-email: Paul Slaughter <paul@souldzin.com>
6
6
  License-Expression: MIT
@@ -3,7 +3,7 @@
3
3
  # - To change the __version__ in this file, use the `set_version` make target.
4
4
 
5
5
  # Version of package
6
- __version__ = "0.2.0"
6
+ __version__ = "0.2.1"
7
7
 
8
8
 
9
9
  # Evalis expression version that this package supports
@@ -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 as_str, is_primitive, should_str_concat
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
- return left > right
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
- return left >= right
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
- return left < right
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
- return left <= right
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: evalis
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: A polyglot, safe, user-friendly expression evaluator.
5
5
  Author-email: Paul Slaughter <paul@souldzin.com>
6
6
  License-Expression: MIT
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