diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-09-29 20:08:32 +0300 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2018-09-30 11:06:09 +0200 |
commit | 3746acc55f5445e1e350fa4a4ca225fad823ed12 (patch) | |
tree | 1e5216c6a87738c71cc9cf6350f402525e4952e6 /astroid/rebuilder.py | |
parent | 4eb48354b96bb1bcf61a3d7f018e0badf7f1a99a (diff) | |
download | astroid-git-3746acc55f5445e1e350fa4a4ca225fad823ed12.tar.gz |
Reflect AST changes in Python 3.8.
* Num, Str, Bytes, Ellipsis and NameConstant are replaced with Constant.
(https://bugs.python.org/issue32892)
* Index is replaced with its value, ExtSlice is replaced with Tuple.
(https://bugs.python.org/issue34822)
Diffstat (limited to 'astroid/rebuilder.py')
-rw-r--r-- | astroid/rebuilder.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/astroid/rebuilder.py b/astroid/rebuilder.py index c37128fa..3cac7083 100644 --- a/astroid/rebuilder.py +++ b/astroid/rebuilder.py @@ -479,6 +479,7 @@ class TreeRebuilder: newnode.postinit(self.visit(node.value, newnode)) return newnode + # Not used in Python 3.8+. def visit_ellipsis(self, node, parent): """visit an Ellipsis node by returning a fresh instance of it""" return nodes.Ellipsis(getattr(node, 'lineno', None), @@ -509,6 +510,7 @@ class TreeRebuilder: _visit_or_none(node, 'locals', self, newnode)) return newnode + # Not used in Python 3.8+. def visit_extslice(self, node, parent): """visit an ExtSlice node by returning a fresh instance of it""" newnode = nodes.ExtSlice(parent=parent) @@ -641,6 +643,7 @@ class TreeRebuilder: parent.set_local(name.split('.')[0], newnode) return newnode + # Not used in Python 3.8+. def visit_index(self, node, parent): """visit a Index node by returning a fresh instance of it""" newnode = nodes.Index(parent=parent) @@ -702,12 +705,19 @@ class TreeRebuilder: self._save_assignment(newnode) return newnode + def visit_constant(self, node, parent): + """visit a Constant node by returning a fresh instance of Const""" + return nodes.Const(node.value, getattr(node, 'lineno', None), + getattr(node, 'col_offset', None), parent) + + # Not used in Python 3.8+. def visit_str(self, node, parent): """visit a String/Bytes node by returning a fresh instance of Const""" return nodes.Const(node.s, getattr(node, 'lineno', None), getattr(node, 'col_offset', None), parent) visit_bytes = visit_str + # Not used in Python 3.8+. def visit_num(self, node, parent): """visit a Num node by returning a fresh instance of Const""" return nodes.Const(node.n, getattr(node, 'lineno', None), @@ -854,6 +864,7 @@ class TreeRebuilder3(TreeRebuilder): """visit an arg node by returning a fresh AssName instance""" return self.visit_assignname(node, parent, node.arg) + # Not used in Python 3.8+. def visit_nameconstant(self, node, parent): # in Python 3.4 we have NameConstant for True / False / None return nodes.Const(node.value, getattr(node, 'lineno', None), |