class documentation

class SemanticAnalyzerPluginInterface: (source)

Known subclasses: mypy.semanal.SemanticAnalyzer

View In Hierarchy

Interface for accessing semantic analyzer functionality in plugins.

Methods docstrings contain only basic info. Look for corresponding implementation docstrings in semanal.py for more details.

# TODO: clean-up lookup functions.

Method add​_plugin​_dependency Specify semantic dependencies for generated methods/variables.
Method add​_symbol​_table​_node Add node to global symbol table (or to nearest class if there is one).
Method anal​_type Analyze an unbound type.
Method class​_type Generate type of first argument of class methods from type of self.
Method defer Call this to defer the processing of the current node.
Method fail Emit an error message at given location.
Method lookup​_fully​_qualified Lookup a symbol by its fully qualified name.
Method lookup​_fully​_qualified​_or​_none Lookup a symbol by its fully qualified name.
Method lookup​_qualified Lookup symbol using a name in current scope.
Method named​_type Construct an instance of a builtin type with given type arguments.
Method named​_type​_or​_none Construct an instance of a type with given type arguments.
Method parse​_bool Parse True/False literals.
Method qualified​_name Make qualified name using current module and enclosing class (if any).
Class Variable cur​_mod​_id Undocumented
Class Variable modules Undocumented
Class Variable msg Undocumented
Class Variable options Undocumented
Property final​_iteration Is this the final iteration of semantic analysis?
Property is​_stub​_file Undocumented
@abstractmethod
def add_plugin_dependency(self, trigger, target=None): (source)

Specify semantic dependencies for generated methods/variables.

If the symbol with full name given by trigger is found to be stale by mypy, then the body of node with full name given by target will be re-checked. By default, this is the node that is currently analyzed.

For example, the dataclass plugin adds a generated __init__ method with a signature that depends on types of attributes in ancestor classes. If any attribute in an ancestor class gets stale (modified), we need to reprocess the subclasses (and thus regenerate __init__ methods).

This is used by fine-grained incremental mode (mypy daemon). See mypy/server/deps.py for more details.

Parameters
trigger:strUndocumented
target:Optional[str]Undocumented
@abstractmethod
def add_symbol_table_node(self, name, stnode): (source)
Add node to global symbol table (or to nearest class if there is one).
Parameters
name:strUndocumented
stnode:SymbolTableNodeUndocumented
Returns
AnyUndocumented
@abstractmethod
def anal_type(self, t, *, tvar_scope=None, allow_tuple_literal=False, allow_unbound_tvars=False, report_invalid_types=True, third_pass=False): (source)

Analyze an unbound type.

Return None if some part of the type is not ready yet. In this case the current target being analyzed will be deferred and analyzed again.

Parameters
t:TypeUndocumented
tvar​_scope:Optional[TypeVarLikeScope]Undocumented
allow​_tuple​_literal:boolUndocumented
allow​_unbound​_tvars:boolUndocumented
report​_invalid​_types:boolUndocumented
third​_pass:boolUndocumented
Returns
Optional[Type]Undocumented
@abstractmethod
def class_type(self, self_type): (source)
Generate type of first argument of class methods from type of self.
Parameters
self​_type:TypeUndocumented
Returns
TypeUndocumented
@abstractmethod
def defer(self): (source)

Call this to defer the processing of the current node.

This will request an additional iteration of semantic analysis.

@abstractmethod
def fail(self, msg, ctx, serious=False, *, blocker=False, code=None): (source)
Emit an error message at given location.
Parameters
msg:strUndocumented
ctx:ContextUndocumented
serious:boolUndocumented
blocker:boolUndocumented
code:Optional[ErrorCode]Undocumented
@abstractmethod
def lookup_fully_qualified(self, name): (source)

Lookup a symbol by its fully qualified name.

Raise an error if not found.

Parameters
name:strUndocumented
Returns
SymbolTableNodeUndocumented
@abstractmethod
def lookup_fully_qualified_or_none(self, name): (source)

Lookup a symbol by its fully qualified name.

Return None if not found.

Parameters
name:strUndocumented
Returns
Optional[SymbolTableNode]Undocumented
@abstractmethod
def lookup_qualified(self, name, ctx, suppress_errors=False): (source)

Lookup symbol using a name in current scope.

This follows Python local->non-local->global->builtins rules.

Parameters
name:strUndocumented
ctx:ContextUndocumented
suppress​_errors:boolUndocumented
Returns
Optional[SymbolTableNode]Undocumented
@abstractmethod
def named_type(self, fullname, args=None): (source)
Construct an instance of a builtin type with given type arguments.
Parameters
fullname:strUndocumented
args:Optional[List[Type]]Undocumented
Returns
InstanceUndocumented
@abstractmethod
def named_type_or_none(self, fullname, args=None): (source)

Construct an instance of a type with given type arguments.

Return None if a type could not be constructed for the qualified type name. This is possible when the qualified name includes a module name and the module has not been imported.

Parameters
fullname:strUndocumented
args:Optional[List[Type]]Undocumented
Returns
Optional[Instance]Undocumented
@abstractmethod
def parse_bool(self, expr): (source)
Parse True/False literals.
Parameters
expr:ExpressionUndocumented
Returns
Optional[bool]Undocumented
@abstractmethod
def qualified_name(self, n): (source)
Make qualified name using current module and enclosing class (if any).
Parameters
n:strUndocumented
Returns
strUndocumented
cur_mod_id: str = (source)

Undocumented

modules: Dict[str, MypyFile] = (source)

Undocumented

options: Options = (source)

Undocumented

@property
@abstractmethod
final_iteration: bool = (source)
Is this the final iteration of semantic analysis?
@property
@abstractmethod
is_stub_file: bool = (source)

Undocumented