We’ve just uploaded mypy 0.630 to the Python Package Index (
PyPI). Mypy is an optional 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 documentation for this release on
ReadTheDocs.
New Feature: Callback Protocols
You can now use protocols to specify callable types. In some situations it was hard (or even impossible) to express types of complex callbacks using the
Callable[[Arg, ...], Ret] syntax. Examples include overloaded callbacks, complex generic callbacks, or just callables that don’t accept a fixed number of positional arguments. You can define a callback protocol for situations like these — it’s a protocol with only
__call__ defined:
from typing import Optional, Iterable, List
from typing_extensions import Protocol
class Combiner(Protocol):
def __call__(self, *vals: bytes,
maxlen: Optional[int] = None) -> List[bytes]: ...
def batch_proc(data: Iterable[bytes],
cb_results: Combiner) -> bytes:
...
def good_cb(*vals: bytes,
maxlen: Optional[int] = None) -> List[bytes]:
...
batch_proc([], good_cb) # OK
For more information see
the docs.
Other Improvements and Notable Bugs Fixed
- Support classes and type aliases in plugin hooks (PR 5379)
- Treat IntEnum type object as iterable (Elazar Gershuni, PR 5388)
- Improve Tuple/Sequence/Iterable type overlap checks (Ethan Smith, PR 5315)
- Improve checks for overlapping types (Michael Lee, PR 5476)
- Improve error message for overload overrides with swapped variants (Michael Lee, PR 5369)
- Add support for optional converters in attrs plugin (David Euresti, PR 5411)
- Allow calling Type[T] where T has a generic bound (Elazar Gershuni, PR 5309)
- Support additional arguments to namedtuple() (Jelle Zijlstra, PR 5215)
- Fix crash related to decorated functions (PR 5427)
- Fix daemon crash related to named tuples (PR 5429)
- Avoid infinite recursion when attempting to define recursive types (PR 5434)
- Don't treat non-method functions whose name resembles a reverse operator (e.g. __radd__) as such (Sebastian Rittau, PR 5421)
- Allow plugin registration in mypy.ini using module names or entry points (Chad Dombrova, PR 5358)
- Invalidate cache when a previously missing stub is added (PR 5465)
- Fix issues related to reverse operator methods (Michael Lee, PR 5475)
Documentation Fixes and Internal Improvements
- Remove runtests.py in favor of pytest (Elazar Gershuni, PR 5274)
- Improve stub testing to cover all of typeshed (Ethan Smith, PR 5051)
- Reorganize command line documentation (Michael Lee, PR 5333)
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:
- Alex Jurkiewicz
- Anthony Sottile
- Batuhan Osman Taşkaya
- Bernát Gábor
- Bruce Merry
- Chad Dombrova
- David Euresti
- Elazar Gershuni
- Elias Zamaria
- Emil Hessman
- Ethan Smith
- Georg Molau
- Janus Troelsen
- Jelle Zijlstra
- Matvey Tolstolytski
- Michael Lee
- Sebastian Rittau
- William Schwartz
- ceh
- snarkmaster
Additional thanks to all contributors to
typeshed:
- Amol Bhave
- Anthony Sottile
- Brandon Lin
- Bruce Merry
- Chelsea Voss
- Daniel Li
- David Euresti
- David Zbarsky
- Devin Fee
- Dmitry Shachnev
- Dominik Gabi
- EFanZh
- Emil Hessman
- Ethan Smith
- Gary van der Merwe
- Goldstein
- Hynek Schlawack
- Ilya Konstantinov
- Jelle Zijlstra
- Linda_pp
- Martin DeMello
- Matt Gilson
- Max Murin
- Michael Lee
- MinJune Kim
- Ollie Ford
- Olmo Kramer
- Omar Sandoval
- Philipp Hahn
- Ran Benita
- Rebecca Chen
- Sebastian Kreft
- Sebastian Rittau
- Siva Chandra
- Stig Johan Berggren
- Teddy Sudol
- Tomasz Trębski
- Ville Skyttä
- Yusuke Miyazaki
- Zac Hatfield-Dodds
- Zsolt Dollenstein
- justinpawela
- stevenjackson121
- tikki
— Ivan Levkivskyi, on behalf of the mypy team