Skip to content

Commit 04199c5

Browse files
committed
fix: Python 3.8 AST compatibility and ruff formatting
- Add deprecated AST node types (Index, Num, Str, Bytes, NameConstant) to the safe eval allowlist for Python 3.8 compatibility - Fix ruff format in test_issues.py
1 parent 07e2c11 commit 04199c5

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

jsonpath/jsonpath.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ class JSONPath:
165165
# Context
166166
ast.Load,
167167
}
168+
# Python 3.8 compatibility: deprecated AST nodes removed in 3.12
169+
| {getattr(ast, n) for n in ("Index", "Num", "Str", "Bytes", "NameConstant") if hasattr(ast, n)}
168170
)
169171
_ALLOWED_NAMES = frozenset({"__obj", "len", "RegexPattern"})
170172
_ALLOWED_CALLS = frozenset({"len", "RegexPattern"})

tests/test_issues.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ def test_bare_at_numeric_comparison(self):
9393
def test_bare_at_regex(self):
9494
"""Bare @ should work with regex matching."""
9595
data = {"tags": ["web", "owasp:software_and_data_integrity_failures"]}
96-
assert JSONPath("$.tags[?(@ =~ /owasp:.+/)]").parse(data) == [
97-
"owasp:software_and_data_integrity_failures"
98-
]
96+
assert JSONPath("$.tags[?(@ =~ /owasp:.+/)]").parse(data) == ["owasp:software_and_data_integrity_failures"]
9997

10098
def test_bare_at_in_operator(self):
10199
"""Bare @ with 'in' operator."""

0 commit comments

Comments
 (0)