Types¶
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.
Policy¶
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
final¶
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
Reference¶
- AnyText¶
We use this type to represent all string-like nodes.
alias of
Str
|Bytes
- AnyImport¶
In cases we need to work with both import types.
alias of
Import
|ImportFrom
- AnyFunctionDef¶
In cases we need to work with both function definitions.
alias of
FunctionDef
|AsyncFunctionDef
- AnyFunctionDefAndLambda¶
In cases we need to work with all function definitions (including lambdas).
alias of
FunctionDef
|AsyncFunctionDef
|Lambda
- AnyIf¶
In cases we need to work with both forms of if functions.
alias of
If
|IfExp
- AnyFor¶
In cases we need to work with both sync and async loops.
alias of
For
|AsyncFor
- AnyLoop¶
sync, async, and while.
- Type:
In case we need to work with any loop
alias of
For
|AsyncFor
|While
- AnyVariableDef¶
This is how you can define a variable in Python.
alias of
Name
|Attribute
|ExceptHandler
- AnyComprehension¶
All different comprehension types in one place.
alias of
ListComp
|DictComp
|SetComp
|GeneratorExp
- AnyWith¶
In cases we need to work with both sync and async context managers.
alias of
With
|AsyncWith
- AnyAssign¶
When we search for assign elements, we also need typed assign.
alias of
Assign
|AnnAssign
- AnyAssignWithWalrus¶
When we search for assign elements, we also need typed assign.
alias of
Assign
|AnnAssign
|NamedExpr
- AnyAccess¶
In cases we need to work with both access types.
alias of
Attribute
|Subscript
- AnyChainable¶
In case we need to handle types that can be chained.
alias of
Attribute
|Subscript
|Call
- AnyNodes¶
Tuple of AST node types for declarative syntax.
alias of
Tuple
[Type
[AST
], …]
- AnyTextPrimitive¶
We use this type to work with any text-like values. Related to AnyText.
alias of
str
|bytes
- ContextNodes¶
That’s how we define context of operations.
alias of
Module
|ClassDef
|FunctionDef
|AsyncFunctionDef
- CheckResult¶
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 show_violation_links: bool¶
- property exps_for_one_empty_line: int¶