@@ -1144,7 +1144,7 @@ def get_children(self):
1144
1144
yield from self .generators
1145
1145
1146
1146
1147
- class _ListComp ( node_classes . NodeNG ):
1147
+ class ListComp ( ComprehensionScope ):
1148
1148
"""Class representing an :class:`ast.ListComp` node.
1149
1149
1150
1150
>>> import astroid
@@ -1154,17 +1154,43 @@ class _ListComp(node_classes.NodeNG):
1154
1154
"""
1155
1155
1156
1156
_astroid_fields = ("elt" , "generators" )
1157
+ _other_other_fields = ("locals" ,)
1158
+
1157
1159
elt = None
1158
1160
"""The element that forms the output of the expression.
1159
1161
1160
1162
:type: NodeNG or None
1161
1163
"""
1164
+
1162
1165
generators = None
1163
1166
"""The generators that are looped through.
1164
1167
1165
1168
:type: list(Comprehension) or None
1166
1169
"""
1167
1170
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
+
1168
1194
def postinit (self , elt = None , generators = None ):
1169
1195
"""Do some setup after initialisation.
1170
1196
@@ -1192,41 +1218,6 @@ def get_children(self):
1192
1218
yield from self .generators
1193
1219
1194
1220
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
-
1230
1221
def _infer_decorator_callchain (node ):
1231
1222
"""Detect decorator call chaining and see if the end result is a
1232
1223
static or a classmethod.
0 commit comments