calculate_math_string: support Python 3.14 and newer

Switch to ast.Constant, ast.Num was deprecated in Python 3.8 and removed in
Python 3.14.

> Changed in version 3.8: Class ast.Constant is now used for all constants.
>
> Deprecated since version 3.8: Old classes ast.Num, ast.Str, ast.Bytes,
> ast.NameConstant and ast.Ellipsis are still available, but they will be
> removed in future Python releases. In the meanwhile, instantiating them
> will return an instance of a different class.
https://docs.python.org/3.14/library/ast.html#ast.AST.end_col_offset
This commit is contained in:
Hans-Christoph Steiner
2025-12-03 18:35:31 +01:00
parent 6c46c363a1
commit 31a2c18725

View File

@@ -4776,8 +4776,8 @@ def calculate_math_string(expr):
}
def execute_ast(node):
if isinstance(node, ast.Num): # <number>
return node.n
if isinstance(node, ast.Constant): # <number>
return node.value
elif isinstance(node, ast.BinOp): # <left> <operator> <right>
return ops[type(node.op)](execute_ast(node.left),
execute_ast(node.right))