News

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

2 min read

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.

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, static type checker for the Python language written in TypeScript

Python 3.8 alpha 2 is now available for testing

Fatema Patrawala

Being a Senior Content Marketing Editor at Packt Publishing, I handle vast array of content in the tech space ranging from Data science, Web development, Programming, Cloud & Networking, IoT, Security and Game development. With prior experience and understanding of Marketing I aspire to grow leaps and bounds in the Content & Digital Marketing field. On the personal front I am an ambivert and love to read inspiring articles and books on life and in general.

Share
Published by
Fatema Patrawala

Recent Posts

Top life hacks for prepping for your IT certification exam

I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…

3 years ago

Learn Transformers for Natural Language Processing with Denis Rothman

Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…

3 years ago

Learning Essential Linux Commands for Navigating the Shell Effectively

Once we learn how to deploy an Ubuntu server, how to manage users, and how…

3 years ago

Clean Coding in Python with Mariano Anaya

Key-takeaways:   Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…

3 years ago

Exploring Forms in Angular – types, benefits and differences   

While developing a web application, or setting dynamic pages and meta tags we need to deal with…

3 years ago

Gain Practical Expertise with the Latest Edition of Software Architecture with C# 9 and .NET 5

Software architecture is one of the most discussed topics in the software industry today, and…

3 years ago