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 can not 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¶
-
AnyImport
= typing.Union[_ast.Import, _ast.ImportFrom]¶ In cases we need to work with both import types.
-
AnyFunctionDef
= typing.Union[_ast.FunctionDef, _ast.AsyncFunctionDef]¶ In cases we need to work with both function definitions.
-
AnyFunctionDefAndLambda
= typing.Union[_ast.FunctionDef, _ast.AsyncFunctionDef, _ast.Lambda]¶ In cases we need to work with all function definitions (including lambdas).
-
AnyIf
= typing.Union[_ast.If, _ast.IfExp]¶ In cases we need to work with both forms of if functions
-
CheckResult
¶ alias of
typing.Tuple
-
AnyNodes
¶ alias of
typing.Tuple
-
AnyUnaryOp
= typing.Union[typing.Type[_ast.Invert], typing.Type[_ast.Not], typing.Type[_ast.UAdd], typing.Type[_ast.USub]]¶ In cases we need to work with all unary operators
-
class
ConfigurationOptions
(*args, **kwargs)[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.