All Unkept
Posted in: Django, Python  —  28 April 2006

pychecker vs pylint vs Django

I just used pychecker on Django and it helpfully found a few bugs. However, it printed a lot of warnings that were wrong, and it obviously has some bugs itself:

.../django/db/models/options.py:134: INTERNAL ERROR -- STOPPED PROCESSING FUNCTION --
        Traceback (most recent call last):
          File "/usr/lib/site-python/pychecker/warn.py", line 222, in _checkFunction
            _findUnreachableCode(code)
          File "/usr/lib/site-python/pychecker/warn.py", line 180, in _findUnreachableCode
            lastLine, lastItem, lastIndex = code.returnValues[-1]
        IndexError: list index out of range

So just how good is pychecker?

$ pychecker pychecker
Processing pychecker...

Warnings...

None

Pretty good -- according to itself! Lets try another experiment:

$ pylint pychecker
************* Module pychecker

[snip 1600 lines]

Global evaluation
-----------------
Your code has been rated at 5.65/10

5.65 out of 10 -- ha! I detect some bias in pychecker's assessment of itself! Why are we even listening to pychecker! pylint is obviously miles better - look:

$ pylint pylint
[snip 100 lines]

Global evaluation
-----------------
Your code has been rated at 9.89/10

Pretty hot! Let's try pylint on Django:

$ pylint django
************* Module django

[snip 7000 lines]

Global evaluation
-----------------
Your code has been rated at 5.19/10

Bummer. That didn't go where I wanted it to. Actually, why I am listening to what some dumb program says about Django? Who appointed pylint as the arbiter of code style: ... Line too long (208/80) ... Too many local variables (23/15) ...? Bah!

On a more serious note, I think pylint (especially pylint | egrep '^E:') has some useful output, though it still makes mistakes. At some point I intend to go through it more carefully. The problem is there is so much of it -- perhaps it would be nice to have a 'pylintdiff' type command - what errors is pylint giving that it didn't last time. I guess that would be a few lines of shell script.

Comments §

§ On 25 June 2007, jiivan wrote: 217
Instead of pylint | egrep '^E:' just use pyflakes. :-)

§ On 14 January 2008, alexandre fayolle wrote: 299

Use pylint -e instead of grepping for ^E it will run much faster.

Also don't hesitate to report what you feel are false positives to the authors of pylint: thats one of the nicest ways to enhance the tool (patches are welcome too)

§ On 31 January 2008, Tim Lesher wrote: 300
> Also don't hesitate to report what you feel are false positives to the authors of pylint

Unfortunately, the project seems to address issues like this very slowly. For example, pylint incorrectly flags "import string" as importing a deprecated module; this was reported three and a half years ago, and it still flags it today. :-/

http://www.logilab.org/email/2258

§ On 12 January 2010, Michael Buckley wrote: 830
No one appointed pylint as the arbiter of code style. That is why it follows higher authorities, namely pep 8 http://www.python.org/dev/peps/pep-0008/

Yes I know this post is old.

Add comment

Format:

  • Javascript has to be on to get past my spam protection, and cookies, and there is a delay, sorry for any inconvenience!
  • I reserve the right to moderate comments.