Pylint is astatic code checker, meaning it can analyse your code withoutactually running it. Pylint checks for errors, tries to enforce a codingstandard, and tries to enforce a coding style.
A major difference between Pylint andPychecker is that Pylint checks forstyle issues, while Pychecker explicitly does not. There are a few otherdifferences, such as the fact that Pylint does not import live modules whilePychecker does (see6.2 Why does Pychecker catch problems with imports thatPylint doesn’t?).
Pylint’s main author and maintainer for the first ten years of its life has beenSylvain Thénault, while he worked atLogilab where the project was born. For afull list of contributors, see the “Contributors” section of Pylint’s READMEfile.
Everybody knows someone who uses Pylint.
Everything should be explained onhttp://docs.pylint.org/installation
Pylint uses theMercurial distributed version control system. The URL of therepository is:https://bitbucket.org/logilab/pylint. To get the latest version ofPylint from the repository, simply invoke
hg clone https://bitbucket.org/logilab/pylint
Pylint requires the latestastroid. It should becompatible with any Python version greater than 2.7.0.
Since Pylint 1.4, we support only Python 2.7+ and Python 3.3+.Using this strategy really helps in maintaining a code base compatiblewith both versions and from this benefits not only the maintainers,but the end users as well, because it’s easier to add and testnew features.If support for Python 2.6 is absolutely required, then the versionfrom pylint-1.3 branch can be used. It will receive backports ofbug fixes for a while.
Pylint expects the name of a package or module as its argument. As aconvenience,you can give it a file name if it’s possible to guess a module name fromthe file’s path using the python path. Some examples :
“pylint mymodule.py” should always work since the current workingdirectory is automatically added on top of the python path
“pylint directory/mymodule.py” will work if “directory” is a pythonpackage (i.e. has an __init__.py file) or if “directory” is in thepython path.
“pylint /whatever/directory/mymodule.py” will work if either:
- “/whatever/directory” is in the python path
- your cwd is “/whatever/directory”
- “directory” is a python package and “/whatever” is in the pythonpath
- “directory” is a python package and your cwd is “/whatever” and soon...
Analysis data are stored as a pickle file in a directory which islocalized using the following rules:
value of the PYLINTHOME environment variable if set
(not always findable on Windows platforms)
”.pylint.d” directory in the current directory
You can always generate a sample pylintrc file with –generate-rcfileEvery option present on the command line before this will be included inthe rc file
For example:
pylint --disable=bare-except,invalid-name --class-rgx='[A-Z][a-z]+' --generate-rcfile
Much probably. Readhttp://docs.pylint.org/ide-integration
Yes, this feature has been added in Pylint 0.11. This may be done byadding “#pylint: disable=some-message,another-one” at the desired block levelor at the end of the desired line of code
Yes, you can disable or enable (globally disabled) messages at themodule level by adding the corresponding option in a comment at thetop of the file:
# pylint: disable=wildcard-import, method-hidden# pylint: enable=too-many-lines
With Pylint < 0.25, add “#pylint: disable-all” at the beginning of themodule. Pylint 0.26.1 and up have renamed that directive to“#pylint: skip-file” (but the first version will be kept for backwardcompatibility).
In order to ease finding which modules are ignored a Information-level messagefile-ignored is emited. With recent versions of Pylint, if you use the oldsyntax, an additionaldeprecated-disable-all message is emited.
No, starting from 0.25.3, you can use symbolic names for messages:
# pylint: disable=fixme, line-too-long
Prefix (ui) the callback’s name bycb_, as in cb_onclick(...). Bydoing so arguments usage won’t be checked. Another solution is touse one of the names defined in the “dummy-variables” configurationvariable for unused argument (“_” and “dummy” by default).
Pylint uses ConfigParser from the standard library to parse the configurationfile. It means that if you need to disable a lot of messages, you can usetricks like:
# disable wildcard-import, method-hidden and too-many-lines because I do# not want itdisable= wildcard-import, method-hidden, too-many-lines
A class is considered as an abstract class if at least one of itsmethods is doing nothing but raising NotImplementedError.
To do so you have to set the ignore-mixin-members option to“yes” (this is the default value) and to name your mixin class witha name which ends with “mixin” (whatever case).
Even though the final rating Pylint renders is nominally out of ten, there’s nolower bound on it. By default, the formula to calculate score is
10.0-((float(5*error+warning+refactor+convention)/statement)*10)
However, this option can be changed in the Pylint rc file. If having negativevalues really bugs you, you can set the formula to be the maximum of 0 and theabove expression.
Pychecker and Pylint use different approaches. pycheckerimports the modules and rummages around in the result, hence it sees mymangled sys.path. Pylint doesn’t import any of the candidate modules andthus doesn’t include any of import’s side effects (good and bad). Ittraverses an AST representation of the code.
Pylint can crash with this error if you have a string in your analyzedprogram, created by joining a lot of strings with the addition operator.Due to how Pylint works, visiting nodes on a AST tree and due to howthe BinOp node is represented (the node which represents the string ‘1+1’for instance), the same visit method will be called over and over again, leadingto a maximum recursion error. You can alleviate this problem by passingthe flag–optimize-ast=y to Pylint. This will activate an optimizationwhich will transform such AST subtrees into the final resulting string.This flag is off by default. If this is not the case, please report a bug!
A Beginner’s Guide to Code Standards in Python - Pylint Tutorial
Enter search terms or a module, class or function name.