summaryrefslogtreecommitdiff
path: root/astroid/nodes
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2023-04-22 22:32:31 +0200
committerGitHub <noreply@github.com>2023-04-22 20:32:31 +0000
commit32281b9129106093354c490b289ac8c285ae8e17 (patch)
tree979f8ee0a099bc354d203f910b3066acaa39c7b3 /astroid/nodes
parentbf7d42e494d8c4ad3526bd7983067a05e9a8a248 (diff)
downloadastroid-git-32281b9129106093354c490b289ac8c285ae8e17.tar.gz
Fix constructors of ``ComprehensionScopes`` (#2132)
Diffstat (limited to 'astroid/nodes')
-rw-r--r--astroid/nodes/scoped_nodes/scoped_nodes.py210
1 files changed, 52 insertions, 158 deletions
diff --git a/astroid/nodes/scoped_nodes/scoped_nodes.py b/astroid/nodes/scoped_nodes/scoped_nodes.py
index 2c1daf4c..8cd2d06b 100644
--- a/astroid/nodes/scoped_nodes/scoped_nodes.py
+++ b/astroid/nodes/scoped_nodes/scoped_nodes.py
@@ -641,42 +641,24 @@ class GeneratorExp(ComprehensionScope):
_astroid_fields = ("elt", "generators")
_other_other_fields = ("locals",)
- elt = None
- """The element that forms the output of the expression.
-
- :type: NodeNG or None
- """
+ elt: NodeNG
+ """The element that forms the output of the expression."""
def __init__(
self,
- lineno=None,
- col_offset=None,
- parent=None,
+ lineno: int,
+ col_offset: int,
+ parent: NodeNG,
*,
- end_lineno=None,
- end_col_offset=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
-
- :param end_lineno: The last line this node appears on in the source code.
- :type end_lineno: Optional[int]
-
- :param end_col_offset: The end column this node appears on in the
- source code. Note: This is after the last symbol.
- :type end_col_offset: Optional[int]
- """
+ end_lineno: int | None,
+ end_col_offset: int | None,
+ ) -> None:
self.locals = {}
"""A map of the name of a local variable to the node defining the local."""
+ self.generators: list[nodes.Comprehension] = []
+ """The generators that are looped through."""
+
super().__init__(
lineno=lineno,
col_offset=col_offset,
@@ -685,19 +667,9 @@ class GeneratorExp(ComprehensionScope):
parent=parent,
)
- def postinit(self, elt=None, generators: list[nodes.Comprehension] | None = None):
- """Do some setup after initialisation.
-
- :param elt: The element that forms the output of the expression.
- :type elt: NodeNG or None
-
- :param generators: The generators that are looped through.
- """
+ def postinit(self, elt: NodeNG, generators: list[nodes.Comprehension]) -> None:
self.elt = elt
- if generators is None:
- self.generators = []
- else:
- self.generators = generators
+ self.generators = generators
def bool_value(self, context: InferenceContext | None = None) -> Literal[True]:
"""Determine the boolean value of this node.
@@ -724,44 +696,21 @@ class DictComp(ComprehensionScope):
_astroid_fields = ("key", "value", "generators")
_other_other_fields = ("locals",)
- key = None
- """What produces the keys.
+ key: NodeNG
+ """What produces the keys."""
- :type: NodeNG or None
- """
- value = None
- """What produces the values.
-
- :type: NodeNG or None
- """
+ value: NodeNG
+ """What produces the values."""
def __init__(
self,
- lineno=None,
- col_offset=None,
- parent=None,
+ lineno: int,
+ col_offset: int,
+ parent: NodeNG,
*,
- end_lineno=None,
- end_col_offset=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
-
- :param end_lineno: The last line this node appears on in the source code.
- :type end_lineno: Optional[int]
-
- :param end_col_offset: The end column this node appears on in the
- source code. Note: This is after the last symbol.
- :type end_col_offset: Optional[int]
- """
+ end_lineno: int | None,
+ end_col_offset: int | None,
+ ) -> None:
self.locals = {}
"""A map of the name of a local variable to the node defining the local."""
@@ -774,27 +723,11 @@ class DictComp(ComprehensionScope):
)
def postinit(
- self,
- key=None,
- value=None,
- generators: list[nodes.Comprehension] | None = None,
- ):
- """Do some setup after initialisation.
-
- :param key: What produces the keys.
- :type key: NodeNG or None
-
- :param value: What produces the values.
- :type value: NodeNG or None
-
- :param generators: The generators that are looped through.
- """
+ self, key: NodeNG, value: NodeNG, generators: list[nodes.Comprehension]
+ ) -> None:
self.key = key
self.value = value
- if generators is None:
- self.generators = []
- else:
- self.generators = generators
+ self.generators = generators
def bool_value(self, context: InferenceContext | None = None):
"""Determine the boolean value of this node.
@@ -823,42 +756,24 @@ class SetComp(ComprehensionScope):
_astroid_fields = ("elt", "generators")
_other_other_fields = ("locals",)
- elt = None
- """The element that forms the output of the expression.
-
- :type: NodeNG or None
- """
+ elt: NodeNG
+ """The element that forms the output of the expression."""
def __init__(
self,
- lineno=None,
- col_offset=None,
- parent=None,
+ lineno: int,
+ col_offset: int,
+ parent: NodeNG,
*,
- end_lineno=None,
- end_col_offset=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
-
- :param end_lineno: The last line this node appears on in the source code.
- :type end_lineno: Optional[int]
-
- :param end_col_offset: The end column this node appears on in the
- source code. Note: This is after the last symbol.
- :type end_col_offset: Optional[int]
- """
+ end_lineno: int | None,
+ end_col_offset: int | None,
+ ) -> None:
self.locals = {}
"""A map of the name of a local variable to the node defining the local."""
+ self.generators: list[nodes.Comprehension] = []
+ """The generators that are looped through."""
+
super().__init__(
lineno=lineno,
col_offset=col_offset,
@@ -867,19 +782,9 @@ class SetComp(ComprehensionScope):
parent=parent,
)
- def postinit(self, elt=None, generators: list[nodes.Comprehension] | None = None):
- """Do some setup after initialisation.
-
- :param elt: The element that forms the output of the expression.
- :type elt: NodeNG or None
-
- :param generators: The generators that are looped through.
- """
+ def postinit(self, elt: NodeNG, generators: list[nodes.Comprehension]) -> None:
self.elt = elt
- if generators is None:
- self.generators = []
- else:
- self.generators = generators
+ self.generators = generators
def bool_value(self, context: InferenceContext | None = None):
"""Determine the boolean value of this node.
@@ -908,24 +813,24 @@ class ListComp(ComprehensionScope):
_astroid_fields = ("elt", "generators")
_other_other_fields = ("locals",)
- elt = None
- """The element that forms the output of the expression.
-
- :type: NodeNG or None
- """
+ elt: NodeNG
+ """The element that forms the output of the expression."""
def __init__(
self,
- lineno=None,
- col_offset=None,
- parent=None,
+ lineno: int,
+ col_offset: int,
+ parent: NodeNG,
*,
- end_lineno=None,
- end_col_offset=None,
- ):
+ end_lineno: int | None,
+ end_col_offset: int | None,
+ ) -> None:
self.locals = {}
"""A map of the name of a local variable to the node defining it."""
+ self.generators: list[nodes.Comprehension] = []
+ """The generators that are looped through."""
+
super().__init__(
lineno=lineno,
col_offset=col_offset,
@@ -934,20 +839,9 @@ class ListComp(ComprehensionScope):
parent=parent,
)
- def postinit(self, elt=None, generators: list[nodes.Comprehension] | None = None):
- """Do some setup after initialisation.
-
- :param elt: The element that forms the output of the expression.
- :type elt: NodeNG or None
-
- :param generators: The generators that are looped through.
- :type generators: list(Comprehension) or None
- """
+ def postinit(self, elt: NodeNG, generators: list[nodes.Comprehension]):
self.elt = elt
- if generators is None:
- self.generators = []
- else:
- self.generators = generators
+ self.generators = generators
def bool_value(self, context: InferenceContext | None = None):
"""Determine the boolean value of this node.