class Definitions: (source)
Collect definitions used to build a TypeDeclUnit.
Method | __init__ |
Undocumented |
Method | add |
Add an alias or constant. |
Method | add |
Add an import. |
Method | add |
Undocumented |
Method | add |
Undocumented |
Method | build |
Build a pytd.Class from definitions collected from an ast node. |
Method | build |
Return a pytd.TypeDeclUnit for the given defs (plus parser state). |
Method | new |
Return a type for a named tuple (implicitly generates a class). |
Method | new |
Returns a type for a NewType. |
Method | new |
Return the AST for a type. |
Method | new |
Returns a type for a TypedDict. |
Method | resolve |
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 |
Undocumented |
Instance Variable | module |
Undocumented |
Instance Variable | module |
Undocumented |
Instance Variable | paramspec |
Undocumented |
Instance Variable | type |
Undocumented |
Instance Variable | type |
Undocumented |
Method | _add |
Add a type variable definition, `name = TypeName(name, args)`. |
Method | _is |
Undocumented |
Method | _is |
Undocumented |
Method | _is |
Undocumented |
Method | _matches |
Whether t.name matches full_name in format {module}.{member}. |
Method | _matches |
Whether t is a NamedType matching any of names. |
Method | _parameterized |
Return a parameterized type. |
Method | _remove |
Returns a copy of 'parameters' with unsupported features removed. |
Method | _verify |
Raises an error if 'parameters' contains any literal types. |
Add an alias or constant. Args: alias_or_constant: the top-level definition to add. Raises: ParseError: For an invalid __slots__ declaration.
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".
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.
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.
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.
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.