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 Union[_ast.Str, _ast.Bytes]
-
AnyImport
¶ In cases we need to work with both import types.
alias of Union[_ast.Import, _ast.ImportFrom]
-
AnyFunctionDef
¶ In cases we need to work with both function definitions.
alias of Union[_ast.FunctionDef, _ast.AsyncFunctionDef]
-
AnyFunctionDefAndLambda
¶ In cases we need to work with all function definitions (including lambdas).
alias of Union[_ast.FunctionDef, _ast.AsyncFunctionDef, _ast.Lambda]
-
AnyIf
¶ In cases we need to work with both forms of if functions.
alias of Union[_ast.If, _ast.IfExp]
-
AnyFor
¶ In cases we need to work with both sync and async loops.
alias of Union[_ast.For, _ast.AsyncFor]
-
AnyLoop
¶ sync, async, and while.
- Type
In case we need to work with any loop
alias of Union[_ast.For, _ast.AsyncFor, _ast.While]
-
AnyVariableDef
¶ This is how you can define a variable in Python.
alias of Union[_ast.Name, _ast.Attribute, _ast.ExceptHandler]
-
AnyComprehension
¶ All different comprehension types in one place.
alias of Union[_ast.ListComp, _ast.DictComp, _ast.SetComp, _ast.GeneratorExp]
-
AnyWith
¶ In cases we need to work with both sync and async context managers.
alias of Union[_ast.With, _ast.AsyncWith]
-
AnyAssign
¶ When we search for assign elements, we also need typed assign.
alias of Union[_ast.Assign, _ast.AnnAssign]
-
AnyAccess
¶ In cases we need to work with both access types.
alias of Union[_ast.Attribute, _ast.Subscript]
-
AnyChainable
¶ In case we need to handle types that can be chained.
alias of Union[_ast.Attribute, _ast.Subscript, _ast.Call]
-
AnyNodes
¶ Tuple of AST node types for declarative syntax.
alias of Tuple[Type[_ast.AST], …]
-
AnyTextPrimitive
¶ We use this type to work with any text-like values. Related to AnyText.
alias of Union[str, bytes]
-
ContextNodes
¶ That’s how we define context of operations.
alias of Union[_ast.Module, _ast.ClassDef, _ast.FunctionDef, _ast.AsyncFunctionDef]
-
CheckResult
¶ Flake8 API format to return error messages.
alias of Tuple[int, int, str, type]
-
class
ConfigurationOptions
(*args, **kwds)[source]¶ Bases:
typing_extensions.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
¶ - Return type
int
-
property
i_control_code
¶ - Return type
bool
-
property
max_name_length
¶ - Return type
int
-
property
max_noqa_comments
¶ - Return type
int
-
property
nested_classes_whitelist
¶ - Return type
Tuple
[str
, …]
-
property
forbidden_inline_ignore
¶ - Return type
Tuple
[str
, …]
-
property
allowed_domain_names
¶ - Return type
Tuple
[str
, …]
-
property
forbidden_domain_names
¶ - Return type
Tuple
[str
, …]
-
property
max_arguments
¶ - Return type
int
-
property
max_local_variables
¶ - Return type
int
-
property
max_returns
¶ - Return type
int
-
property
max_expressions
¶ - Return type
int
-
property
max_module_members
¶ - Return type
int
-
property
max_methods
¶ - Return type
int
-
property
max_line_complexity
¶ - Return type
int
-
property
max_jones_score
¶ - Return type
int
-
property
max_imports
¶ - Return type
int
-
property
max_imported_names
¶ - Return type
int
-
property
max_base_classes
¶ - Return type
int
-
property
max_decorators
¶ - Return type
int
-
property
max_string_usages
¶ - Return type
int
-
property
max_awaits
¶ - Return type
int
-
property
max_try_body_length
¶ - Return type
int
-
property
max_module_expressions
¶ - Return type
int
-
property
max_function_expressions
¶ - Return type
int
-
property
max_asserts
¶ - Return type
int
-
property
max_access_level
¶ - Return type
int
-
property
max_attributes
¶ - Return type
int
-
property
max_raises
¶ - Return type
int
-
property
max_cognitive_score
¶ - Return type
int
-
property
max_cognitive_average
¶ - Return type
int
-
property
max_call_level
¶ - Return type
int
-
property
max_annotation_complexity
¶ - Return type
int
-
property
max_import_from_members
¶ - Return type
int
-
property
max_tuple_unpack_length
¶ - Return type
int
-
property