This module contains knowledge about the most important types that we use.

There are also different visitor specific types that are defined and use exclusively in that file.


If any of the following statements is true, move the type to this file:

  • if type is used in multiple files

  • if type is complex enough it has to be documented

  • if type is very important for the public API


As you can see in the source code almost everything is marked as @final or Final.

It means that this value cannot be subclassed or reassigned. This it only a mypy feature, it does not affect python runtime.

We do this, because we value composition over inheritance. And this @final decorators help you to define readable and clear APIs for cases when inheritance is used.

See also

My guide about @final type in python: https://sobolevn.me/2018/07/real-python-contants



We use this type to represent all string-like nodes.

alias of Str | Bytes


In cases we need to work with both import types.

alias of Import | ImportFrom


In cases we need to work with both function definitions.

alias of FunctionDef | AsyncFunctionDef


In cases we need to work with all function definitions (including lambdas).

alias of FunctionDef | AsyncFunctionDef | Lambda


In cases we need to work with both forms of if functions.

alias of If | IfExp


In cases we need to work with both sync and async loops.

alias of For | AsyncFor


sync, async, and while.


In case we need to work with any loop

alias of For | AsyncFor | While


This is how you can define a variable in Python.

alias of Name | Attribute | ExceptHandler


All different comprehension types in one place.

alias of ListComp | DictComp | SetComp | GeneratorExp


In cases we need to work with both sync and async context managers.

alias of With | AsyncWith


When we search for assign elements, we also need typed assign.

alias of Assign | AnnAssign


When we search for assign elements, we also need typed assign.

alias of Assign | AnnAssign | NamedExpr


In cases we need to work with both access types.

alias of Attribute | Subscript


In case we need to handle types that can be chained.

alias of Attribute | Subscript | Call


Tuple of AST node types for declarative syntax.

alias of Tuple[Type[AST], …]


We use this type to work with any text-like values. Related to AnyText.

alias of str | bytes


That’s how we define context of operations.

alias of Module | ClassDef | FunctionDef | AsyncFunctionDef


Flake8 API format to return error messages.

alias of Tuple[int, int, str, type]

class ConfigurationOptions(*args, **kwargs)[source]

Bases: Protocol

Provides structure for the options we use in our checker and visitors.

Then this protocol is passed to each individual visitor. It uses structural sub-typing, and does not represent any kind of a real class or structure.

We use @property decorator here instead of regular attributes, because we need to explicitly mark these atrtibutes as read-only.

property min_name_length: int
property i_control_code: bool
property max_name_length: int
property max_noqa_comments: int
property nested_classes_whitelist: Tuple[str, ...]
property forbidden_inline_ignore: Tuple[str, ...]
property allowed_domain_names: Tuple[str, ...]
property forbidden_domain_names: Tuple[str, ...]
property max_arguments: int
property max_local_variables: int
property max_returns: int
property max_expressions: int
property max_module_members: int
property max_methods: int
property max_line_complexity: int
property max_jones_score: int
property max_imports: int
property max_imported_names: int
property max_base_classes: int
property max_decorators: int
property max_string_usages: int
property max_awaits: int
property max_try_body_length: int
property max_module_expressions: int
property max_function_expressions: int
property max_asserts: int
property max_access_level: int
property max_attributes: int
property max_raises: int
property max_cognitive_score: int
property max_cognitive_average: int
property max_call_level: int
property max_annotation_complexity: int
property max_import_from_members: int
property max_tuple_unpack_length: int
property exps_for_one_empty_line: int