[Python-projects] Suspicious-lambda checker for pylint
Sylvain Thénault
sylvain.thenault at logilab.fr
Tue Dec 16 17:31:39 CET 2008
Le Monday 15 December 2008 21:36:59 Nathaniel Manista, vous avez écrit :
> Sylvain Thenault & Pylint Team-
> I've written a patch to pylint/checkers/base.py that extends pylint to
> check for "suspicious" lambda expressions of the form "lambda <args>:
> <callee expression>(<args>)". These expressions can almost always be
> replaced with "<callee expression>" (for example, "lambda x,y : min(x,y)"
> should simply be written as "min").
[snip potential false positive explanation]
> I'd like to contribute this code to pylint and am eager to work with
> you toward that end - my choice of terms, warning code (W0108), and of
> which source file is appropriate for it may need to be corrected, for
> example.
humm, I would use a [R]efactor code since this message is indeed suggesting a
refactoring. Regarding the numbering its fine : the two first number (01
here) are for the ckecher which emit the message, while the two last are used
to have a unique message id while grouping "similar" messages in subsequent
number (though that's not really enforced).
> I apologize for not submitting it with "hg email" as is suggested
> on the pylint web site - I'm still learning my way around the basics of hg.
> I also apologize for the lack of a unit test - I could neither find on the
> pylint web site instructions for running the existing tests nor figure out
> on my own how to run them (and extend them).
submitting simple diff is fine as long as the patch is simple and well
targeted, as yours. But not having a test is a problem. Pylint has a simple
functional test system :
* put an input python file into the test/inputs directory
* put a file in the test/messages directory named as your python file but
with '.txt' instead of '.py', containing expected messages
* run the functional tests using "python test_func.py" in the test directory
take a look at other test to see how they isolate the message to test and what
to put in the message file (take care: message order differs from a bare
pylint execution).
I would be happy to include your patch once the test are there as well :)
Cheers,
--
Sylvain Thénault LOGILAB, Paris (France)
Formations Python, Zope, Plone, Debian: http://www.logilab.fr/formations
Développement logiciel sur mesure: http://www.logilab.fr/services
Python et calcul scientifique: http://www.logilab.fr/science
More information about the Python-Projects
mailing list