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.
Class | ArgUseFinder |
Visitor for finding all the types of arguments that each arg is passed to. |
Class | MakeSuggestionAny |
Undocumented |
Class | ReturnFinder |
Visitor for finding all types returned from a function. |
Class | StrToText |
Undocumented |
Class | SuggestionEngine |
Engine for finding call sites and suggesting signatures. |
Class | SuggestionFailure |
Undocumented |
Class | SuggestionPlugin |
Plugin that records all calls to a given target. |
Class | TypeFormatter |
Visitor used to format types |
Function | any_score_callable |
Undocumented |
Function | any_score_type |
Generate a very made up number representing the Anyness of a type. |
Function | count_errors |
Undocumented |
Function | dedup |
Undocumented |
Function | generate_type_combinations |
Generate possible combinations of a list of types. |
Function | get_arg_uses |
Find all the types of arguments that each arg is passed to. |
Function | get_return_types |
Find all the types returned by return statements in func. |
Function | is_explicit_any |
Undocumented |
Function | is_implicit_any |
Undocumented |
Function | is_tricky_callable |
Is t a callable that we need to put a ... in for syntax reasons? |
Function | make_suggestion_anys |
Make all anys in the type as coming from the suggestion engine. |
Function | refine_callable |
Refine a callable based on another. |
Function | refine_type |
Refine ti by replacing Anys in it with information taken from si |
Function | refine_union |
Refine a union type based on another type. |
Constant | T |
Undocumented |
Variable | Callsite |
Undocumented |
Variable | PyAnnotateSignature |
Undocumented |
Variable | TType |
Undocumented |
Undocumented
Parameters | |
t:CallableType | Undocumented |
is_method:bool | Undocumented |
ignore_return:bool | Undocumented |
Returns | |
float | Undocumented |
Generate a very made up number representing the Anyness of a type.
Higher is better, 1.0 is max
Parameters | |
ut:Type | Undocumented |
arg_pos:bool | Undocumented |
Returns | |
float | Undocumented |
Find all the types of arguments that each arg is passed to.
def foo(x: int) -> None: ... def bar(x: str) -> None: ... def test(x, y):
foo(x) bar(y)
this will return [[int], [str]].
Parameters | |
typemap:Dict[ | Undocumented |
func:FuncDef | Undocumented |
Returns | |
List[ | Undocumented |
Parameters | |
typemap:Dict[ | Undocumented |
func:FuncDef | Undocumented |
Returns | |
List[ | Undocumented |
Parameters | |
t:CallableType | Undocumented |
Returns | |
bool | Undocumented |
Refine a callable based on another.
See comments for refine_type.
Parameters | |
t:CallableType | Undocumented |
s:CallableType | Undocumented |
Returns | |
CallableType | Undocumented |
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.
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]
Parameters | |
ti:Type | Undocumented |
si:Type | Undocumented |
Returns | |
Type | Undocumented |
Refine a union type based on another type.
This is done by refining every component of the union against the right hand side type (or every component of its union if it is one). If an element of the union is successfully refined, we drop it from the union in favor of the refined versions.
Parameters | |
t:UnionType | Undocumented |
s:ProperType | Undocumented |
Returns | |
Type | Undocumented |