Functions for optimizing pytd syntax trees. pytd files come from various sources, and are typically redundant (duplicate functions, different signatures saying the same thing, overlong type disjunctions). The Visitors in this file remove various forms of these redundancies.
Class |
|
Converts mutable parameters to unions. This is lossy. |
Class |
|
Copy methods and constants from base classes into their derived classes. |
Class |
|
Changes the generic type from "object" to "Any". |
Class |
|
Changes "object" to "Any" in return and constant types. |
Class |
|
Shortens long unions to object (or "?"). |
Class |
|
Change unions of containers to containers of unions. |
Class |
|
Group function signatures that only differ in exceptions or return values. |
Class |
|
Find common super classes. Optionally also uses abstract base classes. |
Class |
|
Remove all function type parameters in a union with a class type param. |
Class |
|
Removes unwanted parameter types from the 'self' parameter. |
Class |
|
Simplifies classes with only a __call__ function to just a method. |
Class |
|
Remove duplicate function signatures. |
Class |
|
Give unknowns that map to the same set of concrete types the same name. |
Class |
|
Simplifies containers whose type parameters are all Any. |
Class |
|
Remove duplicate or redundant entries in union types. |
Class |
|
Simplify Unions with superclasses. |
Class |
|
Utility class for optimizations working with superclasses. |
Class |
|
Common superclass for optimizations that track type parameters. |
Function |
|
Optimize a PYTD tree. |
Variable | log |
Undocumented |
Class | _ |
Mutable class for collecting return types and exceptions of functions. |
Optimize a PYTD tree. Tries to shrink a PYTD tree by applying various optimizations. Arguments: node: A pytd node to be optimized. It won't be modified - this function will return a new node. builtins: Definitions of all of the external types in node. lossy: Allow optimizations that change the meaning of the pytd. use_abcs: Use abstract base classes to represent unions like e.g. "Union[float, int]" as "Real". max_union: How many types we allow in a union before we simplify it to just "object". remove_mutable: Whether to simplify mutable parameters to normal parameters. can_do_lookup: True: We're either allowed to try to resolve NamedType instances in the AST, or the AST is already resolved. False: Skip any optimizations that would require NamedTypes to be resolved. Returns: An optimized node.