Pylint: Pylint gives a false positive when an override method changes the argument names

Created on 18 Aug 2017  路  7Comments  路  Source: PyCQA/pylint

Steps to reproduce

Lint this code:

import json
class MyJsonEncoder(json.JSONEncoder):
    # pylint: disable=method-hidden
    # See https://github.com/PyCQA/pylint/issues/414 for reference
    def default(self, obj) -> str:
        return super().default(obj)

Current behavior

W:  5, 4: Parameters differ from overridden 'default' method (arguments-differ)

Expected behavior

No warning

pylint --version output

pylint 1.7.2, 
astroid 1.5.3
Python 3.6.2 (default, Jul 20 2017, 03:52:27) 
[GCC 7.1.1 20170630]
bug

Most helpful comment

Why do you consider this a false positive? Renaming arguments means that as a user I could no longer do something like

encoder = MyEncoder()
kwargs = {'o': to_encode}
encoder.default(**kwargs)

In my opinion, the message is correct and arguments should not be renamed.

All 7 comments

Still present with

pylint 1.8.1, 
astroid 1.6.0
Python 2.7.14 (default, Sep 25 2017, 09:53:22) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)]

Present with:

pylint 1.8.4, 
astroid 1.6.3
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609]

Hey folks! Just wanted to say that I'm aware that this bug hasn't been fixed yet.

Why do you consider this a false positive? Renaming arguments means that as a user I could no longer do something like

encoder = MyEncoder()
kwargs = {'o': to_encode}
encoder.default(**kwargs)

In my opinion, the message is correct and arguments should not be renamed.

Ashley is right here. I'm not sure why we argue that pylint is emitting incorrectly this message when technically it is correct, the parameter has a different name.

And encoder.default(o=to_encode) would cease to work too. Thanks :)

I have another example of the original issue where I don't think it's so clear that pylint is justified in complaining.

Consider:

class A:
    def method_x(self, **kwargs: Any):
        pass

class B(A):
    def method_x(self, *, foo: Optional[Any] = None, **kwargs: Any):
        pass

I would argue that since the signature for B.method_X is subsumed by A.method_X; indeed the set of valid inputs for each is identical, it should be acceptable. However pylint 2.5.3 disagrees.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

z4y4ts picture z4y4ts  路  3Comments

thanatos picture thanatos  路  3Comments

mrginglymus picture mrginglymus  路  3Comments

adamtheturtle picture adamtheturtle  路  3Comments

glmdgrielson picture glmdgrielson  路  3Comments