Yesterday the Mypy team uploaded mypy 0.730 to the Python Package Index (PyPI). Mypy is a static type checker for Python. This release includes many features, bug fixes and library stub updates. You can install it as follows:
python3 -m pip install -U mypy
Python creator Guido van Rossum tweeted about this release, he says “mypy 0.720 released. New semantic analyzer is now the default! Also, –warn-unreachable flag, and many more fixes and updates.”
Major updates in Mypy 0.730
Some of the breaking changes in the Mypy 0.730 include:
More precise error locations
If you call a function with an incompatible argument type, mypy now points the error message to the argument with the incompatible type. Previously, mypy pointed to the function being called, which could be confusing in multi-line calls.
Mypy 0.730 can now optionally display error codes. They are shown within square brackets after each error message:
prog.py:24: error: “str” has no attribute “trim” [attr-defined]
Enable error codes using –show-error-codes (or show_error_codes = True in a configuration file).
Ignoring specific error codes
You can ignore only errors with specific error codes on a particular line by using a # type: ignore[code, …] comment. This reduces the risk of ignoring unexpected, serious errors when using # type: ignore comments that ignore (almost) all possible errors on a line.
Colors in output
Mypy 0.730 now uses colored, more user-friendly output by default. You can use –no-color to disable colored output. You can use –no-error-summary to hide the summary line with the number of errors.
Pretty output mode
You can use –pretty to display each line which had errors and a caret that points to the location of the error on each line.
Old semantic analyzer removed
This release of Mypy 0.730 no longer includes the old semantic analyzer.
Reachability and context managers
The –warn-unreachable option now behaves more correctly with “exception-swallowing” context managers. If a context manager is currently declared to return bool but it never swallows exceptions, you should annotate the return of __exit__ as Literal[False] instead of bool, or otherwise mypy may complain about missing return statements.
To know more about this release, read the full documentation on Read the Docs.