Skip to content

Commit

Permalink
remove Python 3.8 deprecated nodes, names
Browse files Browse the repository at this point in the history
  • Loading branch information
newville committed Jun 30, 2024
1 parent 471ddc1 commit 0ebd66e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 31 deletions.
33 changes: 4 additions & 29 deletions asteval/asteval.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,6 @@ def on_pass(self, node):
"""Pass statement."""
return None # ()

def on_ellipsis(self, node):
"""Ellipses. deprecated in 3.8"""
return Ellipsis

# for break and continue: set the instance variable _interrupt
def on_interrupt(self, node): # ()
"""Interrupt handler."""
Expand All @@ -460,9 +456,8 @@ def on_continue(self, node):
def on_assert(self, node): # ('test', 'msg')
"""Assert statement."""
if not self.run(node.test):
#depraction warning: will become:
# msg = node.msg.value if node.msg else ""
msg = node.msg.s if node.msg else ""
msg = node.msg.value if node.msg else ""
# msg = node.msg.s if node.msg else ""
self.raise_exception(node, exc=AssertionError, msg=msg)
return True

Expand All @@ -487,18 +482,6 @@ def on_constant(self, node): # ('value', 'kind')
"""Return constant value."""
return node.value

def on_num(self, node): # ('n',)
"""Return number. deprecated in 3.8"""
return node.n

def on_str(self, node): # ('s',)
"""Return string. deprecated in 3.8"""
return node.s

def on_bytes(self, node):
"""return bytes. deprecated in 3.8"""
return node.s # ('s',)

def on_joinedstr(self, node): # ('values',)
"join strings, used in f-strings"
return ''.join([self.run(k) for k in node.values])
Expand Down Expand Up @@ -528,10 +511,6 @@ def on_name(self, node): # ('id', 'ctx')
return str(node.id)
return self._getsym(node)

def on_nameconstant(self, node):
"""True, False, or None deprecated in 3.8"""
return node.value

def node_assign(self, node, val):
"""Assign a value (not the node.value object) to a node.
Expand Down Expand Up @@ -952,12 +931,8 @@ def on_functiondef(self, node):
args = [tnode.arg for tnode in node.args.args[:offset]]
doc = None
nb0 = node.body[0]
# deprecation warning: will become
# if isinstance(nb0, ast.Expr) and isinstance(nb0.value, ast.Constant):
if isinstance(nb0, ast.Expr) and isinstance(nb0.value, ast.Str):
# deprecation warning: will become
# doc = nb0.value
doc = nb0.value.s
if isinstance(nb0, ast.Expr) and isinstance(nb0.value, ast.Constant):
doc = nb0.value
varkws = node.args.kwarg
vararg = node.args.vararg
if isinstance(vararg, ast.arg):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_asteval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,9 +1105,9 @@ def test_astdump(nested):
assert isinstance(astnode, ast.Module)
assert isinstance(astnode.body[0], ast.Assign)
assert isinstance(astnode.body[0].targets[0], ast.Name)
assert isinstance(astnode.body[0].value, ast.Num)
assert isinstance(astnode.body[0].value, ast.Constant)
assert astnode.body[0].targets[0].id == 'x'
assert astnode.body[0].value.n == 1
assert astnode.body[0].value.value == 1
dumped = interp.dump(astnode.body[0])
assert dumped.startswith('Assign')

Expand Down

0 comments on commit 0ebd66e

Please sign in to comment.