From 0ebd66ecdb2aa53667df11e81af7f5e1da3e4799 Mon Sep 17 00:00:00 2001 From: Matthew Newville Date: Sun, 30 Jun 2024 11:07:32 -0500 Subject: [PATCH] remove Python 3.8 deprecated nodes, names --- asteval/asteval.py | 33 ++++----------------------------- tests/test_asteval.py | 4 ++-- 2 files changed, 6 insertions(+), 31 deletions(-) diff --git a/asteval/asteval.py b/asteval/asteval.py index 11fc6c9..5d33c9a 100644 --- a/asteval/asteval.py +++ b/asteval/asteval.py @@ -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.""" @@ -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 @@ -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]) @@ -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. @@ -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): diff --git a/tests/test_asteval.py b/tests/test_asteval.py index 5620a47..f7a2865 100644 --- a/tests/test_asteval.py +++ b/tests/test_asteval.py @@ -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')