Mechanisms for inferring function types based on callsites. Currently works by collecting all argument types at callsites, synthesizing a list of possible function types from that, trying them all, and picking the one with the fewest errors that we think is the "best". Can return JSON that pyannotate can use to apply the annotations to code. There are a bunch of TODOs here: * Maybe want a way to surface the choices not selected?? * We can generate an exponential number of type suggestions, and probably want a way to not always need to check them all. * Our heuristics for what types to try are primitive and not yet supported by real practice. * More! Other things: * This is super brute force. Could we integrate with the typechecker more to understand more about what is going on? * Like something with tracking constraints/unification variables? * No understanding of type variables at *all*
Class |
|
Visitor for finding all the types of arguments that each arg is passed to. |
Class |
|
Undocumented |
Class |
|
Undocumented |
Class |
|
Undocumented |
Class |
|
Visitor for finding all types returned from a function. |
Class |
|
Engine for finding call sites and suggesting signatures. |
Class |
|
Plugin that records all calls to a given target. |
Class |
|
Visitor used to format types |
Exception |
|
Undocumented |
Function | any |
Undocumented |
Function | any |
Generate a very made up number representing the Anyness of a type. |
Function | count |
Undocumented |
Function | dedup |
Undocumented |
Function | generate |
Generate possible combinations of a list of types. |
Function | get |
Find all the types of arguments that each arg is passed to. |
Function | get |
Find all the types returned by return statements in func. |
Function | is |
Undocumented |
Function | is |
Undocumented |
Function | is |
Is t a callable that we need to put a ... in for syntax reasons? |
Function | make |
Make all anys in the type as coming from the suggestion engine. |
Function | refine |
Refine a callable based on another. |
Function | refine |
Refine `ti` by replacing Anys in it with information taken from `si` |
Function | refine |
Refine a union type based on another type. |
Type Variable | T |
Undocumented |
Type Variable |
|
Undocumented |
Generate possible combinations of a list of types. mypy essentially supports two different ways to do this: joining the types and unioning the types. We try both.
Find all the types of arguments that each arg is passed to. For example, given def foo(x: int) -> None: ... def bar(x: str) -> None: ... def test(x, y): foo(x) bar(y) this will return [[int], [str]].
Make all anys in the type as coming from the suggestion engine. This keeps those Anys from influencing constraint generation, which allows us to do better when refining types.
Refine `ti` by replacing Anys in it with information taken from `si` This basically works by, when the types have the same structure, traversing both of them in parallel and replacing Any on the left with whatever the type on the right is. If the types don't have the same structure (or aren't supported), the left type is chosen. For example: refine(Any, T) = T, for all T refine(float, int) = float refine(List[Any], List[int]) = List[int] refine(Dict[int, Any], Dict[Any, int]) = Dict[int, int] refine(Tuple[int, Any], Tuple[Any, int]) = Tuple[int, int] refine(Callable[[Any], Any], Callable[[int], int]) = Callable[[int], int] refine(Callable[..., int], Callable[[int, float], Any]) = Callable[[int, float], int] refine(Optional[Any], int) = Optional[int] refine(Optional[Any], Optional[int]) = Optional[int] refine(Optional[Any], Union[int, str]) = Optional[Union[int, str]] refine(Optional[List[Any]], List[int]) = List[int]