Type checker plugin that is enabled by default.
Method | get |
Adjust type of an instance attribute. |
Method | get |
Update class definition for given class decorators. |
Method | get |
Update class definition for given class decorators. |
Method | get |
Adjust the return type of a function call. |
Method | get |
Adjust return type of a method call. |
Method | get |
Adjust the signature of a method. |
Inherited from Plugin
:
Method | __init__ |
Undocumented |
Method | get |
Customize dependencies for a module. |
Method | get |
Update class definition for given base classes. |
Method | get |
Adjust type of a class attribute. |
Method | get |
Customize MRO for given classes. |
Method | get |
Semantically analyze a dynamic class definition. |
Method | get |
Adjust the signature of a function. |
Method | get |
Update class definition for given declared metaclasses. |
Method | get |
Customize behaviour of the type analyzer for given full names. |
Method | lookup |
Lookup a symbol by its full name (including module). |
Method | report |
Get representation of configuration data for a module. |
Method | set |
Undocumented |
Instance Variable | options |
Undocumented |
Instance Variable | python |
Undocumented |
Instance Variable | _modules |
Undocumented |
mypy.plugin.Plugin.get_attribute_hook
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.
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.
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.
mypy.plugin.Plugin.get_function_hook
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'.
mypy.plugin.Plugin.get_method_hook
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).
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__'.