class documentation

class InspectionEngine: (source)

View In Hierarchy

Engine for locating and statically inspecting expressions.

Method __init__ Undocumented
Method add_prefixes Undocumented
Method collect_attrs Collect attributes from all union/typevar variants.
Method collect_nodes Collect nodes that can be referred to by an expression.
Method expr_attrs Format attributes that are valid for a given expression.
Method expr_type Format type for an expression using current options.
Method expression_def Find and format definition location for an expression.
Method find_module Find module by path, or return a suitable error message.
Method format_node Undocumented
Method get_attrs Get attributes of expression(s) at a location.
Method get_definition Get symbol definitions of expression(s) at a location.
Method get_type Get types of expression(s) at a location.
Method missing_node Undocumented
Method missing_type Undocumented
Method modules_for_nodes Gather modules where given nodes where defined.
Method object_type Undocumented
Method parse_location Undocumented
Method reload_module Reload given module while temporary exporting types.
Method run_inspection Top-level logic to inspect expression(s) at a location.
Method run_inspection_by_exact_location Get type of an expression matching a span.
Method run_inspection_by_position Get types of all expressions enclosing a position.
Instance Variable fg_manager Undocumented
Instance Variable finder Undocumented
Instance Variable force_reload Undocumented
Instance Variable include_kind Undocumented
Instance Variable include_object_attrs Undocumented
Instance Variable include_span Undocumented
Instance Variable limit Undocumented
Instance Variable module Undocumented
Instance Variable union_attrs Undocumented
Instance Variable verbosity Undocumented
Method _fill_from_dict Undocumented
def __init__(self, fg_manager: FineGrainedBuildManager, *, verbosity: int = 0, limit: int = 0, include_span: bool = False, include_kind: bool = False, include_object_attrs: bool = False, union_attrs: bool = False, force_reload: bool = False): (source)

Undocumented

def add_prefixes(self, result: str, expression: Expression) -> str: (source)

Undocumented

def collect_attrs(self, instances: list[Instance]) -> dict[TypeInfo, list[str]]: (source)

Collect attributes from all union/typevar variants.

def collect_nodes(self, expression: RefExpr) -> list[FuncBase|SymbolNode]: (source)

Collect nodes that can be referred to by an expression. Note: it can be more than one for example in case of a union attribute.

def expr_attrs(self, expression: Expression) -> tuple[str, bool]: (source)

Format attributes that are valid for a given expression. If expression type is not an Instance, try using fallback. Attributes are returned as a JSON (ordered by MRO) that maps base class name to list of attributes. Attributes may appear in multiple bases if overridden (we simply follow usual mypy logic for creating new Vars etc).

def expr_type(self, expression: Expression) -> tuple[str, bool]: (source)

Format type for an expression using current options. If type is known, second item returned is True. If type is not known, an error message is returned instead, and second item returned is False.

def expression_def(self, expression: Expression) -> tuple[str, bool]: (source)

Find and format definition location for an expression. If it is not a RefExpr, it is effectively skipped by returning an empty result.

def find_module(self, file: str) -> tuple[State|None, dict[str, object]]: (source)

Find module by path, or return a suitable error message. Note we don't use exceptions to simplify handling 1 vs 2 statuses.

def format_node(self, module: State, node: FuncBase|SymbolNode) -> str: (source)

Undocumented

def get_attrs(self, location: str) -> dict[str, object]: (source)

Get attributes of expression(s) at a location.

def get_definition(self, location: str) -> dict[str, object]: (source)

Get symbol definitions of expression(s) at a location.

def get_type(self, location: str) -> dict[str, object]: (source)

Get types of expression(s) at a location.

def missing_node(self, expression: Expression) -> str: (source)

Undocumented

def missing_type(self, expression: Expression) -> str: (source)

Undocumented

def modules_for_nodes(self, nodes: list[FuncBase|SymbolNode], expression: RefExpr) -> tuple[dict[FuncBase|SymbolNode, State], bool]: (source)

Gather modules where given nodes where defined. Also check if they need to be refreshed (cached nodes may have lines/columns missing).

def object_type(self) -> Instance: (source)

Undocumented

def parse_location(self, location: str) -> tuple[str, list[int]]: (source)

Undocumented

def reload_module(self, state: State): (source)

Reload given module while temporary exporting types.

def run_inspection(self, location: str, method: Callable[[Expression], tuple[str, bool]]) -> dict[str, object]: (source)

Top-level logic to inspect expression(s) at a location. This can be re-used by various simple inspections.

def run_inspection_by_exact_location(self, tree: MypyFile, line: int, column: int, end_line: int, end_column: int, method: Callable[[Expression], tuple[str, bool]]) -> dict[str, object]: (source)

Get type of an expression matching a span. Type or error is returned as a standard daemon response dict.

def run_inspection_by_position(self, tree: MypyFile, line: int, column: int, method: Callable[[Expression], tuple[str, bool]]) -> dict[str, object]: (source)

Get types of all expressions enclosing a position. Types and/or errors are returned as a standard daemon response dict.

fg_manager = (source)

Undocumented

Undocumented

force_reload = (source)

Undocumented

include_kind = (source)

Undocumented

include_object_attrs = (source)

Undocumented

include_span = (source)

Undocumented

Undocumented

Undocumented

union_attrs = (source)

Undocumented

verbosity = (source)

Undocumented

def _fill_from_dict(self, attrs_strs: list[str], attrs_dict: dict[TypeInfo, list[str]]): (source)

Undocumented