home If you program in Python, use pychecker   

If you program in Python, use pychecker – a static code analyzer.

Python is a dynamic language so sometimes trivial typos are only caught when executing code with the typo. It’s especially aggravating when it happens at the end of a long-running process.

Pychecker saves times by finding many such problems by analyzing code, without executing it. And it actually works i.e. finds real problems without too many false positives.

My new best practice is to always run pychecker on a modified piece of code before running it. Saved me many unpleasant surprises.

Pychecker tips

Sadly, some 3rd party packages and even standard python libraries contain code that pychecker flags. Since there’s nothing I can do about it, I silence it with the following bash alias on my mac: alias pychecker='pychecker -b boto,contextlib,zipfile,ftplib'. This line goes into my ~/.bash_profile. As you can probably figure out, -b is a list of modules to ignore in the analysis. Those 4 are modules that caused problems for me in the past.

On Windows I had to modify pychecker.bat to put quotes around the full path to python.exe (since it contained spaces and cmd.exe doesn’t like that). I also copied pychecker.bat to a dir in my %PATH% so that I don’t have to type the full path to execute it.

What pychecker finds

Those are the kinds of bugs that pychecker finds (according to the documentation):

← newer • 631 of 636older →