class documentation

class MergeTypeParameters(TypeParameterScope): (source)

View In Hierarchy

Remove all function type parameters in a union with a class type param. For example, this will change class A(typing.Generic(T)): def append(self, Union[T, T2]) -> T2 to class A(typing.Generic(T)): def append(self, T) -> T . Use this visitor after using AbsorbMutableParameters. As another example, the combination of AbsorbMutableParameters and MergeTypeParameters transforms class list(typing.Generic(T)): def append(self, v: T2) -> NoneType: self = Union[T, T2] to class list(typing.Generic(T')): def append(self, V:T') -> NoneType by creating a *new* template variable T' that propagates the mutations to the outermost level (in this example, T' = Union[T, T2])

Method __init__ Undocumented
Method EnterSignature Undocumented
Method LeaveSignature Undocumented
Method VisitSignature Undocumented
Method VisitUnionType Undocumented
Instance Variable type_param_union Undocumented
Method _AllContaining Gets all type parameters that are in a union with the passed one.
Method _AppendNew Appends all items to l1 that are not in l2.
Method _ReplaceByOuterIfNecessary Potentially replace a function type param with a class type param.

Inherited from TypeParameterScope:

Method EnterClass Undocumented
Method IsClassTypeParameter Undocumented
Method IsFunctionTypeParameter Undocumented
Method LeaveClass Undocumented
Instance Variable type_params_stack Undocumented

Inherited from Visitor (via TypeParameterScope):

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 EnterSignature(self, sig): (source)
def LeaveSignature(self, node): (source)
def VisitSignature(self, sig): (source)

Undocumented

def VisitUnionType(self, u): (source)

Undocumented

type_param_union = (source)

Undocumented

def _AllContaining(self, type_param, seen=None): (source)

Gets all type parameters that are in a union with the passed one.

def _AppendNew(self, l1, l2): (source)

Appends all items to l1 that are not in l2.

def _ReplaceByOuterIfNecessary(self, item, substitutions): (source)

Potentially replace a function type param with a class type param. Args: item: A pytd.TemplateItem substitutions: A dictionary to update with what we replaced. Returns: Either [item] or [].