class TypedDictAnalyzer: (source)
Undocumented
Method | __init__ |
Undocumented |
Method | add |
Undocumented |
Method | analyze |
Analyze arguments of base type expressions as types. |
Method | analyze |
Analyze a class that may define a TypedDict. |
Method | analyze |
Analyze fields defined in a TypedDict class definition. |
Method | build |
Undocumented |
Method | check |
Check if a call defines a TypedDict. |
Method | fail |
Undocumented |
Method | fail |
Undocumented |
Method | is |
Undocumented |
Method | map |
Map item types to how they would look in their base with type arguments applied. |
Method | note |
Undocumented |
Method | parse |
Parse typed dict call expression. |
Method | parse |
Parse typed dict items passed as pairs (name expression, type expression). |
Instance Variable | api |
Undocumented |
Instance Variable | msg |
Undocumented |
Instance Variable | options |
Undocumented |
Options
, api: SemanticAnalyzerInterface
, msg: MessageBuilder
):
(source)
¶
Undocumented
Expression
, keys: list[ str]
, types: list[ Type]
, required_keys: set[ str]
, ctx: Context
):
(source)
¶
Undocumented
Analyze arguments of base type expressions as types. We need to do this, because normal base class processing happens after the TypedDict special-casing (plus we get a custom error message).
Analyze a class that may define a TypedDict. Assume that base classes have been analyzed already. Note: Unlike normal classes, we won't create a TypeInfo until the whole definition of the TypeDict (including the body and all key names and types) is complete. This is mostly because we store the corresponding TypedDictType in the TypeInfo. Return (is this a TypedDict, new TypeInfo). Specifics: * If we couldn't finish due to incomplete reference anywhere in the definition, return (True, None). * If this is not a TypedDict, return (False, None).
ClassDef
, oldfields: list[ str]|None
= None) -> tuple[ list[ str]|None, list[ Type], list[ Statement], set[ str]]
:
(source)
¶
Analyze fields defined in a TypedDict class definition. This doesn't consider inherited fields (if any). Also consider totality, if given. Return tuple with these items: * List of keys (or None if found an incomplete reference --> deferral) * List of types for each key * List of statements from defn.defs.body that are legally allowed to be a part of a TypedDict definition * Set of required keys
str
, items: list[ str]
, types: list[ Type]
, required_keys: set[ str]
, line: int
, existing_info: TypeInfo|None
) -> TypeInfo
:
(source)
¶
Undocumented
Expression
, var_name: str|None
, is_func_scope: bool
) -> tuple[ bool, TypeInfo|None, list[ TypeVarLikeType]]
:
(source)
¶
Check if a call defines a TypedDict. The optional var_name argument is the name of the variable to which this is assigned, if any. Return a pair (is it a typed dict, corresponding TypeInfo). If the definition is invalid but looks like a TypedDict, report errors but return (some) TypeInfo. If some type is not ready, return (True, None).
str
, context: Context
) -> tuple[ str, list[ str], list[ Type], bool, list[ TypeVarLikeType], bool]
:
(source)
¶
Undocumented
dict[ str, Type]
, tvars: list[ TypeVarLikeType]
, base_args: list[ Type]
) -> dict[ str, Type]
:
(source)
¶
Map item types to how they would look in their base with type arguments applied. We would normally use expand_type() for such task, but we can't use it during semantic analysis, because it can (indirectly) call is_subtype() etc., and it will crash on placeholder types. So we hijack replace_alias_tvars() that was initially intended to deal with eager expansion of generic type aliases during semantic analysis.
CallExpr
) -> tuple[ str, list[ str], list[ Type], bool, list[ TypeVarLikeType], bool]|None
:
(source)
¶
Parse typed dict call expression. Return names, types, totality, was there an error during parsing. If some type is not ready, return None.
list[ tuple[ Expression|None, Expression]]
, context: Context
) -> tuple[ list[ str], list[ Type], bool]|None
:
(source)
¶
Parse typed dict items passed as pairs (name expression, type expression). Return names, types, was there an error. If some type is not ready, return None.