Skip to content

Commit b5fc7b5

Browse files
committed
Remove _ListComp
1 parent 6abb955 commit b5fc7b5

File tree

1 file changed

+27
-36
lines changed

1 file changed

+27
-36
lines changed

astroid/nodes/scoped_nodes/scoped_nodes.py

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ def get_children(self):
11441144
yield from self.generators
11451145

11461146

1147-
class _ListComp(node_classes.NodeNG):
1147+
class ListComp(ComprehensionScope):
11481148
"""Class representing an :class:`ast.ListComp` node.
11491149
11501150
>>> import astroid
@@ -1154,17 +1154,43 @@ class _ListComp(node_classes.NodeNG):
11541154
"""
11551155

11561156
_astroid_fields = ("elt", "generators")
1157+
_other_other_fields = ("locals",)
1158+
11571159
elt = None
11581160
"""The element that forms the output of the expression.
11591161
11601162
:type: NodeNG or None
11611163
"""
1164+
11621165
generators = None
11631166
"""The generators that are looped through.
11641167
11651168
:type: list(Comprehension) or None
11661169
"""
11671170

1171+
def __init__(
1172+
self,
1173+
lineno=None,
1174+
col_offset=None,
1175+
parent=None,
1176+
*,
1177+
end_lineno=None,
1178+
end_col_offset=None,
1179+
):
1180+
self.locals = {}
1181+
"""A map of the name of a local variable to the node defining it.
1182+
1183+
:type: dict(str, NodeNG)
1184+
"""
1185+
1186+
super().__init__(
1187+
lineno=lineno,
1188+
col_offset=col_offset,
1189+
end_lineno=end_lineno,
1190+
end_col_offset=end_col_offset,
1191+
parent=parent,
1192+
)
1193+
11681194
def postinit(self, elt=None, generators=None):
11691195
"""Do some setup after initialisation.
11701196
@@ -1192,41 +1218,6 @@ def get_children(self):
11921218
yield from self.generators
11931219

11941220

1195-
class ListComp(_ListComp, ComprehensionScope):
1196-
"""Class representing an :class:`ast.ListComp` node.
1197-
1198-
>>> import astroid
1199-
>>> node = astroid.extract_node('[thing for thing in things if thing]')
1200-
>>> node
1201-
<ListComp l.1 at 0x7f23b2e418d0>
1202-
"""
1203-
1204-
_other_other_fields = ("locals",)
1205-
1206-
def __init__(
1207-
self,
1208-
lineno=None,
1209-
col_offset=None,
1210-
parent=None,
1211-
*,
1212-
end_lineno=None,
1213-
end_col_offset=None,
1214-
):
1215-
self.locals = {}
1216-
"""A map of the name of a local variable to the node defining it.
1217-
1218-
:type: dict(str, NodeNG)
1219-
"""
1220-
1221-
super().__init__(
1222-
lineno=lineno,
1223-
col_offset=col_offset,
1224-
end_lineno=end_lineno,
1225-
end_col_offset=end_col_offset,
1226-
parent=parent,
1227-
)
1228-
1229-
12301221
def _infer_decorator_callchain(node):
12311222
"""Detect decorator call chaining and see if the end result is a
12321223
static or a classmethod.

0 commit comments

Comments
 (0)