class documentation

class DefaultPlugin(Plugin): (source)

View In Hierarchy

Type checker plugin that is enabled by default.

Method get_attribute_hook Adjust type of an instance attribute.
Method get_class_decorator_hook Update class definition for given class decorators.
Method get_class_decorator_hook_2 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_class_attribute_hook Adjust type of a class attribute.
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: str) -> Callable[[AttributeContext], Type]|None: (source)

Adjust type of an instance attribute. This method is called with attribute full name using the class of the instance 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.

def get_class_decorator_hook(self, fullname: str) -> Callable[[ClassDefContext], None]|None: (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, but *there may still be placeholders* (typically caused by forward references). NOTE: Usually get_class_decorator_hook_2 is the better option, since it guarantees that there are no placeholders. The hook is called with full names of all class decorators. The hook can be called multiple times per class, so it must be idempotent.

def get_class_decorator_hook_2(self, fullname: str) -> Callable[[ClassDefContext], bool]|None: (source)

Update class definition for given class decorators. Similar to get_class_decorator_hook, but this runs in a later pass when placeholders have been resolved. The hook can return False if some base class hasn't been processed yet using class hooks. It causes all class hooks (that are run in this same pass) to be invoked another time for the file(s) currently being processed. The hook can be called multiple times per class, so it must be idempotent.

def get_function_hook(self, fullname: str) -> Callable[[FunctionContext], Type]|None: (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'.

def get_method_hook(self, fullname: str) -> Callable[[MethodContext], Type]|None: (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).

def get_method_signature_hook(self, fullname: str) -> Callable[[MethodSigContext], FunctionLike]|None: (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__'.