Extending and integrating mypy¶
Integrating mypy into another Python application¶
It is possible to integrate mypy into another Python 3 application by
mypy.api and calling the
run function with a parameter of type
what normally would have been the command line arguments to mypy.
run returns a
Tuple[str, str, int], namely
(<normal_report>, <error_report>, <exit_status>), in which
is what mypy normally writes to
<error_report> is what mypy
normally writes to
exit_status is the exit status mypy normally
returns to the operating system.
A trivial example of using the api is the following
import sys from mypy import api result = api.run(sys.argv[1:]) if result: print('\nType checking report:\n') print(result) # stdout if result: print('\nError report:\n') print(result) # stderr print ('\nExit status:', result)
Extending mypy using plugins¶
Mypy supports a plugin system that lets you customize the way mypy type checks code. This can be useful if you want to extend mypy so it can type check code that uses a library that is difficult to express using just PEP 484 types, for example.
Warning: The plugin system is extremely experimental and prone to change. If you want to contribute a plugin to mypy, we recommend you start by contacting the mypy core developers either on gitter or on mypy’s issue tracker.