Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon

Mypy 0.730 releases with more precise error locations, display error codes and more!

Save for later
  • 3 min read
  • 27 Sep 2019

article-image

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.

Error codes


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.

Unlock access to the largest independent learning library in Tech for FREE!
Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
Renews at €18.99/month. Cancel anytime

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.

Other interesting news in programming


Łukasz Langa at PyLondinium19: “If Python stays synonymous with CPython for too long, we’ll be in big trouble”

Microsoft introduces Pyright, a static type checker for the Python language written in TypeScript

Python 3.8 alpha 2 is now available for testing