diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2016-12-30 19:24:59 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2016-12-30 19:24:59 +0200 |
commit | 607e2bfcb236faa527a738a84a48434a236fd08d (patch) | |
tree | 90bd30cabb2f896046047d965de4b8995bc0d4e5 /pylint/checkers/classes.py | |
parent | d7ee7d809294685ffb293ed2de909480b38b086a (diff) | |
download | pylint-git-607e2bfcb236faa527a738a84a48434a236fd08d.tar.gz |
Take in consideration the dummy-rgx-variable when checking for different parameters. Close #1041
Diffstat (limited to 'pylint/checkers/classes.py')
-rw-r--r-- | pylint/checkers/classes.py | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py index 4ef6b22d2..85e2eead6 100644 --- a/pylint/checkers/classes.py +++ b/pylint/checkers/classes.py @@ -21,6 +21,7 @@ import six import astroid from astroid.bases import Generator, BUILTINS from astroid.exceptions import InconsistentMroError, DuplicateBasesError +from astroid import decorators from astroid import objects from astroid.scoped_nodes import function_to_method from pylint.interfaces import IAstroidChecker @@ -133,19 +134,22 @@ def _positional_parameters(method): return positional -def _same_parameter(first, second): - return first.name == second.name - +def _has_different_parameters(original, overridden, dummy_parameter_regex): + zipped = six.moves.zip_longest(original, overridden) + for original_param, overridden_param in zipped: + params = (original_param, overridden_param) + if not all(params): + return True -def _has_different_parameters(original, overridden): - same_length = len(original) == len(overridden) - if same_length: - return any(not _same_parameter(first, second) - for first, second in zip(original, overridden)) - return True + names = [param.name for param in params] + if any(map(dummy_parameter_regex.match, names)): + continue + if original_param.name != overridden_param.name: + return True + return False -def _different_parameters(original, overridden): +def _different_parameters(original, overridden, dummy_parameter_regex): """Determine if the two methods have different parameters They are considered to have different parameters if: @@ -162,10 +166,12 @@ def _different_parameters(original, overridden): different_positional = _has_different_parameters( original_parameters, - overridden_parameters) + overridden_parameters, + dummy_parameter_regex) different_kwonly = _has_different_parameters( original.args.kwonlyargs, - overridden.args.kwonlyargs) + overridden.args.kwonlyargs, + dummy_parameter_regex) if original.name in PYMETHODS: # Ignore the difference for special methods. If the parameter # numbers are different, then that is going to be caught by @@ -514,6 +520,16 @@ a metaclass class method.'} self._first_attrs = [] self._meth_could_be_func = None + @decorators.cachedproperty + def _dummy_rgx(self): + return get_global_option( + self, 'dummy-variables-rgx', default=None) + + @decorators.cachedproperty + def _ignore_mixin(self): + return get_global_option( + self, 'ignore-mixin-members', default=True) + def visit_classdef(self, node): """init visit variable _accessed """ @@ -564,9 +580,7 @@ a metaclass class method.'} access to existent members """ # check access to existent members on non metaclass classes - ignore_mixins = get_global_option(self, 'ignore-mixin-members', - default=True) - if ignore_mixins and cnode.name[-5:].lower() == 'mixin': + if self._ignore_mixin and cnode.name[-5:].lower() == 'mixin': # We are in a mixin class. No need to try to figure out if # something is missing, since it is most likely that it will # miss. @@ -1192,7 +1206,9 @@ a metaclass class method.'} decorator.attrname == 'setter'): return - if _different_parameters(refmethod, method1): + if _different_parameters( + refmethod, method1, + dummy_parameter_regex=self._dummy_rgx): self.add_message('arguments-differ', args=(class_type, method1.name), node=method1) |