class documentation

class VerifyContainers(Visitor): (source)

View In Hierarchy

Visitor for verifying containers. Every container (except typing.Generic) must inherit from typing.Generic and have an explicitly parameterized base that is also a container. The parameters on typing.Generic must all be TypeVar instances. A container must have at most as many parameters as specified in its template. Raises: ContainerError: If a problematic container definition is encountered.

Method EnterCallableType Undocumented
Method EnterClass Check for conflicting type parameter values in the class's bases.
Method EnterGenericType Verify a pytd.GenericType.
Method EnterTupleType Undocumented
Method _GetGenericBasesLookupMap Get a lookup map for the generic bases of a class.
Method _TypeCompatibilityCheck Check if the types are compatible.
Method _UpdateParamToValuesMapping Update the given mapping of parameter names to values.

Inherited from Visitor:

Method __init__ Undocumented
Method Enter Undocumented
Method Leave Undocumented
Method Visit Undocumented
Class Variable old_node Undocumented
Class Variable unchecked_node_names Undocumented
Class Variable visits_all_node_types Undocumented
Instance Variable enter_functions Undocumented
Instance Variable leave_functions Undocumented
Instance Variable visit_class_names Undocumented
Instance Variable visit_functions Undocumented
Class Variable _visitor_functions_cache Undocumented
def EnterCallableType(self, node): (source)

Undocumented

def EnterClass(self, node): (source)

Check for conflicting type parameter values in the class's bases.

def EnterGenericType(self, node): (source)

Verify a pytd.GenericType.

def EnterTupleType(self, node): (source)

Undocumented

def _GetGenericBasesLookupMap(self, node): (source)

Get a lookup map for the generic bases of a class. Gets a map from a pytd.ClassType to the list of pytd.GenericType bases of the node that have that class as their base. This method does depth-first traversal of the bases, which ensures that the order of elements in each list is consistent with the node's MRO. Args: node: A pytd.Class node. Returns: A pytd.ClassType -> List[pytd.GenericType] map.

def _TypeCompatibilityCheck(self, type_params): (source)

Check if the types are compatible. It is used to handle the case: class A(Sequence[A]): pass class B(A, Sequence[B]): pass class C(B, Sequence[C]): pass In class `C`, the type parameter `_T` of Sequence could be `A`, `B` or `C`. Next we will check they have a linear inheritance relationship: `A` -> `B` -> `C`. Args: type_params: The class type params. Returns: True if all the types are compatible.

def _UpdateParamToValuesMapping(self, mapping, param, value): (source)

Update the given mapping of parameter names to values.