From daniel.knuettel at daknuett.eu Fri Dec 20 05:15:32 2019 From: daniel.knuettel at daknuett.eu (Daniel =?ISO-8859-1?Q?Kn=FCttel?=) Date: Fri, 20 Dec 2019 14:15:32 +0100 Subject: [TIP] pytest-cov: Sanitize file paths Message-ID: Hi folks, I use pytest-cov to generate coverage reports that I want to upload to codacy to analyze them there. As I have to build and install the module first, pytest-cov puts the path of the installed module in front of the actual file path: /home/daniel/.envs/pyqcs/lib/python3.7/site-packages/pyqcs-1.1.2-py3.7-linux-x86_64.egg/pyqcs/__init__.py Codacy rejects those coverage reports, as it cannot match the file paths. Is there a way to tell pytest-cov to sanitize the output, i.e. use just pyqcs/__init__.py? Cheers, Daniel PS: I didn't find a way to test for memory leaks in C extensions yet. -- Daniel Kn?ttel From skip.montanaro at gmail.com Fri Dec 20 15:21:52 2019 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Fri, 20 Dec 2019 17:21:52 -0600 Subject: [TIP] Is it me or Python? Message-ID: 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 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: From daniel.knuettel at daknuett.eu Sat Dec 21 01:50:50 2019 From: daniel.knuettel at daknuett.eu (Daniel =?ISO-8859-1?Q?Kn=FCttel?=) Date: Sat, 21 Dec 2019 10:50:50 +0100 Subject: [TIP] Is it me or Python? In-Reply-To: References: Message-ID: <59f31bcd8b49d7e9549965c636cef3770ba01263.camel@daknuett.eu> 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 '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