41
41
from pylint .lint import PyLinter
42
42
from pylint .typing import MessageDefinitionTuple
43
43
44
+ Consumption = dict [str , list [nodes .NodeNG ]]
45
+
44
46
45
47
SPECIAL_OBJ = re .compile ("^_{2}[a-z]+_{2}$" )
46
48
FUTURE = "__future__"
@@ -261,7 +263,7 @@ def _infer_name_module(node: nodes.Import, name: str) -> Generator[InferenceResu
261
263
262
264
263
265
def _fix_dot_imports (
264
- not_consumed : dict [ str , list [ nodes . NodeNG ]]
266
+ not_consumed : Consumption ,
265
267
) -> list [tuple [str , _base_nodes .ImportNode ]]:
266
268
"""Try to fix imports with multiple dots, by returning a dictionary
267
269
with the import names expanded.
@@ -533,9 +535,9 @@ def _has_locals_call_after_node(stmt: nodes.NodeNG, scope: nodes.FunctionDef) ->
533
535
class ScopeConsumer (NamedTuple ):
534
536
"""Store nodes and their consumption states."""
535
537
536
- to_consume : dict [ str , list [ nodes . NodeNG ]]
537
- consumed : dict [ str , list [ nodes . NodeNG ]]
538
- consumed_uncertain : defaultdict [ str , list [ nodes . NodeNG ]]
538
+ to_consume : Consumption
539
+ consumed : Consumption
540
+ consumed_uncertain : Consumption
539
541
scope_type : str
540
542
541
543
@@ -573,15 +575,15 @@ def __iter__(self) -> Iterator[Any]:
573
575
return iter (self ._atomic )
574
576
575
577
@property
576
- def to_consume (self ) -> dict [ str , list [ nodes . NodeNG ]] :
578
+ def to_consume (self ) -> Consumption :
577
579
return self ._atomic .to_consume
578
580
579
581
@property
580
- def consumed (self ) -> dict [ str , list [ nodes . NodeNG ]] :
582
+ def consumed (self ) -> Consumption :
581
583
return self ._atomic .consumed
582
584
583
585
@property
584
- def consumed_uncertain (self ) -> defaultdict [ str , list [ nodes . NodeNG ]] :
586
+ def consumed_uncertain (self ) -> Consumption :
585
587
"""Retrieves nodes filtered out by get_next_to_consume() that may not
586
588
have executed.
587
589
@@ -3171,7 +3173,7 @@ def _check_module_attrs(
3171
3173
def _check_all (
3172
3174
self ,
3173
3175
node : nodes .Module ,
3174
- not_consumed : dict [ str , list [ nodes . NodeNG ]] ,
3176
+ not_consumed : Consumption ,
3175
3177
) -> None :
3176
3178
try :
3177
3179
assigned = next (node .igetattr ("__all__" ))
@@ -3226,7 +3228,7 @@ def _check_all(
3226
3228
# when the file will be checked
3227
3229
pass
3228
3230
3229
- def _check_globals (self , not_consumed : dict [ str , nodes . NodeNG ] ) -> None :
3231
+ def _check_globals (self , not_consumed : Consumption ) -> None :
3230
3232
if self ._allow_global_unused_variables :
3231
3233
return
3232
3234
for name , node_lst in not_consumed .items ():
@@ -3236,7 +3238,7 @@ def _check_globals(self, not_consumed: dict[str, nodes.NodeNG]) -> None:
3236
3238
self .add_message ("unused-variable" , args = (name ,), node = node )
3237
3239
3238
3240
# pylint: disable = too-many-branches
3239
- def _check_imports (self , not_consumed : dict [ str , list [ nodes . NodeNG ]] ) -> None :
3241
+ def _check_imports (self , not_consumed : Consumption ) -> None :
3240
3242
local_names = _fix_dot_imports (not_consumed )
3241
3243
checked = set ()
3242
3244
unused_wildcard_imports : defaultdict [
@@ -3328,7 +3330,7 @@ def _check_imports(self, not_consumed: dict[str, list[nodes.NodeNG]]) -> None:
3328
3330
3329
3331
def _check_metaclasses (self , node : nodes .Module | nodes .FunctionDef ) -> None :
3330
3332
"""Update consumption analysis for metaclasses."""
3331
- consumed : list [tuple [dict [ str , list [ nodes . NodeNG ]] , str ]] = []
3333
+ consumed : list [tuple [Consumption , str ]] = []
3332
3334
3333
3335
for child_node in node .get_children ():
3334
3336
if isinstance (child_node , nodes .ClassDef ):
@@ -3343,12 +3345,12 @@ def _check_classdef_metaclasses(
3343
3345
self ,
3344
3346
klass : nodes .ClassDef ,
3345
3347
parent_node : nodes .Module | nodes .FunctionDef ,
3346
- ) -> list [tuple [dict [ str , list [ nodes . NodeNG ]] , str ]]:
3348
+ ) -> list [tuple [Consumption , str ]]:
3347
3349
if not klass ._metaclass :
3348
3350
# Skip if this class doesn't use explicitly a metaclass, but inherits it from ancestors
3349
3351
return []
3350
3352
3351
- consumed : list [tuple [dict [ str , list [ nodes . NodeNG ]] , str ]] = []
3353
+ consumed : list [tuple [Consumption , str ]] = []
3352
3354
metaclass = klass .metaclass ()
3353
3355
name = ""
3354
3356
if isinstance (klass ._metaclass , nodes .Name ):
0 commit comments