diff --git a/ChangeLog b/ChangeLog index e782194576..f92c467298 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,10 @@ What's New in Pylint 2.6.1? Release date: TBA +* Fix ``useless-super-delegation`` false positive when default keyword argument is a dictionnary. + + Close #3773 + What's New in Pylint 2.6.0? =========================== diff --git a/doc/whatsnew/2.6.rst b/doc/whatsnew/2.6.rst index 54239d7f35..58eb2076a0 100644 --- a/doc/whatsnew/2.6.rst +++ b/doc/whatsnew/2.6.rst @@ -24,6 +24,8 @@ New checkers Other Changes ============= +* Fix false positive message ``useless-super-delegation`` when default keyword argument is a dictionnary. + * `bad-continuation` and `bad-whitespace` have been removed. `black` or another formatter can help you with this better than Pylint * The `no-space-check` option has been removed, it's no longer possible to consider empty line like a `trailing-whitespace` by using clever options. diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py index bbbd602101..08715d279b 100644 --- a/pylint/checkers/classes.py +++ b/pylint/checkers/classes.py @@ -246,6 +246,7 @@ def _has_different_parameters_default_value(original, overridden): astroid.ClassDef: "name", astroid.Tuple: "elts", astroid.List: "elts", + astroid.Dict: "items", } handled_types = tuple( astroid_type for astroid_type in astroid_type_compared_attr diff --git a/tests/functional/u/useless_super_delegation.py b/tests/functional/u/useless_super_delegation.py index 5cf435b967..002c7eb031 100644 --- a/tests/functional/u/useless_super_delegation.py +++ b/tests/functional/u/useless_super_delegation.py @@ -1,7 +1,7 @@ # pylint: disable=missing-docstring, no-member, no-self-use, bad-super-call # pylint: disable=too-few-public-methods, unused-argument, invalid-name, too-many-public-methods # pylint: disable=line-too-long, useless-object-inheritance, arguments-out-of-order -# pylint: disable=super-with-arguments +# pylint: disable=super-with-arguments, dangerous-default-value def not_a_method(param, param2): return super(None, None).not_a_method(param, param2) @@ -49,6 +49,9 @@ def with_default_argument_int(self, first, default_arg=42): def with_default_argument_tuple(self, first, default_arg=()): pass + def with_default_argument_dict(self, first, default_arg={}): + pass + def with_default_arg_ter(self, first, default_arg="has_been_changed"): super().with_default_arg_ter(first, default_arg) @@ -160,6 +163,10 @@ def with_default_argument_tuple(self, first, default_arg=("42", "a")): # Not useless because the default_arg is different from the one in the base class super(NotUselessSuper, self).with_default_argument_tuple(first, default_arg) + def with_default_argument_dict(self, first, default_arg={'foo': 'bar'}): + # Not useless because the default_arg is different from the one in the base class + super(NotUselessSuper, self).with_default_argument_dict(first, default_arg) + def with_default_argument_bis(self, first, default_arg="default"): # Although the default_arg is the same as in the base class, the call signature # differs. Thus it is not useless. @@ -226,6 +233,9 @@ def with_default_argument_int(self, first, default_arg=42): # [useless-super-del def with_default_argument_tuple(self, first, default_arg=()): # [useless-super-delegation] super(UselessSuper, self).with_default_argument_tuple(first, default_arg) + def with_default_argument_dict(self, first, default_arg={}): # [useless-super-delegation] + super(UselessSuper, self).with_default_argument_dict(first, default_arg) + def __init__(self): # [useless-super-delegation] super(UselessSuper, self).__init__() diff --git a/tests/functional/u/useless_super_delegation.txt b/tests/functional/u/useless_super_delegation.txt index 4426fd125b..94812398f6 100644 --- a/tests/functional/u/useless_super_delegation.txt +++ b/tests/functional/u/useless_super_delegation.txt @@ -1,17 +1,18 @@ -useless-super-delegation:191:UselessSuper.equivalent_params:Useless super delegation in method 'equivalent_params' -useless-super-delegation:194:UselessSuper.equivalent_params_1:Useless super delegation in method 'equivalent_params_1' -useless-super-delegation:197:UselessSuper.equivalent_params_2:Useless super delegation in method 'equivalent_params_2' -useless-super-delegation:200:UselessSuper.equivalent_params_3:Useless super delegation in method 'equivalent_params_3' -useless-super-delegation:203:UselessSuper.equivalent_params_4:Useless super delegation in method 'equivalent_params_4' -useless-super-delegation:206:UselessSuper.equivalent_params_5:Useless super delegation in method 'equivalent_params_5' -useless-super-delegation:209:UselessSuper.equivalent_params_6:Useless super delegation in method 'equivalent_params_6' -useless-super-delegation:212:UselessSuper.with_default_argument:Useless super delegation in method 'with_default_argument' -useless-super-delegation:216:UselessSuper.without_default_argument:Useless super delegation in method 'without_default_argument' -useless-super-delegation:219:UselessSuper.with_default_argument_none:Useless super delegation in method 'with_default_argument_none' -useless-super-delegation:223:UselessSuper.with_default_argument_int:Useless super delegation in method 'with_default_argument_int' -useless-super-delegation:226:UselessSuper.with_default_argument_tuple:Useless super delegation in method 'with_default_argument_tuple' -useless-super-delegation:229:UselessSuper.__init__:Useless super delegation in method '__init__' -useless-super-delegation:232:UselessSuper.with_default_arg:Useless super delegation in method 'with_default_arg' -useless-super-delegation:235:UselessSuper.with_default_arg_bis:Useless super delegation in method 'with_default_arg_bis' -useless-super-delegation:238:UselessSuper.with_default_arg_ter:Useless super delegation in method 'with_default_arg_ter' -useless-super-delegation:241:UselessSuper.with_default_arg_quad:Useless super delegation in method 'with_default_arg_quad' +useless-super-delegation:198:UselessSuper.equivalent_params:Useless super delegation in method 'equivalent_params' +useless-super-delegation:201:UselessSuper.equivalent_params_1:Useless super delegation in method 'equivalent_params_1' +useless-super-delegation:204:UselessSuper.equivalent_params_2:Useless super delegation in method 'equivalent_params_2' +useless-super-delegation:207:UselessSuper.equivalent_params_3:Useless super delegation in method 'equivalent_params_3' +useless-super-delegation:210:UselessSuper.equivalent_params_4:Useless super delegation in method 'equivalent_params_4' +useless-super-delegation:213:UselessSuper.equivalent_params_5:Useless super delegation in method 'equivalent_params_5' +useless-super-delegation:216:UselessSuper.equivalent_params_6:Useless super delegation in method 'equivalent_params_6' +useless-super-delegation:219:UselessSuper.with_default_argument:Useless super delegation in method 'with_default_argument' +useless-super-delegation:223:UselessSuper.without_default_argument:Useless super delegation in method 'without_default_argument' +useless-super-delegation:226:UselessSuper.with_default_argument_none:Useless super delegation in method 'with_default_argument_none' +useless-super-delegation:230:UselessSuper.with_default_argument_int:Useless super delegation in method 'with_default_argument_int' +useless-super-delegation:233:UselessSuper.with_default_argument_tuple:Useless super delegation in method 'with_default_argument_tuple' +useless-super-delegation:236:UselessSuper.with_default_argument_dict:Useless super delegation in method 'with_default_argument_dict' +useless-super-delegation:239:UselessSuper.__init__:Useless super delegation in method '__init__' +useless-super-delegation:242:UselessSuper.with_default_arg:Useless super delegation in method 'with_default_arg' +useless-super-delegation:245:UselessSuper.with_default_arg_bis:Useless super delegation in method 'with_default_arg_bis' +useless-super-delegation:248:UselessSuper.with_default_arg_ter:Useless super delegation in method 'with_default_arg_ter' +useless-super-delegation:251:UselessSuper.with_default_arg_quad:Useless super delegation in method 'with_default_arg_quad'