Skip to content
Niayesh Ilkhani edited this page Oct 29, 2016 · 2 revisions

Intro to Pylint

Pylint is a static analysis tool used for linting code for syntax and style errors. Its versatile and open-source nature makes it both easy to use and easy to extend. Python TA is a custom setup of pylint that has written new checkers, reporters, and configuration in the pylint style.

For more information about the pylint system, see the page for individual elements of pylint:

How Pylint Works

Usually you call Pylint from the command line, which means you do something like:

> pylint --option-1 --option-2 <module to check>

And this makes a call to __main__.py, which calls pylint.run_pylint() (inside __init__.py). run_pylint then calls pylint.lint.Run(sys.argv[1:]), where sys.argv[1:] is every command line argument except the call to pylint itself. Unless only calling pylint for information, the last element of sys.argv is the module or filename to be linted. Run in turn loads up the PyLinter:

  • Pre-processing (command line): the init-hook (standalone Python code), rcfile, and load-plugins command line options are processed first, because following parts of the program may be dependent on them. preprocess_options searches the arguments from argv for those three options, and calls their associated callback functions (as defined by Run) to load the values from argv into variables used by the linter.
  • Initialising PyLinter: Call PyLinter.__init__ with a series of "external" options (and option groups), as well as the rcfile found.
    • PyLinter then adds to this list of options and option groups, and amongst its other tasks (several relating to checkers and reporters), initialises OptionsManagerMixIn with the path to the pylintrc file.
  • Reading into the linter: Register all checkers, plugins, help documents, etc. Then run read_config_file() (an OptionsManagerMixIn method) on the linter to read and record (but not run) the options in the pylintrc file.
    • OptionsManagerMixIn is responsible for handling configurations (from both command line and pylintrc). Its read_config_file method uses a ConfigParser to read the pylintrc file, which stores the sections, keys, and values from the file in _sections.
  • Pre-processing (config file): As before when pre-processing the command line options, the config file can have init-hook and load-plugins options that must be executed before any other options.
  • Loading the linter: Call OptionsManagerMixIn.load_config_file() to set each option up.
    • load_config_file adds every registered/read option to the list of options to be followed when the linter is linting.
  • Loading command line options: Alter configuration based on command line arguments using load_command_line_configurations(args).

Other Info

  • Default pylint sections: ['MASTER', 'MESSAGES CONTROL', 'REPORTS', 'BASIC', 'ELIF', 'FORMAT', 'LOGGING', 'MISCELLANEOUS', 'SIMILARITIES', 'SPELLING', 'TYPECHECK', 'VARIABLES', 'CLASSES', 'DESIGN', 'IMPORTS', 'EXCEPTIONS']
  • Current PyTA sections: ['ELIF', 'FORMAT', 'FORBIDDEN IMPORT', 'FORBIDDEN IO', 'MESSAGES CONTROL']
Clone this wiki locally