Checker

Entry point to the app.

Represents a checker business entity. There’s only a single checker instance that runs a lot of visitors.

graph TD C1[Checker] --> V1[Visitor 1] C1[Checker] --> V2[Visitor 2] C1[Checker] --> VN[Visitor N]

Checker relation with visitors.

That’s how all flake8 plugins work:

graph LR F1[flake8] --> F2[add_options] F2 --> F3[parse_options] F3 --> F4[__init__] F4 --> F5[run]

flake8 API calls order.

Checker API

class Checker(tree, file_tokens, filename='stdin')[source]

Bases: object

Implementation of checker.

name

required by the flake8 API, should match the package name.

Type

ClassVar[str]

version

required by the flake8 API, defined in the packaging file.

Type

ClassVar[str]

config

custom configuration object used to provide and parse options:

:class:`wemake_python_styleguide.options.config.Configuration`.
options

option structure passed by flake8:

Type

wemake_python_styleguide.types.ConfigurationOptions

:class:`wemake_python_styleguide.types.ConfigurationOptions`.
visitors

preset of visitors that are run by this checker.

__init__(tree, file_tokens, filename='stdin')[source]

Creates new checker instance.

These parameter names should not be changed. flake8 has special API that passes concrete parameters to the plugins that ask for them.

flake8 also decides how to execute this plugin based on its parameters. This one is executed once per module.

Parameters
  • tree (AST) – ast tree parsed by flake8.

  • file_tokens (Sequence[TokenInfo]) – tokenize.tokenize parsed file tokens.

  • filename (str) – module file name, might be empty if piping is used.

classmethod add_options(parser)[source]

flake8 api method to register new plugin options.

See wemake_python_styleguide.options.config.Configuration docs for detailed options reference.

Parameters

parser (OptionManager) – flake8 option parser instance.

Return type

None

classmethod parse_options(options)[source]

Parses registered options for providing them to each visitor.

Return type

None

run()[source]

Runs the checker.

This method is used by flake8 API. It is executed after all configuration is parsed.

Yields

Violations that were found by the passed visitors.

Return type

Iterator[Tuple[int, int, str, type]]