[TIP] Is it me or Python?

Skip Montanaro skip.montanaro at gmail.com
Fri Dec 20 15:21:52 PST 2019


I can't see what I'm doing wrong here. The environment is Python 3.7.4
& pylint 2.4.4 via Conda (just updated a few minutes ago), Ubuntu
18.04LTS. When I run pylint against the attached file, I get this
output:

% pylint pylintnit.py
************* Module pylintnit
pylintnit.py:7: [W0221(arguments-differ), UniqueQueue.index]
Parameters differ from overridden 'index' method

This was abstracted from a slightly more complete example of
overriding the collections.deque class. As far as I can tell from
reading the docs and inspecting the underlying _collectionsmodule.c
code, I've got the method's signature right. It takes a required
offset (variously given as "value" or "x" depending on what you're
reading) and optional start and stop arguments which default to None.
The pylint declaration of the W0221 key/value pair shows that it
should only be checking the number of arguments, not the names (I
think).

    "W0221": (
        "Parameters differ from %s %r method",
        "arguments-differ",
        "Used when a method has a different number of arguments than in "
        "the implemented interface or in an overridden method.",
    ),

If I use inspect to display the signatures of the two versions of the
index method, I get:

>>> print(inspect.signature(pylintnit.UniqueQueue.index))
(self, value, start=None, stop=None)
>>> print(inspect.signature(collections.deque.index))
Traceback (most recent call last):
...
ValueError: no signature found for builtin <method 'index' of
'collections.deque' objects>

which suggests to me that pylint is sort of doing the right thing, but
blaming me for the problem, when it should probably more correctly
point its finger at the signature-free C version of the index method.

Have I got that more-or-less correct? If so, I can fiddle with the
signature of the overridden C version of index() and file a CPython
bug report.

Thanks,

Skip Montanaro
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pylintnit.py
Type: text/x-python
Size: 201 bytes
Desc: not available
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20191220/b25a8a2d/attachment.py>


More information about the testing-in-python mailing list