class documentation

class DefaultPlugin(Plugin): (source)

View In Hierarchy

Type checker plugin that is enabled by default.
Method get​_attribute​_hook Adjust type of a class attribute.
Method get​_class​_decorator​_hook Update class definition for given class decorators.
Method get​_function​_hook Adjust the return type of a function call.
Method get​_method​_hook Adjust return type of a method call.
Method get​_method​_signature​_hook Adjust the signature of a method.

Inherited from Plugin:

Method __init__ Undocumented
Method get​_additional​_deps Customize dependencies for a module.
Method get​_base​_class​_hook Update class definition for given base classes.
Method get​_customize​_class​_mro​_hook Customize MRO for given classes.
Method get​_dynamic​_class​_hook Semantically analyze a dynamic class definition.
Method get​_function​_signature​_hook Adjust the signature of a function.
Method get​_metaclass​_hook Update class definition for given declared metaclasses.
Method get​_type​_analyze​_hook Customize behaviour of the type analyzer for given full names.
Method lookup​_fully​_qualified Lookup a symbol by its full name (including module).
Method report​_config​_data Get representation of configuration data for a module.
Method set​_modules Undocumented
Instance Variable options Undocumented
Instance Variable python​_version Undocumented
Instance Variable _modules Undocumented
def get_attribute_hook(self, fullname): (source)

Adjust type of a class attribute.

This method is called with attribute full name using the class where the attribute was defined (or Var.info.fullname for generated attributes).

For classes without __getattr__ or __getattribute__, this hook is only called for names of fields/properties (but not methods) that exist in the instance MRO.

For classes that implement __getattr__ or __getattribute__, this hook is called for all fields/properties, including nonexistent ones (but still not methods).

For example:

class Base:
x: Any def __getattr__(self, attr: str) -> Any: ...
class Derived(Base):
...

var: Derived var.x var.y

get_attribute_hook is called with '__main__.Base.x' and '__main__.Base.y'. However, if we had not implemented __getattr__ on Base, you would only get the callback for 'var.x'; 'var.y' would produce an error without calling the hook.

Parameters
fullname:strUndocumented
Returns
Optional[Callable[[AttributeContext], Type]]Undocumented
def get_class_decorator_hook(self, fullname): (source)

Update class definition for given class decorators.

The plugin can modify a TypeInfo _in place_ (for example add some generated methods to the symbol table). This hook is called after the class body was semantically analyzed.

The hook is called with full names of all class decorators, for example

Parameters
fullname:strUndocumented
Returns
Optional[Callable[[ClassDefContext], None]]Undocumented
def get_function_hook(self, fullname): (source)

Adjust the return type of a function call.

This method is called after type checking a call. Plugin may adjust the return type inferred by mypy, and/or emit some error messages. Note, this hook is also called for class instantiation calls, so that in this example:

from lib import Class, do_stuff

do_stuff(42) Class()

This method will be called with 'lib.do_stuff' and then with 'lib.Class'.

Parameters
fullname:strUndocumented
Returns
Optional[Callable[[FunctionContext], Type]]Undocumented
def get_method_hook(self, fullname): (source)

Adjust return type of a method call.

This is the same as get_function_hook(), but is called with the method full name (again, using the class where the method is defined).

Parameters
fullname:strUndocumented
Returns
Optional[Callable[[MethodContext], Type]]Undocumented
def get_method_signature_hook(self, fullname): (source)

Adjust the signature of a method.

This method is called before type checking a method call. Plugin may infer a better type for the method. The hook is also called for special Python dunder methods except __init__ and __new__ (use get_function_hook to customize class instantiation). This function is called with the method full name using the class where it was _defined_. For example, in this code:

from lib import Special

class Base:
def method(self, arg: Any) -> Any:
...
class Derived(Base):
...

var: Derived var.method(42)

x: Special y = x[0]

this method is called with '__main__.Base.method', and then with 'lib.Special.__getitem__'.

Parameters
fullname:strUndocumented
Returns
Optional[Callable[[MethodSigContext], FunctionLike]]Undocumented