class NamedTupleAnalyzer: (source)
Undocumented
Method | __init__ |
Undocumented |
Method | analyze |
Analyze if given class definition can be a named tuple definition. |
Method | build |
Undocumented |
Method | check |
Check if a call defines a namedtuple. |
Method | check |
Parse and validate fields in named tuple class definition. |
Method | fail |
Undocumented |
Method | parse |
Parse a namedtuple() call into data needed to construct a type. |
Method | parse |
Parse typed named tuple fields. |
Method | save |
Preserve the generated body of class-based named tuple and then restore it. |
Method | store |
Undocumented |
Instance Variable | api |
Undocumented |
Instance Variable | options |
Undocumented |
ClassDef
, is_stub_file: bool
, is_func_scope: bool
) -> tuple[ bool, TypeInfo|None]
:
(source)
¶
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).
str
, items: list[ str]
, types: list[ Type]
, default_items: Mapping[ str, Expression]
, line: int
, existing_info: TypeInfo|None
) -> TypeInfo
:
(source)
¶
Undocumented
Expression
, var_name: str|None
, is_func_scope: bool
) -> tuple[ str|None, TypeInfo|None, list[ TypeVarLikeType]]
:
(source)
¶
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. Return a tuple of two items: * Internal name of the named tuple (e.g. the name passed as an argument to namedtuple) or None if it is not a valid named tuple * Corresponding TypeInfo, or None if not ready. If the definition is invalid but looks like a namedtuple, report errors but return (some) TypeInfo.
ClassDef
, is_stub_file: bool
) -> tuple[ list[ str], list[ Type], dict[ str, Expression], list[ Statement]]|None
:
(source)
¶
Parse and validate fields in named tuple class definition. Return a four tuple: * field names * field types * field default values * valid statements or None, if any of the types are not ready.
CallExpr
, fullname: str
) -> None|tuple[ list[ str], list[ Type], list[ Expression], str, list[ TypeVarLikeType], bool]
:
(source)
¶
Parse a namedtuple() call into data needed to construct a type. Returns a 6-tuple: - List of argument names - List of argument types - List of default values - First argument of namedtuple - All typevars found in the field definition - Whether all types are ready. Return None if the definition didn't typecheck.
list[ Expression]
, context: Context
) -> tuple[ list[ str], list[ Type], list[ Expression], bool]|None
:
(source)
¶
Parse typed named tuple fields. Return (names, types, defaults, whether types are all ready), or None if error occurred.
def save_namedtuple_body(self, named_tuple_info:
TypeInfo
) -> Iterator[ None]
:
(source)
¶
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).