We’ve just uploaded mypy 0.790 to the Python Package Index (PyPI). Mypy is a static type checker for Python. This release includes new features, bug fixes and library stub (typeshed) updates. You can install it as follows:
python3 -m pip install -U mypy
You can read the full documentation for this release on Read the Docs.
Note that mypy 0.790 doesn’t yet officially support the recently released Python 3.9.
Enabling and Disabling Error Codes
You can now globally disable and enable the generation of error messages with specific error codes by using --enable-error-code and --disable-error-code command line options (and config file options). This lets you disallow certain checks that don’t provide value or are too noisy, and in the future these can be used to enable optional, stricter checks. For more information, read the documentation.
This was contributed by Callum Wilkinson (PR 9172).
Bug Fixes
- Fix disable_error_code config file option (Aristotelis Mikropoulos, PR 9538)
- Fix partial type crash during protocol checking (Shantanu, PR 9495)
- Store the type for assignment expression (walrus) targets (Lawrence Chan, PR 9479)
- Always type check arguments when using --disallow-untyped-calls (PR 9510)
- Make None compatible with Hashable (PR 9371)
- Don't infinite loop on self dependencies in --follow-imports=normal (Michael J. Sullivan, PR 9302)
- Don't simplify away Any when joining union types (PR 9301)
- Check for deleted vars in raise from (Alexandre Viau, PR 9272)
- Fix corner case for comparing nested overloads (Nikita Sobolev, PR 9259)
- Fix issues with async for and with statements (Guido van Rossum, PR 9268)
- Fix internal error on list/dict comprehension with walrus operator in global scope (dhood, PR 9062)
- Fix propagation of module-specific options to the parser (Guido van Rossum, PR 9247)
- Fix crash when super is called outside a method (Weiss, PR 9173)
- Fix untyped decorator overload error on class decorator with __call__ overloads (Ran Benita, PR 9232)
- Clean up terminal width handling (Florian Bruhin, PR 9143)
- Add keyword arguments for functional Enum API (LiuYuhui, PR 9123)
- Validate follow_imports values in mypy.ini (Michael J. Sullivan, PR 9165)
- Fix *expr in an assigned expression (LiuYuhui, PR 8827)
- Don't consider comparing True and False as a dangerous comparison (PR 9021)
- Make reveal_type work with call expressions returning None (Jakub Stasiak, PR 8924)
Error Reporting Improvements
- Improve missing module error for subdirectories (Ethan Leba, PR 8927)
- Clarify bytes formatting error messages (Shantanu, PR 9243)
- Fix misleading follow_imports error message in dmypy (Michael J. Sullivan, PR 9167)
- Use [arg-type] error code for additional argument type error messages (PR 9090)
- Report some additional serious errors in junit.xml (PR 8950)
- Report note about binary operation on the same location as error message (PR 8936)
Documentation Updates
- Document disable_error_code config file option (Aristotelis Mikropoulos, PR 9539)
- Add cross references to config file values (Oleg Höfling, PR 7859)
- Add cross references to additional config values, and missing plugins config value, and document --help option for stubgen (Oleg Höfling, PR 9241)
- Remove note that Final is experimental and suggest importing it from typing (Ran Benita, PR 9138)
- Discuss unreachable code as a common issue (Chetan Khanna, PR 8899)
Stubgen Improvements
- Improve property type detection in extension modules (Antoine Prouvost, PR 8999)
- Fix type stubgen crash caused by invalid type annotation (Henry Schreiner, PR 8888)
- Import Iterable and Iterator from typing in generated stubs (Ashley Whetter, PR 9088)
Other Improvements
- Speed up type checking of unions containing many literal string types (Akuli, PR 9192)
- Add scripts to misc/ (in the mypy GitHub repository) for computing and applying diffs of mypy caches to enable incremental cache downloads (Michael J. Sullivan, PR 8906)
Internal Changes
This release includes several improvements to mypyc, the compiler we use to speed up mypy. Most notably, Xuanda Yang has been migrating mypyc to use a new, lower-level intermediate representation in his Google Summer of Code project. This provides a solid foundation for a variety of future mypyc improvements.
Additional mypyc improvements:
- Dynamically disallow instantiating traits/interpreted subclasses (Michael J. Sullivan, PR 9248)
- Basic support for protocols (Michael J. Sullivan, PR 8914)
- Various optimizations (PR 8903, PR 8870; Michael J. Sullivan and Xuanda Yang, PR 9245)
- Make it easier to write mypyc test cases (PR 9094)
Typeshed Updates
Many improvements were made to typeshed — too many to list. Browse the typeshed commit log here.
Acknowledgments
First of all, we’d like to thank our employer, Dropbox, for funding the mypy core team.
Thanks to all mypy contributors who contributed to this release:
- Akuli
- Alexandre Viau
- Antoine Lecubin
- Antoine Prouvost
- Aristotelis Mikropoulos
- Ashley Whetter
- Ben Wolsieffer
- Brian Mboya
- Callum Wilkinson
- Chetan Khanna
- dhood
- Ethan Leba
- Florian Bruhin
- Henry Schreiner
- ishaan
- Jakub Stasiak
- Jelle Zijlstra
- Lawrence Chan
- LiuYuhui
- Michael R. Crusoe
- Michael Sullivan
- Nikita Sobolev
- Oleg Höfling
- Ram Rachum
- Ran Benita
- Rune Tynan
- Shantanu
- Weiss
- Xuanda Yang
- 谭九鼎
Additional thanks to all contributors to typeshed:
- Adam Hitchcock
- Akuli
- Alex Grönholm
- Anders Kaseorg
- Andre Delfino
- Andreas Poehlmann
- Artem Simonov
- Batuhan Taskaya
- Brad Solomon
- Brian Wellington
- Bruce Merry
- Cerek Hillen
- Christine
- Christopher Head
- Christopher Schramm
- Dakkaron
- Dan Palmer
- David Hotham
- Denis Laxalde
- Dmitry Marakasov
- Eric Masseran
- Eric N. Vander Weele
- Eric Traut
- Federico Bond
- frehoy
- Gregory P. Smith
- helafumpek
- Ian Good
- Ian Woloschin
- Igor Nehoroshev
- Ilaï Deutel
- Ilya Konstantinov
- Jakub Stasiak
- James Weaver
- Jaromir Latal
- Jelle Zijlstra
- Jia Chen
- John Snow
- Jonathan Slenders
- Joshua Oreman
- Julian Mehnle
- Julin S
- Jürgen Gmach
- Karl Ding
- Kevin Wojniak
- Kunal Arya
- Luciano Ramalho
- Magnus Watn
- MapleCCC
- Mario Ishac
- Mark Mendoza
- Markus Pielmeier
- Martijn Pieters
- Matan Gover
- Michael H
- Mikhail Golubev
- Milap Sheth
- Nils K
- Nipunn Koorapati
- Omar Sandoval
- Peter Law
- Philipp Hahn
- Phillip Huang
- Ran Benita
- Rebecca Chen
- Rich Li
- Rune Tynan
- Russell Davis
- Sabby6
- Sam Bull
- Sebastian Kreft
- Sebastian Rittau
- Selim Belhaouane
- Shannon Zhu
- Shantanu
- Steve B
- Steve Dignam
- Tarcisio
- Teddy Sudol
- Toru Ogawa
- Vegard Stikbakke
- Vishal Kuo
- Vlad Emelianov
- Willy Wu
- Wouter Bolsterlee
- Áron Ricardo Perez-Lopez