[TIP] Is it me or Python?

Daniel Knüttel daniel.knuettel at daknuett.eu
Sat Dec 21 01:50:50 PST 2019


Hi Skip,

At first I want to note that inheriting from built-ins is usually not
to recommend, as it can (and will) lead to weird and hard-to-find bugs.

It seems like your particular problem seems to be a bug in CPython and
not your fault. The built-in list's index function for instance has a
valid signature (and the same signature as your own class).
You might want to file a bug report at pylint as the given message is
misleading (there is actually a message that is closer to what would
expect: F0202 method-check-failed). Maybe they will add a new message
for this special case.

Cheers
Daniel

Am Freitag, den 20.12.2019, 17:21 -0600 schrieb Skip Montanaro:
> 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
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
-- 
Daniel Knüttel <daniel.knuettel at daknuett.eu>




More information about the testing-in-python mailing list