summaryrefslogtreecommitdiff
path: root/checkers
diff options
context:
space:
mode:
authorSylvain Thénault <sylvain.thenault@logilab.fr>2010-02-23 13:34:44 +0100
committerSylvain Thénault <sylvain.thenault@logilab.fr>2010-02-23 13:34:44 +0100
commite8e8fd80f2787933494f67a9140c1710940e04ca (patch)
treeb6bb31a833da2dcca7a0cb315594576cdbe33dbd /checkers
parent80de460a54880671b51bb1eaa519c64b20b01755 (diff)
downloadpylint-git-e8e8fd80f2787933494f67a9140c1710940e04ca.tar.gz
implement #5564: ignore function / methode arguments with leading "_".
* "ignored-argument-names" have been added to options in order to set the regexp that recognizes the ignored arguments. * func_too_many_locals_arguments.(py, txt) have been added to test "too many arguments" and "too many local variables" features.
Diffstat (limited to 'checkers')
-rw-r--r--checkers/design_analysis.py26
1 files changed, 22 insertions, 4 deletions
diff --git a/checkers/design_analysis.py b/checkers/design_analysis.py
index 8ff64080a..cfc81c303 100644
--- a/checkers/design_analysis.py
+++ b/checkers/design_analysis.py
@@ -25,6 +25,11 @@ from logilab.astng import Function, If, InferenceError
from pylint.interfaces import IASTNGChecker
from pylint.checkers import BaseChecker
+import re
+
+# regexp for ignored argument name
+IGNORED_ARGUMENT_NAMES = re.compile('_.*')
+
def class_is_abstract(klass):
"""return true if the given class node should be considered as an abstract
class
@@ -92,6 +97,12 @@ class MisdesignChecker(BaseChecker):
{'default' : 5, 'type' : 'int', 'metavar' : '<int>',
'help': 'Maximum number of arguments for function / method'}
),
+ ('ignored-argument-names',
+ {'default' : IGNORED_ARGUMENT_NAMES,
+ 'type' :'regexp', 'metavar' : '<regexp>',
+ 'help' : 'Argument names that match this expression will be '
+ 'ignored. Default to name with leading underscore'}
+ ),
('max-locals',
{'default' : 15, 'type' : 'int', 'metavar' : '<int>',
'help': 'Maximum number of locals for function / method body'}
@@ -240,11 +251,18 @@ class MisdesignChecker(BaseChecker):
self._branchs.append(0)
# check number of arguments
args = node.args.args
- if args is not None and len(args) > self.config.max_args:
- self.add_message('R0913', node=node,
- args=(len(args), self.config.max_args))
+ if args is not None:
+ ignored_args_num = len(
+ [arg for arg in args
+ if self.config.ignored_argument_names.match(arg.name)])
+ argnum = len(args) - ignored_args_num
+ if argnum > self.config.max_args:
+ self.add_message('R0913', node=node,
+ args=(len(args), self.config.max_args))
+ else:
+ ignored_args_num = 0
# check number of local variables
- locnum = len(node.locals)
+ locnum = len(node.locals) - ignored_args_num
if locnum > self.config.max_locals:
self.add_message('R0914', node=node,
args=(locnum, self.config.max_locals))