Friday, 7 December 2018

Mypy 0.650 Released

We’ve just uploaded mypy 0.650 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 documentation for this release on Read the Docs.

Skipping the Rest of a File Using Asserts

You can now use certain always-false, unindented top-level assertions to tell mypy to skip the rest of the file. This allows you to skip type checking based on the target platform, for example:

    import sys

    assert sys.platform != 'win32'

    # The rest of this file doesn't work on Windows.

Some other expressions exhibit similar behavior; in particular, typing.TYPE_CHECKING, variables named MYPY, and any variable whose name is passed to --always-true or --always-false. (However, True and False are not treated specially!)

Mypy Daemon Improvements

  • Exit with status 2 from dmypy on irregular errors, and with 1 only if type checking finished but generated errors (PR 5982)
  • Work towards dmypy support on Windows:
    • Add initial support for dmypy on Windows (Ethan Smith, PR 5859)
    • Create new, hidden window when starting daemon on Windows (Ethan Smith, PR 5994)
  • Add --remove/--update flags to dmypy recheck (to allow Watchman integration, for example) (PR 5840, PR 5745)
  • Fix issues with # type: ignore in dmypy (PR 5861)
  • Fix daemon dependency handling for super() (PR 5793)
  • Speed up dmypy by reducing constant overhead (PR 5907)

Stubgen Improvements

  • Update stubgen to output async def and coroutine decorators (Bryan Forbes, PR 5845)
  • Improve stub files generated by stubgenc for pybind11 modules (Wiktor Niesiobędzki, PR 5850)
  • Improve stub generation so it works better with pybind11 wrappers (Eric Chang, PR 5814)
  • Make stubgen less aggressive about walking C extension modules (PR 5900)

Plugin Improvements

The mypy plugin system is still not documented or officially supported for third-party plugin development, but it’s available for brave early adopters.

  • Add plugin for ctypes.Array (dgelessus, PR 4869)
  • Fix ctypes plugin trying to look up bytes in Python 2 (dgelessus, PR 5924)
  • Fix dataclass inherited field ordering (Jakub Stasiak, PR 5877)
  • Invalidate cache when a plugin is added, removed or changed (PR 5878, PR 5892)
  • Add plugin hook for dynamic class definition (PR 5875)
  • Add options attribute to all plugin APIs (dgelessus, PR 5890)
  • Fix plugin hooks not being called correctly for dunder methods (dgelessus, PR 5700)
  • Fix issues with plugins in daemon mode (PR 5828)

Documentation Updates

  • Document ClassVar (PR 6005, PR 5733) (Joannah Nanjekye)
  • Improve documentation of ABCs (PR 6004)
  • Document what to do if a class is not generic at runtime (PR 5833)
  • Remove the “revision history” chapter, which was not very useful (PR 6018)

Other Improvements and Notable Bugs Fixed

  • Re-order module search path to put MYPYPATH first (Ethan Smith, PR 5776)
  • Stop suggesting MYPYPATH on missing imports (Michael Lee, PR 5950)
  • Add --disallow-any-generics to --strict (Joel Croteau, PR 5685)
  • Change all TypedDicts to be subtypes of Mapping[str, object] (PR 5933)
  • Type check TypedDict as caller kwargs (PR 5925)
  • Fix crash in PEP 561 module resolution (Ethan Smith, PR 6000)
  • Fix crash when reveal_locals() encounters a class definition (PR 5920)
  • Make descriptor assignments more like normal assignments (PR 5853)
  • Fix issue with module __getattr__ (PR 5893)
  • Fixes to reports: don't crash on control characters, ensure directories exist earlier (PR 5885)
  • Preserve tabs when creating XML reports (Maarten ter Huurne, PR 5945)
  • Create missing directories for junit XML output (Evan Kepner, PR 5827)
  • Fix constraint inference for non-invariant instances (PR 5817)
  • Use actual variable name for failed enum calls (PR 5810)
  • Support None.__bool__() (Daniel Darabos, PR 5780)
  • Avoid "No such file or directory" if module ancestor doesn't exist (PR 5785)
  • Add option to raise exception on internal errors (Joel Croteau, PR 5768)

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:

  • Bryan Forbes
  • Chris Philip
  • Daniel Darabos
  • dgelessus
  • Eric Chang
  • Ethan Smith
  • Evan Kepner
  • Florian Bruhin
  • Jakub Stasiak
  • Joannah Nanjekye
  • Joel Croteau
  • Maarten ter Huurne
  • Michael Lee
  • Sebastian Rittau
  • Tomasz Walotek
  • Wiktor Niesiobędzki

Additional thanks to all contributors to typeshed:

  • Adam Simpkins
  • Andrew Svetlov
  • anentropic
  • Brandt Bucher
  • Daniel Li
  • Dave Halter
  • David Zbarsky
  • Dev Aggarwal
  • dgelessus
  • Diego Elio Pettenò
  • edgchen1
  • Ethan Smith
  • Fionn Fitzmaurice
  • Florian Bruhin
  • Gregory P. Smith
  • Grzegorz Śliwiński
  • Hannes Karppila
  • Jakub Stasiak
  • Jelle Zijlstra
  • Jerome Leclanche
  • Jared Hance
  • Joel Rosdahl
  • Joey Wilhelm
  • Keith Gray
  • Lourens Veen
  • Maarten ter Huurne
  • Marco Leogrande
  • Matt Gilson
  • MatthewPScott81
  • Maxim Kurnikov
  • Michael
  • Michael Lee
  • Michael R. Crusoe
  • Opal Symes
  • Pascal Corpet
  • Peter Pentchev
  • PRAJWAL M
  • Rebecca Chen
  • Ruud van Asseldonk
  • Sebastian Rittau
  • Semyon Proshev
  • Siva Chandra
  • Summon528
  • thautwarm
  • Utkarsh Gupta
— Jukka Lehtosalo, on behalf of the mypy team