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 |
mypy.plugin.Plugin.get_attribute_hook
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:str | Undocumented |
Returns | |
Optional[ | Undocumented |
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:str | Undocumented |
Returns | |
Optional[ | Undocumented |
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'.
Parameters | |
fullname:str | Undocumented |
Returns | |
Optional[ | Undocumented |
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).
Parameters | |
fullname:str | Undocumented |
Returns | |
Optional[ | Undocumented |
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:str | Undocumented |
Returns | |
Optional[ | Undocumented |