Do you use an python code analyzer?

January 16th, 2008 § 18 comments

I’ve got a ques­tion out there for every­one doing Python hack­ing — does your nor­mal cod­ing cycle include an analy­sis tool ala Pylint/PyChecker/PyFlakes?

Do you just rely on intel­li­gence in your IDE of choise (Wing, Komodo, Eclipse+PyDev)?

Do you feel the need for the ana­lyz­ers, or do you “dis­card” them in favor of writ­ing unit tests/doctests first (per­son­ally I don’t find the two exclude one another) to ver­ify func­tion­al­ity over “correctness”.

Which (if any) do you pre­fer? Do you setup auto­matic check-in triggers?

Or, do you really take the conformity-to-style-and-rules-correctness to a higher level and auto-pipe checked in code through a Python­Tidy?

  • http://www.voidspace.org.uk/python/weblog/index.shtml Michael Foord

    At Resolver we do TDD. We also have a PyLint step in our build that will fail if PyLint reports cer­tain errors.

    The errors we are par­tic­u­larly inter­ested in are:

    Unused imports
    Unused vari­ables
    Miss­ing (i.e. mis­spelt) vari­ables
    Shad­ow­ing built-ins
    Redefin­ing methods/functions

    Some of these our tests would nor­mally catch any­way — but unused imports and vari­ables is par­tic­u­larly useful.

  • Matt

    I’m try­ing to get bet­ter about using PyLint as a reg­u­lar check on my code. I’ve heard of PyChecker and PyFlakes, but I got the impres­sion those were more for actu­ally incor­rect code rather than styl­is­tic issues, and my code cov­er­age in unit tests is pretty good so I have less of a need for them.

    (As a note, Bran­don Corf­man has a plu­gin to inte­grate PyLint with Komodo, which is how I use it.)

  • http://www.ohuiginn.net Dan

    pylint, all the way. It’s caught quite a few sub­tle bugs that might not have been picked up dur­ing test­ing. Things like notic­ing when a func­tion can return dif­fer­ent vari­able types, or you’re inad­ver­tently over­writ­ing global or builtin vari­ables. And it plays nicely with vim, so it takes almost no time to check code.

    I usu­ally turn off a lot of the more anal checks of for­mat­ting style, though, espe­cially when I’m deal­ing with other people’s code

  • Pete

    I love me some pychecker and pyflakes. I really wish some­thing sim­ple and sta­tic like pyflakes could get rolled into the Python stan­dard libraries. I’m sad to see it has fallen out of devel­op­ment recently.

    These tools are not part of my “day to day”, but run­ning them over my code­base once in awhile always finds errant cor­ner cases.

    9 times out of 10 the prob­lems these find are in my error han­dling code.

  • Bran­don Corfman

    Yes, pylint –e (report­ing errors only) is part of my cod­ing cycle, when­ever I’ve made a bunch of sig­nif­i­cant addi­tions or changes to my code. It helps weed out many of my ini­tial run­time errors. I’ve got it plugged into my Komodo toolbox.

  • http://gedmin.as Mar­ius Gedminas

    Some of these tools (e.g. pychecker) get really con­fused by Zope 3 stuff, so I can’t use them. I’ve a self-written script that checks for unused imports. I rely on unit tests to catch syn­tax errors. And yes, there’s a build­bot instance that runs all tests on every checkin, then pro­duces nightly test suite code cov­er­age reports plus the above-mentioned unused import checker reports.

  • http://kentsjohnson.com Kent

    I use PyFlakes from Text­Mate for a few rea­sons:
    - It helps me to clean up the imports (remove unused imports)
    - it helps find spelling mis­takes and syn­tax errors quickly

    I do write unit tests but I don’t have tests for every­thing and PyFlakes is just another tool to help me write good code.

  • http://kentsjohnson.com Kent

    I use PyFlakes from Text­Mate for a few rea­sons:
    - It helps me to clean up the imports (remove unused imports)
    - it helps find spelling mis­takes and syn­tax errors quickly

    I do write unit tests but I don’t have tests for every­thing and PyFlakes is just another tool to help me write good code.

  • Jeff McNeil

    We’ve actu­ally got it tied into our build­bot sys­tem. Every com­mit is going to trig­ger a build which runs PyChecker, our unit test suites, and finally a Figleaf cov­er­age scan. If code cov­er­age drops below 90%, we fail that step.

    I find that it’s most help­ful in catch­ing prob­lems with quick updates, such as those done with vim Fri­day after­noon at 4:30.

  • Jeff

    komodo and unit tests dur­ing ini­tial design and devel­op­ment, pylint and scite dur­ing refactoring

  • Ed Page

    I recently cre­ated a Make­file that will find all python scripts and make a pyc (basic syn­tax check), doctest, pychecker, pep8, and give warn­ings for @todo’s and errors for @bug. Once I have full unit tests setup I’ll add that to it also.

    I’d like to use some­thing like scons instead of Make but the next gen build sys­tems seem odd for these cus­tom jobs.

  • jnoller

    That’s fan­tas­tic com­bi­na­tion of ideas, and hav­ing them all auto­mated is nice.

  • jnoller

    For style, there’s also PEP8.py http://svn.browsershots.org/trunk/devtools/pep8

  • http://pyblog.drbrett.ca Brett

    Never use them. =) Although I might if pychecker or some­thing ever got inte­grated into the stdlib. But I don’t see that hap­pen­ing any time soon since I don’t think any of the tools use the AST directly yet.

  • Jay

    pylint + fly­makes (Emacs). It runs pylint as you type and high­lights errors and warn­ings. Cuts down sig­nif­i­cantly on save/run cycles to catch syn­tax errors. I don’t know how I lived with­out it.

    My only com­plaint would be some­times it high­lights things I don’t care about but I haven’t fig­ured out the pylin­trc con­fig­u­ra­tion com­pletely. But that’s just my own fault. As long as you set your inden­tion the false neg­a­tives aren’t too bad.

  • Paul Hilde­brandt

    We require devel­op­ers to pylint their code on our project. I tried pycheck and pylint and liked pylint bet­ter. I like PEP8.py but I don’t think I could get the guys here to use it. I do use Eclipse+PyDev (the com­mer­cial ver­sion, well worth the money). I still run pylint along­side it’s check­ers. I want to start­ing run­ning figleaf to check out cov­er­age on our unittest but I just haven’t started that yet.

  • Zachary Voase

    I actu­ally enforce my own good cod­ing stan­dards in my code at write-time. Apart from that, pylint is very use­ful at find­ing cer­tain seman­tic errors and ensur­ing that my code con­forms to some very strict standards.

  • Zachary Voase

    I actu­ally enforce my own good cod­ing stan­dards in my code at write-time. Apart from that, pylint is very use­ful at find­ing cer­tain seman­tic errors and ensur­ing that my code con­forms to some very strict standards.

What's this?

You are currently reading Do you use an python code analyzer? at jessenoller.com.

meta

  • Categories

  • Recent Posts