@@ -403,7 +403,7 @@ class MisdesignChecker(BaseChecker):
403
403
)
404
404
405
405
def __init__ (self , linter = None ):
406
- super ().__init__ (linter )
406
+ super ().__init__ (linter , future_option_parsing = True )
407
407
self ._returns = None
408
408
self ._branches = None
409
409
self ._stmts = None
@@ -435,21 +435,22 @@ def _ignored_argument_names(self):
435
435
def visit_classdef (self , node : nodes .ClassDef ) -> None :
436
436
"""Check size of inheritance hierarchy and number of instance attributes."""
437
437
parents = _get_parents (
438
- node , STDLIB_CLASSES_IGNORE_ANCESTOR .union (self .config .ignored_parents )
438
+ node ,
439
+ STDLIB_CLASSES_IGNORE_ANCESTOR .union (self .linter .namespace .ignored_parents ),
439
440
)
440
441
nb_parents = len (parents )
441
- if nb_parents > self .config .max_parents :
442
+ if nb_parents > self .linter . namespace .max_parents :
442
443
self .add_message (
443
444
"too-many-ancestors" ,
444
445
node = node ,
445
- args = (nb_parents , self .config .max_parents ),
446
+ args = (nb_parents , self .linter . namespace .max_parents ),
446
447
)
447
448
448
- if len (node .instance_attrs ) > self .config .max_attributes :
449
+ if len (node .instance_attrs ) > self .linter . namespace .max_attributes :
449
450
self .add_message (
450
451
"too-many-instance-attributes" ,
451
452
node = node ,
452
- args = (len (node .instance_attrs ), self .config .max_attributes ),
453
+ args = (len (node .instance_attrs ), self .linter . namespace .max_attributes ),
453
454
)
454
455
455
456
@check_messages ("too-few-public-methods" , "too-many-public-methods" )
@@ -466,11 +467,11 @@ def leave_classdef(self, node: nodes.ClassDef) -> None:
466
467
# for classes such as unittest.TestCase, which provides
467
468
# a lot of assert methods. It doesn't make sense to warn
468
469
# when the user subclasses TestCase to add his own tests.
469
- if my_methods > self .config .max_public_methods :
470
+ if my_methods > self .linter . namespace .max_public_methods :
470
471
self .add_message (
471
472
"too-many-public-methods" ,
472
473
node = node ,
473
- args = (my_methods , self .config .max_public_methods ),
474
+ args = (my_methods , self .linter . namespace .max_public_methods ),
474
475
)
475
476
476
477
# Stop here if the class is excluded via configuration.
@@ -491,11 +492,11 @@ def leave_classdef(self, node: nodes.ClassDef) -> None:
491
492
# This checks all the methods defined by ancestors and
492
493
# by the current class.
493
494
all_methods = _count_methods_in_class (node )
494
- if all_methods < self .config .min_public_methods :
495
+ if all_methods < self .linter . namespace .min_public_methods :
495
496
self .add_message (
496
497
"too-few-public-methods" ,
497
498
node = node ,
498
- args = (all_methods , self .config .min_public_methods ),
499
+ args = (all_methods , self .linter . namespace .min_public_methods ),
499
500
)
500
501
501
502
@check_messages (
@@ -523,19 +524,21 @@ def visit_functiondef(self, node: nodes.FunctionDef) -> None:
523
524
)
524
525
525
526
argnum = len (args ) - ignored_args_num
526
- if argnum > self .config .max_args :
527
+ if argnum > self .linter . namespace .max_args :
527
528
self .add_message (
528
529
"too-many-arguments" ,
529
530
node = node ,
530
- args = (len (args ), self .config .max_args ),
531
+ args = (len (args ), self .linter . namespace .max_args ),
531
532
)
532
533
else :
533
534
ignored_args_num = 0
534
535
# check number of local variables
535
536
locnum = len (node .locals ) - ignored_args_num
536
- if locnum > self .config .max_locals :
537
+ if locnum > self .linter . namespace .max_locals :
537
538
self .add_message (
538
- "too-many-locals" , node = node , args = (locnum , self .config .max_locals )
539
+ "too-many-locals" ,
540
+ node = node ,
541
+ args = (locnum , self .linter .namespace .max_locals ),
539
542
)
540
543
# init new statements counter
541
544
self ._stmts .append (1 )
@@ -554,26 +557,26 @@ def leave_functiondef(self, node: nodes.FunctionDef) -> None:
554
557
checks for max returns, branch, return in __init__
555
558
"""
556
559
returns = self ._returns .pop ()
557
- if returns > self .config .max_returns :
560
+ if returns > self .linter . namespace .max_returns :
558
561
self .add_message (
559
562
"too-many-return-statements" ,
560
563
node = node ,
561
- args = (returns , self .config .max_returns ),
564
+ args = (returns , self .linter . namespace .max_returns ),
562
565
)
563
566
branches = self ._branches [node ]
564
- if branches > self .config .max_branches :
567
+ if branches > self .linter . namespace .max_branches :
565
568
self .add_message (
566
569
"too-many-branches" ,
567
570
node = node ,
568
- args = (branches , self .config .max_branches ),
571
+ args = (branches , self .linter . namespace .max_branches ),
569
572
)
570
573
# check number of statements
571
574
stmts = self ._stmts .pop ()
572
- if stmts > self .config .max_statements :
575
+ if stmts > self .linter . namespace .max_statements :
573
576
self .add_message (
574
577
"too-many-statements" ,
575
578
node = node ,
576
- args = (stmts , self .config .max_statements ),
579
+ args = (stmts , self .linter . namespace .max_statements ),
577
580
)
578
581
579
582
leave_asyncfunctiondef = leave_functiondef
@@ -625,11 +628,11 @@ def _check_boolean_expressions(self, node):
625
628
if not isinstance (condition , astroid .BoolOp ):
626
629
return
627
630
nb_bool_expr = _count_boolean_expressions (condition )
628
- if nb_bool_expr > self .config .max_bool_expr :
631
+ if nb_bool_expr > self .linter . namespace .max_bool_expr :
629
632
self .add_message (
630
633
"too-many-boolean-expressions" ,
631
634
node = condition ,
632
- args = (nb_bool_expr , self .config .max_bool_expr ),
635
+ args = (nb_bool_expr , self .linter . namespace .max_bool_expr ),
633
636
)
634
637
635
638
def visit_while (self , node : nodes .While ) -> None :
0 commit comments