class CombineContainers(visitors.Visitor): (source)
Change unions of containers to containers of unions. For example, this transforms Union[list[int], list[float]] to list[Union[int, float]] .
Method |
|
Push unions down into containers. |
Method | _key |
Undocumented |
Method | _should |
Determine whether pytd_type values in the union should be merged. |
Constant | _CONTAINER |
Undocumented |
Inherited from Visitor
:
Method | __init__ |
Undocumented |
Method |
|
Undocumented |
Method |
|
Undocumented |
Method |
|
Undocumented |
Class Variable | old |
Undocumented |
Class Variable | unchecked |
Undocumented |
Class Variable | visits |
Undocumented |
Instance Variable | enter |
Undocumented |
Instance Variable | leave |
Undocumented |
Instance Variable | visit |
Undocumented |
Instance Variable | visit |
Undocumented |
Class Variable | _visitor |
Undocumented |
Push unions down into containers. This collects similar container types in unions and merges them into single instances with the union type pushed down to the element_type level. Arguments: union: A pytd.Union instance. Might appear in a parameter, a return type, a constant type, etc. Returns: A simplified pytd.Union.
Determine whether pytd_type values in the union should be merged. If the union contains the homogeneous flavor of pytd_type (e.g., GenericType(base_type=tuple) when pytd_type is TupleType), or pytd_type values of different lengths, we want to turn all of the pytd_type values into homogeneous ones so that they can be merged into a single container. Args: pytd_type: The pytd type, either TupleType or CallableType. union: a pytd.UnionType Returns: True if the pytd_type values should be merged, False otherwise.
Undocumented
Value |
|