class documentation

class Definitions: (source)

View In Hierarchy

Collect definitions used to build a TypeDeclUnit.

Method __init__ Undocumented
Method add_alias_or_constant Add an alias or constant.
Method add_import Add an import.
Method add_param_spec Undocumented
Method add_type_var Undocumented
Method build_class Build a pytd.Class from definitions collected from an ast node.
Method build_type_decl_unit Return a pytd.TypeDeclUnit for the given defs (plus parser state).
Method new_named_tuple Return a type for a named tuple (implicitly generates a class).
Method new_new_type Returns a type for a NewType.
Method new_type Return the AST for a type.
Method new_typed_dict Returns a type for a TypedDict.
Method resolve_type Return the fully resolved name for an alias.
Constant ELLIPSIS Undocumented
Instance Variable aliases Undocumented
Instance Variable all Undocumented
Instance Variable constants Undocumented
Instance Variable generated_classes Undocumented
Instance Variable module_info Undocumented
Instance Variable module_path_map Undocumented
Instance Variable paramspec_names Undocumented
Instance Variable type_map Undocumented
Instance Variable type_params Undocumented
Method _add_type_variable Add a type variable definition, `name = TypeName(name, args)`.
Method _is_builtin_or_typing_member Undocumented
Method _is_empty_tuple Undocumented
Method _is_heterogeneous_tuple Undocumented
Method _matches_full_name Whether t.name matches full_name in format {module}.{member}.
Method _matches_named_type Whether t is a NamedType matching any of names.
Method _parameterized_type Return a parameterized type.
Method _remove_unsupported_features Returns a copy of 'parameters' with unsupported features removed.
Method _verify_no_literal_parameters Raises an error if 'parameters' contains any literal types.
def __init__(self, module_info): (source)

Undocumented

def add_alias_or_constant(self, alias_or_constant): (source)

Add an alias or constant. Args: alias_or_constant: the top-level definition to add. Raises: ParseError: For an invalid __slots__ declaration.

def add_import(self, from_package, import_list): (source)

Add an import. Args: from_package: A dotted package name if this is a "from" statement, or None if it is an "import" statement. import_list: A list of imported items, which are either strings or pairs of strings. Pairs are used when items are renamed during import using "as".

def add_param_spec(self, name, tvar): (source)

Undocumented

def add_type_var(self, name, tvar): (source)

Undocumented

def build_class(self, class_name, bases, keywords, decorators, defs) -> pytd.Class: (source)

Build a pytd.Class from definitions collected from an ast node.

def build_type_decl_unit(self, defs) -> pytd.TypeDeclUnit: (source)

Return a pytd.TypeDeclUnit for the given defs (plus parser state).

def new_named_tuple(self, base_name, fields): (source)

Return a type for a named tuple (implicitly generates a class). Args: base_name: The named tuple's name. fields: A list of (name, type) tuples. Returns: A NamedType() for the generated class that describes the named tuple.

def new_new_type(self, name, typ): (source)

Returns a type for a NewType.

def new_type(self, name: Union[str, pytd_node.Node], parameters: Optional[List[pytd.Type]] = None) -> pytd.Type: (source)

Return the AST for a type. Args: name: The name of the type. parameters: List of type parameters. Returns: A pytd type node. Raises: ParseError: if the wrong number of parameters is supplied for the base_type - e.g., 2 parameters to Optional or no parameters to Union.

def new_typed_dict(self, name, items, total): (source)

Returns a type for a TypedDict. This method is currently called only for TypedDict objects defined via the following function-based syntax: Foo = TypedDict('Foo', {'a': int, 'b': str}, total=False) rather than the recommended class-based syntax. Args: name: the name of the TypedDict instance, e.g., "'Foo'". items: a {key: value_type} dict, e.g., {"'a'": "int", "'b'": "str"}. total: A tuple of a single kwarg, e.g., ("total", NamedType("False")), or None when no kwarg is passed.

def resolve_type(self, name: Union[str, pytd_node.Node]) -> pytd.Type: (source)

Return the fully resolved name for an alias. Args: name: The name of the type or alias. Returns: A pytd.NamedType with the fully resolved and qualified name.

ELLIPSIS = (source)

Undocumented

Value
types.Ellipsis()

Undocumented

Undocumented

constants: list = (source)

Undocumented

generated_classes = (source)

Undocumented

module_info = (source)

Undocumented

module_path_map: dict = (source)

Undocumented

paramspec_names = (source)

Undocumented

type_map: Dict[str, Any] = (source)

Undocumented

type_params: list = (source)

Undocumented

def _add_type_variable(self, name, tvar, typename, pytd_type): (source)

Add a type variable definition, `name = TypeName(name, args)`.

def _is_builtin_or_typing_member(self, t): (source)

Undocumented

def _is_empty_tuple(self, t): (source)

Undocumented

def _is_heterogeneous_tuple(self, t): (source)

Undocumented

def _matches_full_name(self, t, full_name): (source)

Whether t.name matches full_name in format {module}.{member}.

def _matches_named_type(self, t, names): (source)

Whether t is a NamedType matching any of names.

def _parameterized_type(self, base_type: Any, parameters): (source)

Return a parameterized type.

def _remove_unsupported_features(self, parameters): (source)

Returns a copy of 'parameters' with unsupported features removed.

def _verify_no_literal_parameters(self, base_type, parameters): (source)

Raises an error if 'parameters' contains any literal types.