We’ve just uploaded mypy 0.910 to the Python Package Index (PyPI). Mypy is a static type checker for Python. This is a small feature release that includes a new command-line option --non-interactive for installing stub (type) packages without asking for a confirmation, fixes to regressions, and a few other improvements. 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.
Installing Stub Packages Non-Interactively
Mypy 0.900 added --install-types to install missing stub packages. We received feedback that this wasn’t a good fit for all use cases, since it asks for interactive confirmation from the user, and it requires another mypy invocation to actually perform type checking.
This release adds the new option --non-interactive that can be used with --install-types to install suggested stub packages without asking for confirmation. This can be useful in Continuous Integration jobs. The option causes mypy to both install stub packages and perform type checking within a single invocation. When not using --non-interactive, you’d have to run mypy again to get up-to-date results with the installed stubs.
Here’s an example of using --non-interactive:
$ mypy --install-types --non-interactive src/ Installing missing stub packages: /Users/jukka/venv/mypy/bin/python3 -m pip install types-requests Collecting types-requests Downloading types_requests-2.25.0-py3-none-any.whl (22 kB) Installing collected packages: types-requests Successfully installed types-requests-2.25.0 Success: no issues found in 15 source files
This option provides a new way to migrate existing mypy runner scripts after updating to mypy 0.9xx: just add the --install-types --non-interactive options to your mypy command line.
Note that --install-types currently always installs the latest stubs for all supported packages. If you want reproducible results from your builds, we recommend explicitly pinning stub package versions in your requirements.txt file, for example.
Python 3.5 Deprecation
Running mypy on Python 3.5 is now deprecated. A future mypy release will drop Python 3.5 support. We haven’t decided when this will happen, but this might happen in the next feature release after 0.910.
- Don't annotate unknown argument and return types (Sebastian Rittau, PR 10626)
- Never generate a variable initializer (Sebastian Rittau, PR 10623)
- Use NamedTuple class syntax (Sebastian Rittau, PR 10625)
- Use T | None (PEP 604) instead of Optional[T] (Sebastian Rittau, PR 10624)
Other Fixes and Improvements
- Fix some crashes from faulty casts (Shantanu, PR 10560)
- Update docs for deferral of PEP 563 to 3.11 (Smart, PR 10655)
- Don't suggest to install stubs for packages with py.typed files (Sebastian Rittau, PR 10652)
- Correct the type package name of pyopenssl ( Sebastian Rittau, PR 10656)
- Improve error reporting when --install-types has no cache (PR 10667)
- Suggest types-setuptools for pkg_resources (Sebastian Rittau, PR 10681)
- Fix crash with assignment to variable guarded with TypeGuard (PR 10683)
- Don't ask to install a stub package if stubs are installed (PR 10670)
- Fix crash when inferring multiple assignment with overloaded function (PR 10689)
There are no typeshed updates in this release.
Thanks to all mypy contributors who contributed to this release:
- Sebastian Rittau
We’d also like to thank our employer, Dropbox, for funding the mypy core team.