class documentation

class TypedDictAnalyzer: (source)

View In Hierarchy

Undocumented

Method __init__ Undocumented
Method analyze​_typeddict​_classdef Analyze a class that may define a TypedDict.
Method analyze​_typeddict​_classdef​_fields Analyze fields defined in a TypedDict class definition.
Method build​_typeddict​_typeinfo Undocumented
Method check​_typeddict Check if a call defines a TypedDict.
Method fail Undocumented
Method fail​_typeddict​_arg Undocumented
Method is​_typeddict Undocumented
Method note Undocumented
Method parse​_typeddict​_args Parse typed dict call expression.
Method parse​_typeddict​_fields​_with​_types Parse typed dict items passed as pairs (name expression, type expression).
Instance Variable api Undocumented
Instance Variable msg Undocumented
Instance Variable options Undocumented
def __init__(self, options, api, msg): (source)

Undocumented

Parameters
options:OptionsUndocumented
api:SemanticAnalyzerInterfaceUndocumented
msg:MessageBuilderUndocumented
def analyze_typeddict_classdef(self, defn): (source)

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).
Parameters
defn:ClassDefUndocumented
Returns
Tuple[bool, Optional[TypeInfo]]Undocumented
def analyze_typeddict_classdef_fields(self, defn, oldfields=None): (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
  • Set of required keys
Parameters
defn:ClassDefUndocumented
oldfields:Optional[List[str]]Undocumented
Returns
Tuple[Optional[List[str]], List[Type], Set[str]]Undocumented
def build_typeddict_typeinfo(self, name, items, types, required_keys, line): (source)

Undocumented

Parameters
name:strUndocumented
items:List[str]Undocumented
types:List[Type]Undocumented
required​_keys:Set[str]Undocumented
line:intUndocumented
Returns
TypeInfoUndocumented
def check_typeddict(self, node, var_name, is_func_scope): (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).

Parameters
node:ExpressionUndocumented
var​_name:Optional[str]Undocumented
is​_func​_scope:boolUndocumented
Returns
Tuple[bool, Optional[TypeInfo]]Undocumented
def fail(self, msg, ctx, *, code=None): (source)

Undocumented

Parameters
msg:strUndocumented
ctx:ContextUndocumented
code:Optional[ErrorCode]Undocumented
def fail_typeddict_arg(self, message, context): (source)

Undocumented

Parameters
message:strUndocumented
context:ContextUndocumented
Returns
Tuple[str, List[str], List[Type], bool, bool]Undocumented
def is_typeddict(self, expr): (source)

Undocumented

Parameters
expr:ExpressionUndocumented
Returns
boolUndocumented
def note(self, msg, ctx): (source)

Undocumented

Parameters
msg:strUndocumented
ctx:ContextUndocumented
def parse_typeddict_args(self, call): (source)

Parse typed dict call expression.

Return names, types, totality, was there an error during parsing. If some type is not ready, return None.

Parameters
call:CallExprUndocumented
Returns
Optional[Tuple[str, List[str], List[Type], bool, bool]]Undocumented
def parse_typeddict_fields_with_types(self, dict_items, context): (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.

Parameters
dict​_items:List[Tuple[Optional[Expression], Expression]]Undocumented
context:ContextUndocumented
Returns
Optional[Tuple[List[str], List[Type], bool]]Undocumented

Undocumented

Undocumented

options = (source)

Undocumented