module documentation

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 Alias An alias (symbolic link) for a class implemented in some other module.
Class Annotated Undocumented
Class AnythingType A type we know nothing about yet (? in pytd).
Class CallableType Special generic type for a Callable that specifies its argument types.
Class Class Represents a class declaration.
Class ClassType A type specified through an existing class node.
Class Concatenate Concatenate params and ParamSpec.
Class Constant Undocumented
Class Function A function or a method, defined by one or more PyTD signatures.
Class GenericType Generic type. Takes a base type and type parameters.
Class IntersectionType An intersection type.
Class LateType A type we have yet to resolve.
Class Literal Undocumented
Class MethodFlag Undocumented
Class MethodKind Undocumented
Class Module A module imported into the current module, possibly with an alias.
Class NamedType A type specified by name and, optionally, the module it is in.
Class NothingType An "impossible" type, with no instances (nothing in pytd).
Class Parameter Represents a parameter of a function definition.
Class ParameterKind Undocumented
Class ParamSpec ParamSpec is a specific case of TypeParameter.
Class ParamSpecArgs ParamSpec.args special form.
Class ParamSpecKwargs ParamSpec.kwargs special form.
Class Signature Represents an individual signature of a function.
Class TemplateItem Represents template name for generic types.
Class TupleType Special generic type for heterogeneous tuples.
Class Type Each type class below should inherit from this mixin.
Class TypeDeclUnit Module node. Holds module contents (constants / classes / functions).
Class TypeParameter Represents a type parameter.
Class UnionType A union type that contains all types in self.type_list.
Function AliasMethod Returns method func with its signature modified as if it has been aliased.
Function IsContainer Checks whether class t is a container.
Function LookupItemRecursive Recursively look up name in module.
Function ToType Convert a pytd AST item into a type.
Constant GENERIC_BASE_TYPE Undocumented
Constant SINGLETON_TYPES Undocumented
Class _SetOfTypes Super class for shared behavior of UnionType and IntersectionType.
Function _FlattenTypes Helper function for _SetOfTypes initialization.
Type Variable _TypeT Undocumented
def AliasMethod(func, from_constant): (source)

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.

def IsContainer(t: Class) -> bool: (source)

Checks whether class t is a container.

def LookupItemRecursive(module, name): (source)

Recursively look up name in module.

def ToType(item, allow_constants=False, allow_functions=False, allow_singletons=False): (source)

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`.

GENERIC_BASE_TYPE = (source)

Undocumented

Value
(NamedType, ClassType)
SINGLETON_TYPES = (source)

Undocumented

Value
frozenset(set(['Ellipsis', 'builtins.Ellipsis']))
def _FlattenTypes(type_list) -> Tuple[Type, ...]: (source)

Helper function for _SetOfTypes initialization.

Undocumented

Value
TypeVar('_TypeT',
        bound='Type')