tags:

views:

92

answers:

2

Hey everyone!

A friend told me about Pylint and just out of curiosity, I ran it against some of the standard library modules. To my surprise, the ratings were low. Here are a few runs:

os.py
Your code has been rated at 3.55/10 

random.py
Your code has been rated at 4.74/10

I ran it on some more modules and the found the rating to be ~ 6 - 7.

I was wondering the reason behind this? Is Pylint broken or there are more factors to the rating than I am aware of? I am asking this question particularly cause I am new to Python and was depending on Pylint to help me improve my coding style :)

+5  A: 

Pylint's defaults are quite strict, and complain about things they should not. For example, if you use foo(**kwargs), you get a message about using "magic". Sometimes it seems as if pylint is looking at Python from a Java programmer's point of view.

You'd have to look at the specific messages and decide if you agree with them.

Other problems include not being able to do platform-specific conditionals. In os.py, it complains:

F:119: Unable to import 'riscos'
Ned Batchelder
Aah I see. I have not looked at the reports that deeply, I agree. It was the rating that surprised me!
Joshua
A: 

Pylint was written long after the stdlib. And the stdlib does not adhere to strict naming conventions for instance (PEP008 is recent, wrt python). Key factors for getting "good" pylint ratings:

  • make sure your code writing style is conform to what Pylint is expecting (or tune Pylint to match your style / conventions). This includes function, variables, class, method names, spaces at various places, etc.

  • write Python code in an as static as convenient way, and avoid dynamic tricks.

  • write docstrings

Obviously, the standard library is not written to optimize Pylint's ratings of the modules.

Using Pylint will not necessarily improve your "coding style". It will however in a number of cases make your code more easy to understand, sometimes at the cost of some "pythonicity".

gurney alex