@@ -619,7 +619,7 @@ def mark_as_consumed(self, name, consumed_nodes):
619
619
else :
620
620
del self .to_consume [name ]
621
621
622
- def get_next_to_consume (self , node ) :
622
+ def get_next_to_consume (self , node : nodes . Name ) -> Optional [ List [ nodes . NodeNG ]] :
623
623
"""Return a list of the nodes that define `node` from this scope. If it is
624
624
uncertain whether a node will be consumed, such as for statements in
625
625
except blocks, add it to self.consumed_uncertain instead of returning it.
@@ -1236,18 +1236,14 @@ def _undefined_and_used_before_checker(
1236
1236
action , found_nodes = self ._check_consumer (
1237
1237
node , stmt , frame , current_consumer , i , base_scope_type
1238
1238
)
1239
-
1240
1239
if action is VariableVisitConsumerAction .CONTINUE :
1241
1240
continue
1242
1241
if action is VariableVisitConsumerAction .CONSUME :
1243
- # pylint: disable-next=fixme
1244
- # TODO: remove assert after _check_consumer return value better typed
1245
- assert found_nodes is not None , "Cannot consume an empty list of nodes."
1246
1242
# Any nodes added to consumed_uncertain by get_next_to_consume()
1247
1243
# should be added back so that they are marked as used.
1248
1244
# They will have already had a chance to emit used-before-assignment.
1249
1245
# We check here instead of before every single return in _check_consumer()
1250
- found_nodes += current_consumer .consumed_uncertain [node .name ]
1246
+ found_nodes += current_consumer .consumed_uncertain [node .name ] # type: ignore[operator]
1251
1247
current_consumer .mark_as_consumed (node .name , found_nodes )
1252
1248
if action in {
1253
1249
VariableVisitConsumerAction .RETURN ,
@@ -1321,7 +1317,16 @@ def _check_consumer(
1321
1317
current_consumer : NamesConsumer ,
1322
1318
consumer_level : int ,
1323
1319
base_scope_type : Any ,
1324
- ) -> Tuple [VariableVisitConsumerAction , Optional [Any ]]:
1320
+ ) -> Union [
1321
+ Tuple [
1322
+ Union [
1323
+ Literal [VariableVisitConsumerAction .CONTINUE ],
1324
+ Literal [VariableVisitConsumerAction .RETURN ],
1325
+ ],
1326
+ None ,
1327
+ ],
1328
+ Tuple [Literal [VariableVisitConsumerAction .CONSUME ], List [nodes .NodeNG ]],
1329
+ ]:
1325
1330
"""Checks a consumer for conditions that should trigger messages"""
1326
1331
# If the name has already been consumed, only check it's not a loop
1327
1332
# variable used outside the loop.
@@ -1354,7 +1359,7 @@ def _check_consumer(
1354
1359
# return a CONSUME action so that _undefined_and_used_before_checker()
1355
1360
# will mark them as used
1356
1361
return (VariableVisitConsumerAction .CONSUME , found_nodes )
1357
- return (VariableVisitConsumerAction .RETURN , found_nodes )
1362
+ return (VariableVisitConsumerAction .RETURN , None )
1358
1363
1359
1364
self ._check_late_binding_closure (node )
1360
1365
0 commit comments