class documentation

class SuggestionEngine: (source)

View In Hierarchy

Engine for finding call sites and suggesting signatures.

Method __init__ Undocumented
Method ensure_loaded Make sure that the module represented by state is fully loaded.
Method extract_from_decorator Undocumented
Method filter_options Apply any configured filters to the possible guesses.
Method find_best From a list of possible function types, find the best one.
Method find_node From a target name, return module/target names and the func def.
Method find_node_by_file_and_line Find symbol node by path to file and line number.
Method find_node_by_module_and_name Find symbol node by module id and qualified name.
Method format_args Undocumented
Method format_signature Format a callable type in a way suitable as an annotation... kind of
Method format_type Undocumented
Method get_args Produce a list of type suggestions for each argument type.
Method get_callsites Find all call sites of a function.
Method get_default_arg_types Undocumented
Method get_guesses Compute a list of guesses for a function's type.
Method get_guesses_from_parent Try to get a guess of a method type from a parent class.
Method get_starting_type Undocumented
Method get_suggestion Compute a suggestion for a function.
Method get_trivial_type Generate a trivial callable type from a func def, with all Anys
Method json_suggestion Produce a json blob for a suggestion suitable for application by pyannotate.
Method named_type Undocumented
Method pyannotate_signature Format a callable type as a pyannotate dict
Method reload Recheck the module given by state.
Method restore_after Context manager that reloads a module after executing the body.
Method score_callable Undocumented
Method score_type Generate a score for a type that we use to pick which type to use.
Method suggest Suggest an inferred type for function.
Method suggest_callsites Find a list of call sites of function.
Method try_type Recheck a function while assuming it has type typ.
Method with_export_types Context manager that enables the export_types flag in the body.
Instance Variable fgmanager Undocumented
Instance Variable finder Undocumented
Instance Variable flex_any Undocumented
Instance Variable give_json Undocumented
Instance Variable graph Undocumented
Instance Variable manager Undocumented
Instance Variable max_guesses Undocumented
Instance Variable no_errors Undocumented
Instance Variable plugin Undocumented
Instance Variable use_fixme Undocumented
def __init__(self, fgmanager: FineGrainedBuildManager, *, json: bool, no_errors: bool = False, no_any: bool = False, flex_any: float|None = None, use_fixme: str|None = None, max_guesses: int|None = None): (source)

Undocumented

def ensure_loaded(self, state: State, force: bool = False) -> MypyFile: (source)

Make sure that the module represented by state is fully loaded.

def extract_from_decorator(self, node: Decorator) -> FuncDef|None: (source)

Undocumented

def filter_options(self, guesses: list[CallableType], is_method: bool, ignore_return: bool) -> list[CallableType]: (source)

Apply any configured filters to the possible guesses. Currently the only option is filtering based on Any prevalance.

def find_best(self, func: FuncDef, guesses: list[CallableType]) -> tuple[CallableType, int]: (source)

From a list of possible function types, find the best one. For best, we want the fewest errors, then the best "score" from score_callable.

def find_node(self, key: str) -> tuple[str, str, FuncDef]: (source)

From a target name, return module/target names and the func def. The 'key' argument can be in one of two formats: * As the function full name, e.g., package.module.Cls.method * As the function location as file and line separated by column, e.g., path/to/file.py:42

def find_node_by_file_and_line(self, file: str, line: int) -> tuple[str, SymbolNode]: (source)

Find symbol node by path to file and line number. Find the first function declared *before or on* the line number. Return module id and the node found. Raise SuggestionFailure if can't find one.

def find_node_by_module_and_name(self, modname: str, tail: str) -> SymbolNode|None: (source)

Find symbol node by module id and qualified name. Raise SuggestionFailure if can't find one.

def format_args(self, arg_kinds: list[list[ArgKind]], arg_names: list[list[str|None]], arg_types: list[list[Type]]) -> str: (source)

Undocumented

def format_signature(self, sig: PyAnnotateSignature) -> str: (source)

Format a callable type in a way suitable as an annotation... kind of

def format_type(self, cur_module: str|None, typ: Type) -> str: (source)

Undocumented

def get_args(self, is_method: bool, base: CallableType, defaults: list[Type|None], callsites: list[Callsite], uses: list[list[Type]]) -> list[list[Type]]: (source)

Produce a list of type suggestions for each argument type.

def get_callsites(self, func: FuncDef) -> tuple[list[Callsite], list[str]]: (source)

Find all call sites of a function.

def get_default_arg_types(self, fdef: FuncDef) -> list[Type|None]: (source)

Undocumented

def get_guesses(self, is_method: bool, base: CallableType, defaults: list[Type|None], callsites: list[Callsite], uses: list[list[Type]]) -> list[CallableType]: (source)

Compute a list of guesses for a function's type. This focuses just on the argument types, and doesn't change the provided return type.

def get_guesses_from_parent(self, node: FuncDef) -> list[CallableType]: (source)

Try to get a guess of a method type from a parent class.

def get_starting_type(self, fdef: FuncDef) -> CallableType: (source)

Undocumented

def get_suggestion(self, mod: str, node: FuncDef) -> PyAnnotateSignature: (source)

Compute a suggestion for a function. Return the type and whether the first argument should be ignored.

def get_trivial_type(self, fdef: FuncDef) -> CallableType: (source)

Generate a trivial callable type from a func def, with all Anys

def json_suggestion(self, mod: str, func_name: str, node: FuncDef, suggestion: PyAnnotateSignature) -> str: (source)

Produce a json blob for a suggestion suitable for application by pyannotate.

def named_type(self, s: str) -> Instance: (source)

Undocumented

def pyannotate_signature(self, cur_module: str|None, is_method: bool, typ: CallableType) -> PyAnnotateSignature: (source)

Format a callable type as a pyannotate dict

def reload(self, state: State) -> list[str]: (source)

Recheck the module given by state.

@contextmanager
def restore_after(self, module: str) -> Iterator[None]: (source)

Context manager that reloads a module after executing the body. This should undo any damage done to the module state while mucking around.

def score_callable(self, t: CallableType) -> int: (source)

Undocumented

def score_type(self, t: Type, arg_pos: bool) -> int: (source)

Generate a score for a type that we use to pick which type to use. Lower is better, prefer non-union/non-any types. Don't penalize optionals.

def suggest(self, function: str) -> str: (source)

Suggest an inferred type for function.

def suggest_callsites(self, function: str) -> str: (source)

Find a list of call sites of function.

def try_type(self, func: FuncDef, typ: ProperType) -> list[str]: (source)

Recheck a function while assuming it has type typ. Return all error messages.

@contextmanager
def with_export_types(self) -> Iterator[None]: (source)

Context manager that enables the export_types flag in the body. This causes type information to be exported into the manager's all_types variable.

fgmanager = (source)

Undocumented

Undocumented

Undocumented

give_json = (source)

Undocumented

Undocumented

Undocumented

max_guesses = (source)

Undocumented

no_errors = (source)

Undocumented

Undocumented

use_fixme = (source)

Undocumented