Skip to content

Commit

Permalink
ast.Constant value replaces n
Browse files Browse the repository at this point in the history
supported from python 3.9
(usage of n fires deprecated warnings in new python versions)
  • Loading branch information
idanpa committed Dec 4, 2024
1 parent 3db9eb6 commit de6e038
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions calcpy/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def __init__(self, ip):
class ReplaceIntegerDivisionWithRational(AstNodeTransformer):
def visit_BinOp(self, node):
def is_integer(x):
if isinstance(x, ast.Constant) and isinstance(x.n, int):
if isinstance(x, ast.Constant) and isinstance(x.value, int):
return True
if isinstance(x, ast.Name) and isinstance(self.ip.user_ns.get(x.id, None), int):
return True
Expand All @@ -202,7 +202,7 @@ def is_integer(x):
'''
class ReplaceIntWithInteger(AstNodeTransformer):
def visit_Constant(self, node):
if isinstance(node.n, int):
if isinstance(node.value, int):
return ast.Call(func=ast.Name(id='Integer', ctx=ast.Load()),
args=[node], keywords=[])
return self.generic_visit(node)
Expand All @@ -211,7 +211,7 @@ def visit_Constant(self, node):
class ReplaceFloatWithRational(AstNodeTransformer):
def visit_Constant(self, node):
if self.ip.calcpy.auto_rational:
if isinstance(node.n, float):
if isinstance(node.value, float):
return ast.Call(func=ast.Name(id='Rational', ctx=ast.Load()),
args=[ast.Call(func=ast.Name(id='str', ctx=ast.Load()),
args=[node], keywords=[])],
Expand Down

0 comments on commit de6e038

Please sign in to comment.