summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Mueller <30130371+cdce8p@users.noreply.github.com>2021-06-12 21:54:33 +0200
committerGitHub <noreply@github.com>2021-06-12 21:54:33 +0200
commita73b01aeacbe80bf7dd9ad4d9804defb867d6869 (patch)
treeff028128eef4beb4118d59f8ad3649b528d6bee2
parent3eacc2d4789ff7a43352734beb33be31b8610738 (diff)
downloadastroid-git-a73b01aeacbe80bf7dd9ad4d9804defb867d6869.tar.gz
Remove py2 nodes (#1023)
* Removed Repr, Exec, Print nodes * Updated rebuilder
-rw-r--r--ChangeLog2
-rw-r--r--astroid/node_classes.py126
-rw-r--r--astroid/nodes.py6
-rw-r--r--astroid/rebuilder.py63
-rw-r--r--doc/api/astroid.nodes.rst9
5 files changed, 4 insertions, 202 deletions
diff --git a/ChangeLog b/ChangeLog
index 2e835677..63d54d6a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,8 @@ What's New in astroid 2.6.0?
============================
Release Date: TBA
+* Removed ``Repr``, ``Exec``, and ``Print`` nodes as the ``ast`` nodes
+ they represented have been removed with the change to Python 3
What's New in astroid 2.5.8?
diff --git a/astroid/node_classes.py b/astroid/node_classes.py
index a9ee613d..c8272266 100644
--- a/astroid/node_classes.py
+++ b/astroid/node_classes.py
@@ -2138,33 +2138,6 @@ class AugAssign(mixins.AssignTypeMixin, Statement):
yield from super()._get_yield_nodes_skip_lambdas()
-class Repr(NodeNG):
- """Class representing an :class:`ast.Repr` node.
-
- A :class:`Repr` node represents the backtick syntax,
- which is a deprecated alias for :func:`repr` removed in Python 3.
-
- >>> node = astroid.extract_node('`variable`')
- >>> node
- <Repr l.1 at 0x7fa0951d75d0>
- """
-
- _astroid_fields = ("value",)
- value = None
- """What is having :func:`repr` called on it.
-
- :type: NodeNG or None
- """
-
- def postinit(self, value=None):
- """Do some setup after initialisation.
-
- :param value: What is having :func:`repr` called on it.
- :type value: NodeNG or None
- """
- self.value = value
-
-
class BinOp(NodeNG):
"""Class representing an :class:`ast.BinOp` node.
@@ -3104,49 +3077,6 @@ class ExceptHandler(mixins.MultiLineBlockMixin, mixins.AssignTypeMixin, Statemen
return False
-class Exec(Statement):
- """Class representing the ``exec`` statement.
-
- >>> node = astroid.extract_node('exec "True"')
- >>> node
- <Exec l.1 at 0x7f0e8106c6d0>
- """
-
- _astroid_fields = ("expr", "globals", "locals")
- expr = None
- """The expression to be executed.
-
- :type: NodeNG or None
- """
- globals = None
- """The globals dictionary to execute with.
-
- :type: NodeNG or None
- """
- locals = None
- """The locals dictionary to execute with.
-
- :type: NodeNG or None
- """
-
- # pylint: disable=redefined-builtin; had to use the same name as builtin ast module.
- def postinit(self, expr=None, globals=None, locals=None):
- """Do some setup after initialisation.
-
- :param expr: The expression to be executed.
- :type expr: NodeNG or None
-
- :param globals:The globals dictionary to execute with.
- :type globals: NodeNG or None
-
- :param locals: The locals dictionary to execute with.
- :type locals: NodeNG or None
- """
- self.expr = expr
- self.globals = globals
- self.locals = locals
-
-
class ExtSlice(NodeNG):
"""Class representing an :class:`ast.ExtSlice` node.
@@ -3819,62 +3749,6 @@ class Pass(mixins.NoChildrenMixin, Statement):
"""
-class Print(Statement):
- """Class representing an :class:`ast.Print` node.
-
- >>> node = astroid.extract_node('print "A message"')
- >>> node
- <Print l.1 at 0x7f0e8101d290>
- """
-
- _astroid_fields = ("dest", "values")
- dest = None
- """Where to print to.
-
- :type: NodeNG or None
- """
- values = None
- """What to print.
-
- :type: list(NodeNG) or None
- """
-
- def __init__(self, nl=None, lineno=None, col_offset=None, parent=None):
- """
- :param nl: Whether to print a new line.
- :type nl: bool or None
-
- :param lineno: The line that this node appears on in the source code.
- :type lineno: int or None
-
- :param col_offset: The column that this node appears on in the
- source code.
- :type col_offset: int or None
-
- :param parent: The parent node in the syntax tree.
- :type parent: NodeNG or None
- """
- self.nl = nl
- """Whether to print a new line.
-
- :type: bool or None
- """
-
- super().__init__(lineno, col_offset, parent)
-
- def postinit(self, dest=None, values=None):
- """Do some setup after initialisation.
-
- :param dest: Where to print to.
- :type dest: NodeNG or None
-
- :param values: What to print.
- :type values: list(NodeNG) or None
- """
- self.dest = dest
- self.values = values
-
-
class Raise(Statement):
"""Class representing an :class:`ast.Raise` node.
diff --git a/astroid/nodes.py b/astroid/nodes.py
index e946b761..cfe45e47 100644
--- a/astroid/nodes.py
+++ b/astroid/nodes.py
@@ -53,7 +53,6 @@ from astroid.node_classes import (
EmptyNode,
EvaluatedObject,
ExceptHandler,
- Exec,
Expr,
ExtSlice,
For,
@@ -81,9 +80,7 @@ from astroid.node_classes import (
NamedExpr,
Nonlocal,
Pass,
- Print,
Raise,
- Repr,
Return,
Set,
Slice,
@@ -124,7 +121,6 @@ ALL_NODE_CLASSES = (
AnnAssign,
AssignName,
AugAssign,
- Repr,
BinOp,
BoolOp,
Break,
@@ -147,7 +143,6 @@ ALL_NODE_CLASSES = (
EmptyNode,
EvaluatedObject,
ExceptHandler,
- Exec,
ExtSlice,
For,
ImportFrom,
@@ -178,7 +173,6 @@ ALL_NODE_CLASSES = (
Nonlocal,
Module,
Pass,
- Print,
Raise,
Return,
Set,
diff --git a/astroid/rebuilder.py b/astroid/rebuilder.py
index 6f76a5a2..a8fcb6d9 100644
--- a/astroid/rebuilder.py
+++ b/astroid/rebuilder.py
@@ -40,8 +40,6 @@ from astroid.node_classes import NodeNG
if TYPE_CHECKING:
import ast
-CONST_NAME_TRANSFORMS = {"None": None, "True": True, "False": False}
-
REDIRECT = {
"arguments": "Arguments",
"comprehension": "Comprehension",
@@ -328,12 +326,6 @@ class TreeRebuilder:
)
return newnode
- def visit_repr(self, node, parent):
- """visit a Backquote node by returning a fresh instance of it"""
- newnode = nodes.Repr(node.lineno, node.col_offset, parent)
- newnode.postinit(self.visit(node.value, newnode))
- return newnode
-
def visit_binop(self, node, parent):
"""visit a BinOp node by returning a fresh instance of it"""
newnode = nodes.BinOp(
@@ -367,34 +359,12 @@ class TreeRebuilder:
def visit_call(self, node, parent):
"""visit a CallFunc node by returning a fresh instance of it"""
newnode = nodes.Call(node.lineno, node.col_offset, parent)
- starargs = _visit_or_none(node, "starargs", self, newnode)
- kwargs = _visit_or_none(node, "kwargs", self, newnode)
args = [self.visit(child, newnode) for child in node.args]
if node.keywords:
keywords = [self.visit(child, newnode) for child in node.keywords]
else:
keywords = None
- if starargs:
- new_starargs = nodes.Starred(
- col_offset=starargs.col_offset,
- lineno=starargs.lineno,
- parent=starargs.parent,
- )
- new_starargs.postinit(value=starargs)
- args.append(new_starargs)
- if kwargs:
- new_kwargs = nodes.Keyword(
- arg=None,
- col_offset=kwargs.col_offset,
- lineno=kwargs.lineno,
- parent=kwargs.parent,
- )
- new_kwargs.postinit(value=kwargs)
- if keywords:
- keywords.append(new_kwargs)
- else:
- keywords = [new_kwargs]
newnode.postinit(self.visit(node.func, newnode), args, keywords)
return newnode
@@ -491,7 +461,7 @@ class TreeRebuilder:
for key, value in zip(node.keys, node.values):
rebuilt_value = self.visit(value, newnode)
if not key:
- # Python 3.5 and extended unpacking
+ # Extended unpacking
rebuilt_key = nodes.DictUnpack(
rebuilt_value.lineno, rebuilt_value.col_offset, parent
)
@@ -549,16 +519,6 @@ class TreeRebuilder:
)
return newnode
- def visit_exec(self, node, parent):
- """visit an Exec node by returning a fresh instance of it"""
- newnode = nodes.Exec(node.lineno, node.col_offset, parent)
- newnode.postinit(
- self.visit(node.body, newnode),
- _visit_or_none(node, "globals", self, newnode),
- _visit_or_none(node, "locals", self, newnode),
- )
- return newnode
-
# Not used in Python 3.9+.
def visit_extslice(self, node, parent):
"""visit an ExtSlice node by returning a fresh instance of it"""
@@ -781,20 +741,10 @@ class TreeRebuilder:
def visit_name(self, node, parent):
"""visit a Name node by returning a fresh instance of it"""
context = self._get_context(node)
- # True and False can be assigned to something in py2x, so we have to
- # check first the context.
if context == astroid.Del:
newnode = nodes.DelName(node.id, node.lineno, node.col_offset, parent)
elif context == astroid.Store:
newnode = nodes.AssignName(node.id, node.lineno, node.col_offset, parent)
- elif node.id in CONST_NAME_TRANSFORMS:
- newnode = nodes.Const(
- CONST_NAME_TRANSFORMS[node.id],
- getattr(node, "lineno", None),
- getattr(node, "col_offset", None),
- parent,
- )
- return newnode
else:
newnode = nodes.Name(node.id, node.lineno, node.col_offset, parent)
# XXX REMOVE me :
@@ -804,7 +754,7 @@ class TreeRebuilder:
# Not used in Python 3.8+.
def visit_nameconstant(self, node, parent):
- # in Python 3.4 we have NameConstant for True / False / None
+ # For singleton values True / False / None
return nodes.Const(
node.value,
getattr(node, "lineno", None),
@@ -857,15 +807,6 @@ class TreeRebuilder:
"""visit a Pass node by returning a fresh instance of it"""
return nodes.Pass(node.lineno, node.col_offset, parent)
- def visit_print(self, node, parent):
- """visit a Print node by returning a fresh instance of it"""
- newnode = nodes.Print(node.nl, node.lineno, node.col_offset, parent)
- newnode.postinit(
- _visit_or_none(node, "dest", self, newnode),
- [self.visit(child, newnode) for child in node.values],
- )
- return newnode
-
def visit_raise(self, node, parent):
"""visit a Raise node by returning a fresh instance of it"""
newnode = nodes.Raise(node.lineno, node.col_offset, parent)
diff --git a/doc/api/astroid.nodes.rst b/doc/api/astroid.nodes.rst
index 549ccd25..d221f2e4 100644
--- a/doc/api/astroid.nodes.rst
+++ b/doc/api/astroid.nodes.rst
@@ -42,7 +42,6 @@ Nodes
Ellipsis
EmptyNode
ExceptHandler
- Exec
Expr
ExtSlice
For
@@ -74,9 +73,7 @@ Nodes
Name
Nonlocal
Pass
- Print
Raise
- Repr
Return
Set
SetComp
@@ -155,8 +152,6 @@ Nodes
.. autoclass:: ExceptHandler
-.. autoclass:: Exec
-
.. autoclass:: Expr
.. autoclass:: ExtSlice
@@ -219,12 +214,8 @@ Nodes
.. autoclass:: Pass
-.. autoclass:: Print
-
.. autoclass:: Raise
-.. autoclass:: Repr
-
.. autoclass:: Return
.. autoclass:: Set