Skip to content

Commit 9569dd5

Browse files
committed
[fix] fix deprecated ast features
1 parent b0431aa commit 9569dd5

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

python/solid_dmft/dmft_tools/matheval.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44
import math
55

66

7+
# Determine numeric/constant node for compatibility across Python versions
8+
_AST_CONSTANT = getattr(ast, "Constant", None)
9+
710
class MathExpr(object):
8-
allowed_nodes = (
11+
# Base allowed nodes (version-agnostic)
12+
_base_allowed = (
913
ast.Module,
1014
ast.Expr,
1115
ast.Load,
1216
ast.Expression,
1317
ast.Add,
1418
ast.Sub,
1519
ast.UnaryOp,
16-
ast.Num,
1720
ast.BinOp,
1821
ast.Mult,
1922
ast.Div,
@@ -32,6 +35,11 @@ class MathExpr(object):
3235
ast.Name,
3336
)
3437

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+
3543
functions = {
3644
"abs": abs,
3745
"complex": complex,

0 commit comments

Comments
 (0)