18

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 :)

Joshua
  • 181
  • 1
  • 3

2 Answers2

15

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
  • 364,293
  • 75
  • 561
  • 662
  • Aah I see. I have not looked at the reports that deeply, I agree. It was the rating that surprised me! – Joshua Jul 28 '10 at 18:16
8

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
  • 13,247
  • 4
  • 43
  • 57
  • There are also plenty of cases where following PyLint suggestions with the default configuration will make your code _harder_ to understand. If you find yourself making code less readable to satisfy PyLint, that's a good sign that you should be tweaking the PyLint settings. The default settings are very strict; this is reasonable because disabling things is more obvious than enabling them. – cjs Mar 06 '18 at 02:59