diff options
author | Nick Drozd <nicholasdrozd@gmail.com> | 2023-04-05 03:43:02 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-05 09:43:02 +0200 |
commit | a8a8593979a579e2ba92ca46bb172f00c7d103c6 (patch) | |
tree | fca72495fa93c9b4a87d8750d183f91ba6192e86 | |
parent | b1e1e24c00eff00d3401d58ebd522d697d743b1c (diff) | |
download | astroid-git-a8a8593979a579e2ba92ca46bb172f00c7d103c6.tar.gz |
Mandatory fields for Return (#2104)
Co-authored-by: Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | astroid/nodes/node_classes.py | 40 | ||||
-rw-r--r-- | astroid/rebuilder.py | 3 |
3 files changed, 5 insertions, 39 deletions
@@ -31,6 +31,7 @@ Release date: TBA - ``nodes.Keyword`` - ``nodes.Name`` - ``nodes.Raise`` + - ``nodes.Return - ``nodes.Slice`` - ``nodes.Starred`` - ``nodes.Subscript`` diff --git a/astroid/nodes/node_classes.py b/astroid/nodes/node_classes.py index 1a4613e4..56921d2d 100644 --- a/astroid/nodes/node_classes.py +++ b/astroid/nodes/node_classes.py @@ -3041,44 +3041,10 @@ class Return(_base_nodes.Statement): _astroid_fields = ("value",) - def __init__( - self, - lineno: int | None = None, - col_offset: int | None = None, - parent: NodeNG | None = None, - *, - end_lineno: int | None = None, - end_col_offset: int | None = None, - ) -> None: - """ - :param lineno: The line that this node appears on in the source code. - - :param col_offset: The column that this node appears on in the - source code. - - :param parent: The parent node in the syntax tree. - - :param end_lineno: The last line this node appears on in the source code. - - :param end_col_offset: The end column this node appears on in the - source code. Note: This is after the last symbol. - """ - self.value: NodeNG | None = None # can be None - """The value being returned.""" - - super().__init__( - lineno=lineno, - col_offset=col_offset, - end_lineno=end_lineno, - end_col_offset=end_col_offset, - parent=parent, - ) - - def postinit(self, value: NodeNG | None = None) -> None: - """Do some setup after initialisation. + value: NodeNG | None + """The value being returned.""" - :param value: The value being returned. - """ + def postinit(self, value: NodeNG | None) -> None: self.value = value def get_children(self): diff --git a/astroid/rebuilder.py b/astroid/rebuilder.py index 00ba9da9..5252ac8f 100644 --- a/astroid/rebuilder.py +++ b/astroid/rebuilder.py @@ -1686,8 +1686,7 @@ class TreeRebuilder: end_col_offset=getattr(node, "end_col_offset", None), parent=parent, ) - if node.value is not None: - newnode.postinit(self.visit(node.value, newnode)) + newnode.postinit(self.visit(node.value, newnode)) return newnode def visit_set(self, node: ast.Set, parent: NodeNG) -> nodes.Set: |