Semantic analysis of types
Class |
|
Undocumented |
Class |
|
See docstring of detect_diverging_alias() for details. |
Class |
|
Undocumented |
Class |
|
Undocumented |
Class |
|
Undocumented |
Class |
|
Undocumented |
Class |
|
Undocumented |
Class |
|
Semantic analyzer for types. |
Class |
|
Find TypeVar and ParamSpec references in an unbound type. |
Function | analyze |
Analyze r.h.s. of a (potential) type alias definition. |
Function | check |
Undocumented |
Function | collect |
Return all types that `t` contains |
Function | detect |
This detects type aliases that will diverge during type checking. |
Function | expand |
Expand a (generic) type alias target following the rules outlined in TypeAlias docstring. |
Function | find |
Undocumented |
Function | fix |
Fix a malformed instance by replacing all type arguments with Any. |
Function | fix |
Recursively fix all instance types (type argument count) in a given type. |
Function | flatten |
Undocumented |
Function | get |
Undocumented |
Function | has |
Return true if this type is Any because an import was not followed. |
Function | has |
Whether this type is or type it contains is an Any coming from explicit type annotation |
Function | make |
Return the type corresponding to Optional[t]. |
Function | no |
Undocumented |
Function | remove |
Undocumented |
Function | set |
Undocumented |
Constant | ARG |
Undocumented |
Constant | GENERIC |
Undocumented |
Constant | SELF |
Undocumented |
Constant | type |
Undocumented |
Type Variable | T |
Undocumented |
Type Alias |
|
Undocumented |
Type
, api: SemanticAnalyzerCoreInterface
, tvar_scope: TypeVarLikeScope
, plugin: Plugin
, options: Options
, is_typeshed_stub: bool
, allow_placeholder: bool
= False, in_dynamic_func: bool
= False, global_scope: bool
= True, allowed_alias_tvars: list[ TypeVarLikeType]|None
= None) -> tuple[ Type, set[ str]]
:
(source)
¶
Analyze r.h.s. of a (potential) type alias definition. If `node` is valid as a type alias rvalue, return the resulting type and a set of full names of type aliases it depends on (directly or indirectly). 'node' must have been semantically analyzed.
Type|None
, options: Options
, is_typeshed_stub: bool
, msg: MessageBuilder
, context: Context
):
(source)
¶
Undocumented
TypeAlias
, target: Type
, lookup: Callable[ [ str, Context], SymbolTableNode|None]
, scope: TypeVarLikeScope
) -> bool
:
(source)
¶
This detects type aliases that will diverge during type checking. For example F = Something[..., F[List[T]]]. At each expansion step this will produce *new* type aliases: e.g. F[List[int]], F[List[List[int]]], etc. So we can't detect recursion. It is a known problem in the literature, recursive aliases and generic types don't always go well together. It looks like there is no known systematic solution yet. # TODO: should we handle such aliases using type_recursion counter and some large limit? They may be handy in rare cases, e.g. to express a union of non-mixed nested lists: Nested = Union[T, Nested[List[T]]] ~> Union[T, List[T], List[List[T]], ...]
TypeAlias
, args: list[ Type]
, fail: MsgCallback
, no_args: bool
, ctx: Context
, *, unexpanded_type: Type|None
= None, disallow_any: bool
= False, use_standard_error: bool
= False) -> Type
:
(source)
¶
Expand a (generic) type alias target following the rules outlined in TypeAlias docstring. Here: target: original target type args: types to be substituted in place of type variables fail: error reporter callback no_args: whether original definition used a bare generic `A = List` ctx: context where expansion happens unexpanded_type, disallow_any, use_standard_error: used to customize error messages
Instance
, fail: MsgCallback
, note: MsgCallback
, disallow_any: bool
, python_version: tuple[ int, int]
, use_generic_error: bool
= False, unexpanded_type: Type|None
= None):
(source)
¶
Fix a malformed instance by replacing all type arguments with Any. Also emit a suitable error if this is not due to implicit Any's.
Type
, fail: MsgCallback
, note: MsgCallback
, python_version: tuple[ int, int]
):
(source)
¶
Recursively fix all instance types (type argument count) in a given type. For example 'Union[Dict, List[str, int]]' will be transformed into 'Union[Dict[Any, Any], List[Any]]' in place.
bool
, fail: MsgCallback
, note: MsgCallback
, orig_type: Type
, python_version: tuple[ int, int]
, fullname: str|None
= None, unexpanded_type: Type|None
= None) -> AnyType
:
(source)
¶
Undocumented
Return true if this type is Any because an import was not followed. If type t is such Any type or has type arguments that contain such Any type this function will return true.
Return the type corresponding to Optional[t]. Note that we can't use normal union simplification, since this function is called during semantic analysis and simplification only works during type checking.
TypeAlias
, newline: int
, newcolumn: int
, *, from_error: bool
= False, disallow_any: bool
= False, fail: MsgCallback|None
= None, unexpanded_type: Type|None
= None) -> Type
:
(source)
¶
Undocumented
Undocumented
Value |
|
Undocumented
Value |
|