2
2
import ast
3
3
from ast import iter_child_nodes
4
4
from collections import deque
5
- from collections .abc import Iterable
5
+ from collections .abc import Iterable , Sequence
6
6
from fnmatch import fnmatchcase
7
7
from functools import partial
8
8
from itertools import chain
@@ -170,7 +170,7 @@ def visit_tree(self, node, parents: deque):
170
170
yield from self .visit_tree (child , parents )
171
171
parents .pop ()
172
172
173
- def visit_node (self , node , parents : Iterable ):
173
+ def visit_node (self , node , parents : Sequence ):
174
174
if isinstance (node , ast .ClassDef ):
175
175
self .tag_class_functions (node )
176
176
elif isinstance (node , FUNC_NODES ):
@@ -266,14 +266,14 @@ class ClassNameCheck(BaseASTCheck):
266
266
N818 = "exception name '{name}' should be named with an Error suffix"
267
267
268
268
@classmethod
269
- def get_classdef (cls , name , parents : Iterable ):
269
+ def get_classdef (cls , name , parents : Sequence ):
270
270
for parent in parents :
271
271
for node in parent .body :
272
272
if isinstance (node , ast .ClassDef ) and node .name == name :
273
273
return node
274
274
275
275
@classmethod
276
- def superclass_names (cls , name , parents : Iterable , _names = None ):
276
+ def superclass_names (cls , name , parents : Sequence , _names = None ):
277
277
names = _names or set ()
278
278
classdef = cls .get_classdef (name , parents )
279
279
if not classdef :
@@ -284,7 +284,7 @@ def superclass_names(cls, name, parents: Iterable, _names=None):
284
284
names .update (cls .superclass_names (base .id , parents , names ))
285
285
return names
286
286
287
- def visit_classdef (self , node , parents : Iterable , ignored : NameSet ):
287
+ def visit_classdef (self , node , parents : Sequence , ignored : NameSet ):
288
288
name = node .name
289
289
if name in ignored :
290
290
return
@@ -319,7 +319,7 @@ def has_override_decorator(node):
319
319
return True
320
320
return False
321
321
322
- def visit_functiondef (self , node , parents : Iterable , ignored : NameSet ):
322
+ def visit_functiondef (self , node , parents : Sequence , ignored : NameSet ):
323
323
function_type = getattr (node , 'function_type' , _FunctionType .FUNCTION )
324
324
name = node .name
325
325
if name in ignored :
@@ -350,7 +350,7 @@ class FunctionArgNamesCheck(BaseASTCheck):
350
350
N804 = "first argument of a classmethod should be named 'cls'"
351
351
N805 = "first argument of a method should be named 'self'"
352
352
353
- def visit_functiondef (self , node , parents : Iterable , ignored : NameSet ):
353
+ def visit_functiondef (self , node , parents : Sequence , ignored : NameSet ):
354
354
args = node .args .posonlyargs + node .args .args + node .args .kwonlyargs
355
355
356
356
# Start by applying checks that are specific to the first argument.
@@ -395,7 +395,7 @@ class ImportAsCheck(BaseASTCheck):
395
395
N814 = "camelcase '{name}' imported as constant '{asname}'"
396
396
N817 = "camelcase '{name}' imported as acronym '{asname}'"
397
397
398
- def visit_importfrom (self , node , parents : Iterable , ignored : NameSet ):
398
+ def visit_importfrom (self , node , parents : Sequence , ignored : NameSet ):
399
399
for name in node .names :
400
400
asname = name .asname
401
401
if not asname :
@@ -427,7 +427,7 @@ class VariablesCheck(BaseASTCheck):
427
427
N815 = "variable '{name}' in class scope should not be mixedCase"
428
428
N816 = "variable '{name}' in global scope should not be mixedCase"
429
429
430
- def _find_errors (self , assignment_target , parents : Iterable , ignored : NameSet ):
430
+ def _find_errors (self , assignment_target , parents : Sequence , ignored : NameSet ):
431
431
for parent_func in reversed (parents ):
432
432
if isinstance (parent_func , ast .ClassDef ):
433
433
checker = self .class_variable_check
@@ -455,36 +455,36 @@ def is_namedtupe(node_value):
455
455
return True
456
456
return False
457
457
458
- def visit_assign (self , node , parents : Iterable , ignored : NameSet ):
458
+ def visit_assign (self , node , parents : Sequence , ignored : NameSet ):
459
459
if self .is_namedtupe (node .value ):
460
460
return
461
461
for target in node .targets :
462
462
yield from self ._find_errors (target , parents , ignored )
463
463
464
- def visit_namedexpr (self , node , parents : Iterable , ignored : NameSet ):
464
+ def visit_namedexpr (self , node , parents : Sequence , ignored : NameSet ):
465
465
if self .is_namedtupe (node .value ):
466
466
return
467
467
yield from self ._find_errors (node .target , parents , ignored )
468
468
469
469
visit_annassign = visit_namedexpr
470
470
471
- def visit_with (self , node , parents : Iterable , ignored : NameSet ):
471
+ def visit_with (self , node , parents : Sequence , ignored : NameSet ):
472
472
for item in node .items :
473
473
yield from self ._find_errors (
474
474
item .optional_vars , parents , ignored )
475
475
476
476
visit_asyncwith = visit_with
477
477
478
- def visit_for (self , node , parents : Iterable , ignored : NameSet ):
478
+ def visit_for (self , node , parents : Sequence , ignored : NameSet ):
479
479
yield from self ._find_errors (node .target , parents , ignored )
480
480
481
481
visit_asyncfor = visit_for
482
482
483
- def visit_excepthandler (self , node , parents : Iterable , ignored : NameSet ):
483
+ def visit_excepthandler (self , node , parents : Sequence , ignored : NameSet ):
484
484
if node .name :
485
485
yield from self ._find_errors (node , parents , ignored )
486
486
487
- def visit_generatorexp (self , node , parents : Iterable , ignored : NameSet ):
487
+ def visit_generatorexp (self , node , parents : Sequence , ignored : NameSet ):
488
488
for gen in node .generators :
489
489
yield from self ._find_errors (gen .target , parents , ignored )
490
490
@@ -513,7 +513,7 @@ class TypeVarNameCheck(BaseASTCheck):
513
513
N808 = "type variable name '{name}' should use CapWords convention " \
514
514
"and an optional '_co' or '_contra' suffix"
515
515
516
- def visit_module (self , node , parents : Iterable , ignored : NameSet ):
516
+ def visit_module (self , node , parents : Sequence , ignored : NameSet ):
517
517
for body in node .body :
518
518
try :
519
519
if len (body .targets ) != 1 :
0 commit comments