Integrating mypy into another Python application
It is possible to integrate mypy into another Python 3 application byimporting mypy.api
and calling the run
function with a parameter of type List[str]
, containingwhat normally would have been the command line arguments to mypy.
Function run
returns a Tuple[str, str, int]
, namely(<normal_report>, <error_report>, <exit_status>)
, in which <normal_report>
is what mypy normally writes to sys.stdout
, <error_report>
is what mypynormally writes to sys.stderr
and exit_status
is the exit status mypy normallyreturns 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[0]:
- print('\nType checking report:\n')
- print(result[0]) # stdout
- if result[1]:
- print('\nError report:\n')
- print(result[1]) # stderr
- print('\nExit status:', result[2])