There was an error while loading. Please reload this page.
1 parent b0431aa commit 9569dd5Copy full SHA for 9569dd5
1 file changed
python/solid_dmft/dmft_tools/matheval.py
@@ -4,16 +4,19 @@
4
import math
5
6
7
+# Determine numeric/constant node for compatibility across Python versions
8
+_AST_CONSTANT = getattr(ast, "Constant", None)
9
+
10
class MathExpr(object):
- allowed_nodes = (
11
+ # Base allowed nodes (version-agnostic)
12
+ _base_allowed = (
13
ast.Module,
14
ast.Expr,
15
ast.Load,
16
ast.Expression,
17
ast.Add,
18
ast.Sub,
19
ast.UnaryOp,
- ast.Num,
20
ast.BinOp,
21
ast.Mult,
22
ast.Div,
@@ -32,6 +35,11 @@ class MathExpr(object):
32
35
ast.Name,
33
36
)
34
37
38
+ # Extend allowed nodes with version-specific constant node
39
+ allowed_nodes = _base_allowed + (
40
+ _AST_CONSTANT if _AST_CONSTANT is not None else ast.Num,
41
+ )
42
43
functions = {
44
"abs": abs,
45
"complex": complex,
0 commit comments