Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyLint Best Practices?

Pylint looks like a good tool for running analysis of Python code.

However, our main objective is to catch any potential bugs and not coding conventions. Enabling all Pylint checks seems to generate a lot of noise. What is the set of Pylint features you use and is effective?

like image 979
amit Avatar asked Dec 09 '10 06:12

amit


People also ask

What is Pylint used for?

Pylint is a static code analysis tool for the Python programming language. It is named following a common convention in Python of a "py" prefix, and a nod to the C programming lint program. It follows the style recommended by PEP 8, the Python style guide.

Is Pylint a linter?

Pylint is a really well-known linter for Python, like I said earlier. Pylint has a number of very useful features.

What is a good Pylint score?

It comes with a handy metric, the Pylint score: you get a 10/10 for perfectly conforming to the standard, less it you stray from it. With this handy metric, increasing code quality, and making sure the most people will be able to read it in the future, is simple: we just need to increase the pylint score!


1 Answers

You can block any warnings/errors you don't like, via:

pylint --disable=error1,error2

I've blocked the following (description from http://www.logilab.org/card/pylintfeatures):

W0511: Used when a warning note as FIXME or XXX is detected

W0142: Used * or * magic*. Used when a function or method is called using *args or **kwargs to dispatch arguments. This doesn't improve readability and should be used with care.

W0141: Used builtin function %r. Used when a black listed builtin function is used (see the bad-function option). Usual black listed functions are the ones like map, or filter, where Python offers now some cleaner alternative like list comprehension.

R0912: Too many branches (%s/%s). Used when a function or method has too many branches, making it hard to follow.

R0913: Too many arguments (%s/%s). Used when a function or method takes too many arguments.

R0914: Too many local variables (%s/%s). Used when a function or method has too many local variables.

R0903: Too few public methods (%s/%s). Used when class has too few public methods, so be sure it's really worth it.

W0212: Access to a protected member %s of a client class. Used when a protected member (i.e. class member with a name beginning with an underscore) is access outside the class or a descendant of the class where it's defined.

W0312: Found indentation with %ss instead of %ss. Used when there are some mixed tabs and spaces in a module.

C0111: Missing docstring. Used when a module, function, class or method has no docstring. Some special methods like __init__ don't necessarily require a docstring.

C0103: Invalid name "%s" (should match %s). Used when the name doesn't match the regular expression associated to its type (constant, variable, class...).

like image 72
muckabout Avatar answered Sep 23 '22 09:09

muckabout