[Python-projects] Method signature changed by a decorator

Sylvain Thénault sylvain.thenault at logilab.fr
Mon Jan 21 18:12:29 CET 2013


On 14 janvier 16:06, Jean-Michel Pichavant wrote:
> Hello pylint folks,

Hello Jean-Michel,
 
> I have an issue with decorated methods which argument passing is handled by the decorator. I am using the mock.patch (http://www.voidspace.org.uk/python/mock/patch.html) decorator to well ... mock objects. Anyway, pylint keeps complaining about the method not being called with the right argument numbers.
> 
> I can see why it bothers pylint, but I cannot find any workaround apart from disabling the error. I have the feeling there's no better solution since pylint has no idea about what mock.patch does. Any clue ?

This is indeed because pylint doesn't care about mock.patch machinery.
The only way to make it properly working would be to follow this blog: 
http://www.logilab.org/blogentry/78354, then to write a plugin so that
when modules are loaded, it looks for @mock.patch decorated functions/
methods and does appropriate changes to the syntax tree. Such things
could definitly be included in the pylint-brain project 
(https://bitbucket.org/sthenault/pylint-brain).


> To extend my question I had to work quite a lot for my unit tests py files to be properly processed by pylint. Since these unit test files are all about trickery, replacing legit objects by fake ones, I'm starting to wonder if excluding all my py_unit files  from the pylint process wouldn't be the best way to go.

Well, that may actually be a solution. We don't enforce pylint on unittests 
at Logilab, for instance.
-- 
Sylvain Thénault, LOGILAB, Paris (01.45.32.03.12) - Toulouse (05.62.17.16.42)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
CubicWeb, the semantic web framework:    http://www.cubicweb.org



More information about the Python-Projects mailing list