class NamedTupleAnalyzer: (source)
Undocumented
Method | __init__ |
Undocumented |
Method | analyze_namedtuple_classdef |
Analyze if given class definition can be a named tuple definition. |
Method | build_namedtuple_typeinfo |
Undocumented |
Method | check_namedtuple |
Check if a call defines a namedtuple. |
Method | check_namedtuple_classdef |
Parse and validate fields in named tuple class definition. |
Method | fail |
Undocumented |
Method | parse_namedtuple_args |
Parse a namedtuple() call into data needed to construct a type. |
Method | parse_namedtuple_fields_with_types |
Parse typed named tuple fields. |
Method | save_namedtuple_body |
Preserve the generated body of class-based named tuple and then restore it. |
Method | store_namedtuple_info |
Undocumented |
Instance Variable | api |
Undocumented |
Instance Variable | options |
Undocumented |
Analyze if given class definition can be a named tuple definition.
Return a tuple where first item indicates whether this can possibly be a named tuple, and the second item is the corresponding TypeInfo (may be None if not ready and should be deferred).
Parameters | |
defn:ClassDef | Undocumented |
is_stub_file:bool | Undocumented |
Returns | |
Tuple[ | Undocumented |
Undocumented
Parameters | |
name:str | Undocumented |
items:List[ | Undocumented |
types:List[ | Undocumented |
default_items:Mapping[ | Undocumented |
line:int | Undocumented |
Returns | |
TypeInfo | Undocumented |
Check if a call defines a namedtuple.
The optional var_name argument is the name of the variable to which this is assigned, if any.
If the definition is invalid but looks like a namedtuple, report errors but return (some) TypeInfo.
Parameters | |
node:Expression | Undocumented |
var_name:Optional[ | Undocumented |
is_func_scope:bool | Undocumented |
Returns | |
Tuple[ | Undocumented |
Parse and validate fields in named tuple class definition.
or None, if any of the types are not ready.
Parameters | |
defn:ClassDef | Undocumented |
is_stub_file:bool | Undocumented |
Returns | |
Optional[ | Undocumented |
Parse a namedtuple() call into data needed to construct a type.
Returns a 5-tuple: - List of argument names - List of argument types - List of default values - First argument of namedtuple - Whether all types are ready.
Return None if the definition didn't typecheck.
Parameters | |
call:CallExpr | Undocumented |
fullname:str | Undocumented |
Returns | |
Optional[ | Undocumented |
Parse typed named tuple fields.
Return (names, types, defaults, whether types are all ready), or None if error occurred.
Parameters | |
nodes:List[ | Undocumented |
context:Context | Undocumented |
Returns | |
Optional[ | Undocumented |
Preserve the generated body of class-based named tuple and then restore it.
Temporarily clear the names dict so we don't get errors about duplicate names that were already set in build_namedtuple_typeinfo (we already added the tuple field names while generating the TypeInfo, and actual duplicates are already reported).
Parameters | |
named_tuple_info:TypeInfo | Undocumented |
Returns | |
Iterator[ | Undocumented |