Internal representation of pytd nodes. All pytd nodes should be frozen attrs inheriting from node.Node (aliased to Node in this module). Nodes representing types should also inherit from Type. Since we use frozen classes, setting attributes in __post_init__ needs to be done via object.__setattr__(self, 'attr', value) NOTE: The way we introspect on the types of the fields requires forward references to be simple classes, hence use x: Union['Foo', 'Bar'] rather than x: 'Union[Foo, Bar]'
Class |
|
An alias (symbolic link) for a class implemented in some other module. |
Class |
|
Undocumented |
Class |
|
A type we know nothing about yet (? in pytd). |
Class |
|
Special generic type for a Callable that specifies its argument types. |
Class |
|
Represents a class declaration. |
Class |
|
A type specified through an existing class node. |
Class |
|
Concatenate params and ParamSpec. |
Class |
|
Undocumented |
Class |
|
A function or a method, defined by one or more PyTD signatures. |
Class |
|
Generic type. Takes a base type and type parameters. |
Class |
|
An intersection type. |
Class |
|
A type we have yet to resolve. |
Class |
|
Undocumented |
Class |
|
Undocumented |
Class |
|
Undocumented |
Class |
|
A module imported into the current module, possibly with an alias. |
Class |
|
A type specified by name and, optionally, the module it is in. |
Class |
|
An "impossible" type, with no instances (nothing in pytd). |
Class |
|
Represents a parameter of a function definition. |
Class |
|
Undocumented |
Class |
|
ParamSpec is a specific case of TypeParameter. |
Class |
|
ParamSpec.args special form. |
Class |
|
ParamSpec.kwargs special form. |
Class |
|
Represents an individual signature of a function. |
Class |
|
Represents template name for generic types. |
Class |
|
Special generic type for heterogeneous tuples. |
Class |
|
Each type class below should inherit from this mixin. |
Class |
|
Module node. Holds module contents (constants / classes / functions). |
Class |
|
Represents a type parameter. |
Class |
|
A union type that contains all types in self.type_list. |
Function |
|
Returns method func with its signature modified as if it has been aliased. |
Function |
|
Checks whether class t is a container. |
Function |
|
Recursively look up name in module. |
Function |
|
Convert a pytd AST item into a type. |
Constant | GENERIC |
Undocumented |
Constant | SINGLETON |
Undocumented |
Class | _ |
Super class for shared behavior of UnionType and IntersectionType. |
Function | _ |
Helper function for _SetOfTypes initialization. |
Type Variable | _ |
Undocumented |
Returns method func with its signature modified as if it has been aliased. Args: func: A pytd.Function. from_constant: If True, func will be modified as if it has been aliased from an instance of its defining class, e.g., class Foo: def func(self): ... const = ... # type: Foo func = const.func Otherwise, it will be modified as if aliased from the class itself: class Foo: def func(self): ... func = Foo.func Returns: A pytd.Function, the aliased method.
Convert a pytd AST item into a type. Takes an AST item representing the definition of a type and returns an item representing a reference to the type. For example, if the item is a pytd.Class, this method will return a pytd.ClassType whose cls attribute points to the class. Args: item: A pytd.Node item. allow_constants: When True, constants that cannot be converted to types will be passed through unchanged. allow_functions: When True, functions that cannot be converted to types will be passed through unchanged. allow_singletons: When True, singletons that act as their types in annotations will return that type. Returns: A pytd.Type object representing the type of an instance of `item`.