Pylint: My new favourite static code analyser for Python

I spent most of yesterday evening playing around with Pylint, a static analysis tool that reads your source code and looks for common mistakes. I found a lot.

You can find Pylint in the Sabayon repositories, so it can be installed with a simple equo install pylint and then you’re off.

Running Pylint over a random module, the first thing that surprised me was just how much information the application provides. The first thing it gives you is a line-by-line list of issues – this tells you exactly what problems your code has, and where these problems are. In my case, the vast majority of these were Convention and Warning types, indicating that I really do need to clean up my Python coding style.

It then provides a number of reports which gives you a stack of metrics by which to measure the quality of your code. These were interesting, but would probably be more useful if I was running Pylint over a larger source file.

The approach I found most useful was to go through the list of issues and, for the obvious ones, just fix them. For less obvious issues, I found myself going to the Python documentation to understand why the issue had been raised and what was wrong with my existing approach.

There is a lot of documentation available for Pylint and a goodly set of configuration options. I have looked at neither so far because the reports that it generates are so self-explanatory that it is very easy to jump right in.

This is a tool I can see myself using for a long time to come and, as codebases grow, this is a tool that will become increasingly useful.

One thought on “Pylint: My new favourite static code analyser for Python

Comments are closed.