From 758b1b9250fca93b8fdcdc91053e0f91850f322b Mon Sep 17 00:00:00 2001 From: Nick Drozd Date: Mon, 28 Nov 2022 18:14:13 -0600 Subject: [PATCH 1/2] Mandatory fields for Assign --- astroid/nodes/node_classes.py | 59 +++++++---------------------------- 1 file changed, 11 insertions(+), 48 deletions(-) diff --git a/astroid/nodes/node_classes.py b/astroid/nodes/node_classes.py index 6d3397bf76..0c12fb74d7 100644 --- a/astroid/nodes/node_classes.py +++ b/astroid/nodes/node_classes.py @@ -1202,62 +1202,25 @@ class Assign(_base_nodes.AssignTypeNode, _base_nodes.Statement): """ - _astroid_fields = ("targets", "value") - _other_other_fields = ("type_annotation",) - - 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.targets: list[NodeNG] = [] - """What is being assigned to.""" + targets: list[NodeNG] + """What is being assigned to.""" - self.value: NodeNG | None = None - """The value being assigned to the variables.""" + value: NodeNG + """The value being assigned to the variables.""" - self.type_annotation: NodeNG | None = None # can be None - """If present, this will contain the type annotation passed by a type comment""" + type_annotation: NodeNG | None + """If present, this will contain the type annotation passed by a type comment""" - super().__init__( - lineno=lineno, - col_offset=col_offset, - end_lineno=end_lineno, - end_col_offset=end_col_offset, - parent=parent, - ) + _astroid_fields = ("targets", "value") + _other_other_fields = ("type_annotation",) def postinit( self, - targets: list[NodeNG] | None = None, - value: NodeNG | None = None, + targets: list[NodeNG], + value: NodeNG, type_annotation: NodeNG | None = None, ) -> None: - """Do some setup after initialisation. - - :param targets: What is being assigned to. - :param value: The value being assigned to the variables. - :param type_annotation: - """ - if targets is not None: - self.targets = targets + self.targets = targets self.value = value self.type_annotation = type_annotation From 91bd3521ec92dad7c2a98fb323dbd024c86972a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Mon, 3 Apr 2023 18:01:13 +0200 Subject: [PATCH 2/2] Last changes --- ChangeLog | 1 + astroid/nodes/node_classes.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 03f756fbd9..c21016e10a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,7 @@ Release date: TBA Closes #1780 * Improved signature of the ``__init__`` and ``__postinit__`` methods of the following nodes: + - ``nodes.Assign`` - ``nodes.If`` - ``nodes.IfExp`` diff --git a/astroid/nodes/node_classes.py b/astroid/nodes/node_classes.py index 0c12fb74d7..9b83b91ab0 100644 --- a/astroid/nodes/node_classes.py +++ b/astroid/nodes/node_classes.py @@ -1218,7 +1218,7 @@ def postinit( self, targets: list[NodeNG], value: NodeNG, - type_annotation: NodeNG | None = None, + type_annotation: NodeNG | None, ) -> None: self.targets = targets self.value = value