Skip to content

Commit 8a05b6b

Browse files
Avoid using deprecated ast attributes
This commit updates the logic in the expander to avoid using deprecated attributes (like Num and Str) where possible. Additionally it prioritizes using the newer version (Constant) to avoid deprecation warnings.
1 parent b4685ac commit 8a05b6b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/ramble/ramble/expander.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -839,16 +839,16 @@ def eval_math(self, node):
839839
others will generate integers (if the inputs are integers).
840840
"""
841841
try:
842-
if isinstance(node, ast.Num):
843-
return self._ast_num(node)
844-
elif isinstance(node, ast.Constant):
842+
if hasattr(ast, "Constant") and isinstance(node, ast.Constant):
845843
return self._ast_constant(node)
844+
elif hasattr(ast, "Num") and isinstance(node, ast.Num): # Deprecated, removed in 3.14
845+
return self._ast_num(node)
846846
elif isinstance(node, ast.Name):
847847
return self._ast_name(node)
848848
# TODO: Remove when we drop support for 3.6
849849
# DEPRECATED: Remove due to python 3.8
850850
# See: https://docs.python.org/3/library/ast.html#node-classes
851-
elif isinstance(node, ast.Str):
851+
elif hasattr(ast, "Str") and isinstance(node, ast.Str): # Deprecated, removed in 3.14
852852
return node.s
853853
elif isinstance(node, ast.Attribute):
854854
return self._ast_attr(node)

0 commit comments

Comments
 (0)