Mon Mar 18 14:33:02 UTC 2024 - Dan Čermák <dcermak@suse.com>
New upstream release 1.9.0
#### Breaking Changes
Because the version of typeshed we use in mypy 1.9 doesn't support 3.7, neither does mypy 1.9. (Jared Hance, PR [16883](https://github.com/python/mypy/pull/16883))
We are planning to enable
[local partial types](https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-local-partial-types) (enabled via the
`--local-partial-types` flag) later this year by default. This change
was announced years ago, but now it's finally happening. This is a
major backward-incompatible change, so we'll probably include it as
part of the upcoming mypy 2.0 release. This makes daemon and
non-daemon mypy runs have the same behavior by default.
Local partial types can also be enabled in the mypy config file:
```
local_partial_types = True
```
We are looking at providing a tool to make it easier to migrate
projects to use `--local-partial-types`, but it's not yet clear whether
this is practical. The migration usually involves adding some
explicit type annotations to module-level and class-level variables.
#### Basic Support for Type Parameter Defaults (PEP 696)
This release contains new experimental support for type parameter
defaults ([PEP 696](https://peps.python.org/pep-0696)). Please try it
out! This feature was contributed by Marc Mueller.
Since this feature will be officially introduced in the next Python
feature release (3.13), you will need to import `TypeVar`, `ParamSpec`
or `TypeVarTuple` from `typing_extensions` to use defaults for now.
This example adapted from the PEP defines a default for `BotT`:
```python
from typing import Generic
from typing_extensions import TypeVar
class Bot: ...
BotT = TypeVar("BotT", bound=Bot, default=Bot)
class Context(Generic[BotT]):
bot: BotT
class MyBot(Bot): ...
# type is Bot (the default)
reveal_type(Context().bot)
# type is MyBot
reveal_type(Context[MyBot]().bot)
```
#### Type-checking Improvements
* Fix missing type store for overloads (Marc Mueller, PR [16803](https://github.com/python/mypy/pull/16803))
* Fix `'WriteToConn' object has no attribute 'flush'` (Charlie Denton, PR [16801](https://github.com/python/mypy/pull/16801))
* Various documentation improvements (Shantanu, PR [16836](https://github.com/python/mypy/pull/16836))
#### Stubtest Improvements
* Ignore private function/method parameters when they are missing from the stub (private parameter names start with a single underscore and have a default) (PR [16507](https://github.com/python/mypy/pull/16507))
* Ignore a new protocol dunder (Alex Waygood, PR [16895](https://github.com/python/mypy/pull/16895))
* Private parameters can be omitted (Sebastian Rittau, PR [16507](https://github.com/python/mypy/pull/16507))
* Add support for setting enum members to "..." (Jelle Zijlstra, PR [16807](https://github.com/python/mypy/pull/16807))
* Adjust symbol table logic (Shantanu, PR [16823](https://github.com/python/mypy/pull/16823))
* Fix posisitional-only handling in overload resolution (Shantanu, PR [16750](https://github.com/python/mypy/pull/16750))
#### Stubgen Improvements
* Fix crash on star unpack of TypeVarTuple (Ali Hamdan, PR [16869](https://github.com/python/mypy/pull/16869))
* Use PEP 604 unions everywhere (Ali Hamdan, PR [16519](https://github.com/python/mypy/pull/16519))
* Do not ignore property deleter (Ali Hamdan, PR [16781](https://github.com/python/mypy/pull/16781))
* Support type stub generation for `staticmethod` (WeilerMarcel, PR [14934](https://github.com/python/mypy/pull/14934))
Sun Aug 13 06:30:29 UTC 2023 - Sebastian Wagner <sebix@sebix.at>
- update to version 1.5.0:
- Drop Support for Python 3.7
- Mypy no longer supports running with Python 3.7, which has reached end-of-life. This was contributed by Shantanu (PR 15566).
- Optional Check to Require Explicit @override
- If you enable the explicit-override error code, mypy will generate an error if a method override doesn’t use the @typing.override decorator (as discussed in PEP 698). This way mypy will detect accidentally introduced overrides.
- You can enable the error code via --enable-error-code=explicit-override on the mypy command line or enable_error_code = explicit-override in the mypy config file.
- The override decorator will be available in typing in Python 3.12, but you can also use the backport from a recent version of typing_extensions on all supported Python versions.
- More Flexible TypedDict Creation and Update
- Mypy was previously overly strict when type checking TypedDict creation and update operations. Though these checks were often technically correct, they sometimes triggered for apparently valid code. These checks have now been relaxed by default. You can enable stricter checking by using the new --extra-checks flag.
- Deprecated Flag: --strict-concatenate
- The behavior of --strict-concatenate is now included in the new --extra-checks flag, and the old flag is deprecated.
- Optionally Show Links to Error Code Documentation
- If you use --show-error-code-links, mypy will add documentation links to (many) reported errors. The links are not shown for error messages that are sufficiently obvious, and they are shown once per error code only.
- Consistently Avoid Type Checking Unreachable Code
- If a module top level has unreachable code, mypy won’t type check the unreachable statements. This is consistent with how functions behave. The behavior of --warn-unreachable is also more consistent now.
- Experimental Improved Type Inference for Generic Functions
- You can use --new-type-inference to opt into an experimental new type inference algorithm. It fixes issues when calling a generic functions with an argument that is also a generic function, in particular. This current implementation is still incomplete, but we encourage trying it out and reporting bugs if you encounter regressions. We are planning to enable the new algorithm by default in a future mypy release.
- Partial Support for Python 3.12
- Mypy and mypyc now support running on recent Python 3.12 development versions. Not all new Python 3.12 features are supported, and we don’t ship compiled wheels for Python 3.12 yet.
- Improvements to Dataclasses
- Improve signature of dataclasses.replace (Ilya Priven, PR 14849)
- Add get_expression_type to CheckerPluginInterface (Ilya Priven, PR 15369)
- Remove parameters that no longer exist from NamedTuple._make() (Alex Waygood, PR 15578)
- Allow using typing.Self in __new__ with an explicit @staticmethod decorator (Erik Kemperman, PR 15353)
- Fix self types in subclass methods without Self annotation (Ivan Levkivskyi, PR 15541)
- Check for abstract class objects in tuples (Nikita Sobolev, PR 15366)
- Typeshed Updates
- Typeshed is now modular and distributed as separate PyPI packages for everything except the standard library stubs. Please see git log for full list of typeshed changes.
Sun May 7 09:54:51 UTC 2023 - Sebastian Wagner <sebix@sebix.at>
- update typed_ast to version 1.5.8.6
- update types_psutil to version 5.9.5.12
- update types_setuptools to version 67.7.0.1
- fix "E: wrong-script-end-of-line-encoding" and "E: spurious-executable-perm" for docs/make.bat
- fix "W: python-doc-in-package" for %{$python_sitelib}/mypyc/doc in Python 3.9, 3.10 and 3.11
- update mypy to version 1.2.0:
- Improvements to Dataclass Transforms
- Support implicit default for "init" parameter in field specifiers (Wesley Collin Wright and Jukka Lehtosalo, PR 15010)
- Support descriptors in dataclass transform (Jukka Lehtosalo, PR 15006)
- Fix frozen_default in incremental mode (Wesley Collin Wright)
- Fix frozen behavior for base classes with direct metaclasses (Wesley Collin Wright, PR 14878)
- Mypyc: Native Floats
- Mypyc now uses a native, unboxed representation for values of type float. Previously these were heap-allocated Python objects. Native floats are faster and use less memory. Code that uses floating-point operations heavily can be several times faster when using native floats.
- Various float operations and math functions also now have optimized implementations. Refer to the documentation for a full list.
- This can change the behavior of existing code that uses subclasses of float. When assigning an instance of a subclass of float to a variable with the float type, it gets implicitly converted to a float instance when compiled
- Previously, implicit conversions were applied to int subclasses but not float subclasses.
- Also, int values can no longer be assigned to a variable with type float in compiled code, since these types now have incompatible representations. An explicit conversion is required.
- This restriction only applies to assignments, since they could otherwise narrow down the type of a variable from float to int. int values can still be implicitly converted to float when passed as arguments to functions that expect float values.
- Note that mypyc still doesn’t support arrays of unboxed float values. Using list[float] involves heap-allocated float objects, since list can only store boxed values. Support for efficient floating point arrays is one of the next major planned mypyc features.
- Related changes:
- Use a native unboxed representation for floats (Jukka Lehtosalo, PR 14880)
- Document native floats and integers (Jukka Lehtosalo, PR 14927)
- Fixes to float to int conversion (Jukka Lehtosalo, PR 14936)
- Mypyc: Native Integers
- Mypyc now supports signed 32-bit and 64-bit integer types in addition to the arbitrary-precision int type. You can use the types mypy_extensions.i32 and mypy_extensions.i64 to speed up code that uses integer operations heavily.
- Refer to the documentation for more information. This feature was contributed by Jukka Lehtosalo.
- Other Mypyc Fixes and Improvements
- Support iterating over a TypedDict (Richard Si, PR 14747)
- Faster coercions between different tuple types (Jukka Lehtosalo, PR 14899)
- Faster calls via type aliases (Jukka Lehtosalo, PR 14784)
- Faster classmethod calls via cls (Jukka Lehtosalo, PR 14789)
- Fixes to Crashes
- Fix crash on class-level import in protocol definition (Ivan Levkivskyi, PR 14926)
- Fix crash on single item union of alias (Ivan Levkivskyi, PR 14876)
- Fix crash on ParamSpec in incremental mode (Ivan Levkivskyi, PR 14885)
- Documentation Updates
- Update adopting --strict documentation for 1.0 (Shantanu, PR 14865)
- Some minor documentation tweaks (Jukka Lehtosalo, PR 14847)
- Improve documentation of top level mypy: disable-error-code comment (Nikita Sobolev, PR 14810)
- Error Reporting Improvements
- Add error code to typing_extensions suggestion (Shantanu, PR 14881)
- Add a separate error code for top-level await (Nikita Sobolev, PR 14801)
- Recognise typing.LiteralString and typing_extensions.LiteralString as aliases to str.
- This does not add proper support for LiteralString, but this allows it to be used in type annotations and stubs. LiteralString will be included in Python 3.11 (PEP 675), and it can be used to require that a value is an arbitrary literal string (once fully supported).
- Per-file Timing Stats
- When mypy is run with the (currently hidden) --timing-stats FILE option, mypy will record detailed information about time spent type checking each file (microseconds). When profiling mypy runs over a large codebase, it can be useful to know which files are the slowest to type check. We are happy to receive bug reports about unexpectedly slow type checking.
- Performance Improvements
- Cache type of container literals when possible (Hugues, PR 12707)
- Speed up type checking of nested if expressions (Hugues, PR 12700)
- Speed up type checking of container literals with tuple entries (Hugues, PR 12706)
- Speed up argument count check (Hugues, PR 12703)
- Speed up processing large error counts and improve error filtering (Hugues, PR 12631)
- Experimental Fast Module Lookup
- Use the new --fast-module-lookup to switch to an alternative import resolution implementation that is faster when a large number of folders share a top-level namespace. We’d like to hear if you notice an improvement when using this flag, so that we can potentially prioritize work to enable this by default.
- Documentation Updates
- Add information about classes and types to “Getting started” (Michael Lee, PR 6557)
- Mention no_type_check decorator in documentation (Shantanu, PR 12713)
- Remove most mentions of type comments from docs (Shantanu, PR 12683)
- Use PEP 585 syntax in "The type of class objects" (Alex Waygood, PR 12516)
- Improvements to Plugin System
- Add a class attribute hook to the plugin system (Danny Weinberg, PR 9881)
- Add an alternative class decorator hook that is less error-prone than the old one (Jukka Lehtosalo, PR 12762)
- ParamSpec Improvements
- Friendlier errors for ParamSpec (PEP 612) (Shantanu, PR 12832)
- Fix ParamSpec crash related to Any types (EXPLOSION, PR 12548)
- Use tuple[object, ...] and dict[str, object] as upper bounds for ParamSpec.args and ParamSpec.kwargs (Alex Waygood, PR 12668)
- stubtest: Generate error if type alias doesn't exist at runtime (Alex Waygood, PR 12608)
- Support typing_extensions.overload (Jelle Zijlstra, PR 12602)
- update to version 0.950:
- Recent third-party library stubs available via types-* packages (e.g. types-requests) are actively using recent typing features that may not be supported by older mypy releases. We recommend that if you pin mypy to a specific version, you should also pin any stub packages to a version no more recent than the mypy release. Otherwise the mypy version you use may silently fall back to Any types if it encounters annotation syntax that it can’t process. It’s fine to continue using older versions of stubs when you upgrade mypy.
- Note also that recent versions of many third-party stub packages don’t support Python 2 any more. If you are using mypy to type check Python 2 code, it’s important to pin all stub packages to versions that still support Python 2. Generally stub package versions: in Feb 2022 or earlier still support Python 2 (assuming that they supported Python 2 at all).
- New Features: Concatenate and Literals with ParamSpec
- It’s now possible to precisely annotate decorators that add/remove arguments, using ParamSpec together with typing.Concatenate (Python 3.10 or later) or typing_extensions.Concatenate. The decorator in this example provides an implicit Request argument to the decorated function.
- New Feature: Detect Unused Coroutines and Awaitables
- Now mypy will give an error if you forget to await a coroutine:
- If you enable the unused-awaitable error code, mypy will also complain about any unused value that supports __await__. This is not enabled by default, since this can cause false positives.
- New Feature: assert_type
- You can now use typing_extensions.assert_type to ask mypy to validate that an expression has a specific static type. Mypy will report an error if the inferred type is not as expected:
- from typing_extensions import assert_type
- assert_type([1], list[int]) # OK
- # Error: Expression is of type "List[int]", not "List[str]"
- assert_type([1], list[str])
- This can be used to validate that the expected type is inferred by mypy when calling a complex overloaded function, for example. At runtime assert_type just returns the first argument and doesn’t perform a runtime type check.
- Mypyc Fixes and Improvements
- Fix overflow in id built-in (Ekin Dursun, PR 12332)
- Simplify generated code for native attribute get (Jukka Lehtosalo, PR 11978)
- Implement close method for generators (Max Shvets, PR 12042)
- Use more accurate flags with msvc (KotlinIsland, PR 12468)
Mon Mar 14 21:35:28 UTC 2022 - Sebastian Wagner <sebix+novell.com@sebix.at>
- Update to version 0.940:
- Match Statement
Mypy now has experimental support for type checking match statements introduced in Python 3.10.
- Python 2 End-of-Life Schedule
After this release, Python 2 support is in feature freeze. Mypy won’t add new features or fixes specific to type checking Python 2 code, expect for fixes of significant regressions.
Mypy will drop Python 2 support in the second half of 2022.
Important note: Since typeshed is in the process of removing Python 2 specific stubs, you should pin all installed typeshed stub packages for third-party libraries to a version from Feb 2022 or earlier if you want to type check Python 2 code.
- Miscellaneous New Features
- Add support for conditionally defined overloads (Marc Mueller, PR 10712)
- Give "as" variables in with statements separate scopes when it is safe to do so (Jukka Lehtosalo, PR 12254)
- Add an optional error code ignore-without-code to require ignore comments to have error codes (Peter Law, PR 11633)
- Add support for typing.Never and typing_extensions.Never as alternative spellings of NoReturn (Jelle Zijlstra, PR 12153)
- Add support for typing.reveal_type (Jelle Zijlstra, PR 12117)
- Support universal2 macOS wheels (97littleleaf11, PR 10651)
- Add match_args support to attr.s() (Nikita Sobolev, PR 12111)
- Enum Improvements
- Check Enum definition for invalid base classes (Nikita Sobolev, PR 12026)
- Understand the self-destructing nature of Enum._ignore_ (Kenny Stauffer, PR 12128)
- Add StrEnum support for Python 3.11 (Nikita Sobolev, PR 12035)
- Make enum values final (joey-laminar, PR 11962)
- Improve final detection for Enum (Nikita Sobolev, PR 11984)
- Fix Enum final properties and writable special members (Nikita Sobolev, PR 11945)
- Enum now accepts String literals and final values as 2nd argument (Vincent Perez, PR 8664)
- Fix false positive about member name reuse in enum (Max Rossmannek, PR 11972)
- Fix crash if "_" is in builtins (StefanM-TT, PR 11811)
- Fixes crash on subclassing Annotated without args (Nikita Sobolev, PR 11814)
- Typeshed Updates
- Typeshed is now modular and distributed as separate PyPI packages for everything except the standard library stubs. Please see git log for full list of typeshed changes.
Wed Dec 22 20:10:32 UTC 2021 - Sebastian Wagner <sebix+novell.com@sebix.at>
- Update to version 0.930:
- New Feature: Explicit Type Aliases (PEP 613)
- You can now explicitly mark an assignment as a type alias, by using typing.TypeAlias
- For more context, see the docs or PEP 613.
- New Feature: NotRequired in TypedDicts
- You can now define individual TypedDict items as non-required by using typing_extensions.NotRequired. Previously this could only be configured at TypedDict level (by using total=).
- You can also use typing_extensions.Required to mark an item as required in a non-total TypedDict.
- New Feature: ParamSpec (Experimental)
- Mypy now partially support ParamSpec, which was introduced in Python 3.10. This makes it possible to define type variables that range over the parameter specification of a callable type. In particular, it allows giving precise types for some decorators that change the return type of the decorated function.
- Miscellaneous New Features
- Define a GitHub Action that makes it easier to run mypy in GitHub CI workflows (Elvis Pranskevichus, PR 11320)
- Allow mypy to run self check on PyPy 3.8 beta (Ethan Smith, PR 11350)
- Check that enum values are unique (Nikita Sobolev, PR 11267)
- Make enum classess with values implicitly final (Nikita Sobolev, PR 11247)
- Make enum members implicitly final (Nikita Sobolev, PR 10852)
- Allow NamedTuple to be used as a type that accepts all named tuples, as an experimental extension (Nikita Sobolev, PR 11162)
- Allow booleans to be narrowed to literal types (Ethan Leba, PR 10389)
- Add slots=True support for @dataclass (Nikita Sobolev, PR 11483)
- Add slots=True support for @attr.s (Nikita Sobolev, PR 11489)
- Support the typing_extensions.OrderedDict alias (Nikita Sobolev, PR 11533)
Thu Dec 16 08:04:39 UTC 2021 - Sebastian Wagner <sebix+novell.com@sebix.at>
- Update to version 0.920:
- Making a Variable Optional in an Else Block
- Now mypy alllows more general conditionally defined variables with optional types. Previously mypy allowed this only if a None assignment happened first. Now this is also supported. Implemented by Michael J. Sullivan in PR 11002.
- Type Checking __slots__ Assignment
- For classes that define the special __slots__ attribute, mypy will now report an error on assigning to attributes that are not found in the slots definitions (this matches runtime semantics).
- Note that this feature does not work for dynamically computed slots. Implemented by Nikita Sobolev in PR 10864.
- Partial Python 3.10 Support
- We now ship binary wheels for Python 3.10 and mypy supports the new Python 3.10 union type syntax.
- Some new features, including the match statement, ParamSpec and TypeAlias are not supported yet.
- Python 3.5 Is No Longer Supported
- Python 3.5 reached its end of life more than a year ago. Its support was deprecated in mypy 0.910 and it is no longer supported in mypy 0.920.
- Efficient String and Bytes Formatting in Mypyc
- Most string and bytes formatting methods now use fast C-level logic when compiled with mypyc. This includes % formatting, the format() method, and f-strings. This was implemented by 97littleleaf11 as part of a Google Summer of Code project.
- Work Towards singledispatch Support
- The signature of the initial function variant handles the generic case and describes the external signature of the singledispatch function.
- This was implemented Pranav Rajpal as part of a Google Summer of Code project.
- Stubgen Improvements
- Add support for yield statements in stubgen (Sebastian Rittau, PR 10745)
- Handle commas in namedtuple field definition in stubgen (Vanessa Ung, PR 10828)
- Other Notable Fixes and Improvements
- Allow plugin signature hooks to return FunctionLike (to support overloads) (pranavrajpal, PR 10717)
- Narrow type with type variable when the upper bound is a subtype of current type (ethframe, PR 10658)
- Make --cache-fine-grained imply --local-partial-types (Michael J. Sullivan, PR 10737)
- Support new union syntax in stubs independent of target Python version and in runtime context (PR 10770, PR 10771) (Jukka Lehtosalo)
- Support new union type syntax with isinstance() (Jukka Lehtosalo, PR 10775)
- Better message if method is incompatible with base class (Anmol Takiar, PR 10572)
Sun Jul 4 20:06:55 UTC 2021 - Sebastian Wagner <sebix+novell.com@sebix.at>
- update to version 0.910:
- 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.
- 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.
- 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)
- update to version 0.900:
- Third-party Library Stubs in Stub Packages (Breaking Change)
- Mypy now only ships with type stubs for stdlib modules (plus typing_extensions and mypy_extensions). If you use third-party libraries that don’t include stubs or inline type annotations, you can explicitly install stub packages, usually called types-<name>.
- You can also now run mypy --install-types to install all missing stub packages in the mypy run (or the previous run, if you don’t pass any files to check).
- Using cached types_requests-0.1.8-py2.py3-none-any.whl (22 kB)
- For more information, read the blog post about this change and why we did this. There is more detail in the docs.
- Python 2 Support is Opt-in (Breaking Change)
- If you want to type check Python 2 code, you now have to install mypy[python2] using pip (on Python 3.8 and later):
- python3 -m pip install -U mypy[python2]
- This will install the additional typed-ast pip dependency that is required for Python 2 support. Type checking Python 2 code is still fully supported by mypy.
- TypeGuard
- Mypy now supports defining user-defined functions that perform type narrowing, similar to isinstance. Read PEP 647 for the details.
- Since TypeGuard will be included in Python 3.10, which hasn’t been released yet, you will have to import it from a recent version of typing_extensions for now.
- Support for pyproject.toml
- Binary Wheels for Apple Silicon
- We now include binary wheels for Apple Silicon. This can make mypy runs over 4x faster on supported hardware. This requires a native Apple Silicon build of Python 3.9 to work.
- Type Narrowing with type(x)
- Hosted Documentation for Mypyc
- We now have hosted user documentation for mypyc, the compiler we use to speed up mypy. Mypyc is still experimental, but we are looking for early adopters.
- New Mypyc Features
- Support __setitem__, __delitem__, __len__ and __contains__ in native classes (PR 10451)
- Basic support for class-based named tuples (PR 10252)
- Support class-based TypedDict definitions (PR 10226)
- Mypyc Performance Improvements
- Pre-allocate space in list comprehensions (97littleleaf11, PR 10295)
- Faster dict true test (97littleleaf11, PR 10333)
- Issue an error when overriding typeguard with non-typeguard in subclass (Kamil Turek, PR 10300)
- Support functools.total_ordering (Ashley Whetter, PR 7831)
- Support reversed operand order when comparing against sys.version_info (Kamil Turek, PR 10288)
- Only import distutils if it is needed (Adrian Freund, PR 10203)
- Recombine complete union of enum literals into original type (PR 9097, PR 9063) (Ethan Leba)
- Support union type arguments when showing protocol member conflicts (97littleleaf11, PR 10154)
- Fix recently added enum value type prediction (Paddy, PR 10057)
- Support subclassing of NodeVisitor and TraverserVisitor in plugins (Nikita Sobolev, PR 10125)
- Speed up processing of new files in daemon by caching ASTs (PR 10128)
- Add narrowing and closures to common issues (Shantanu, PR 9956)
- Add Python script to build wheels using cibuildwheel (PR 10096)
- Don't try to follow imports to encodings.* (PR 10094)
- Speed up case sensitive is-file check in file system cache (PR 10093)
- Use fast path for finding modules in mypy daemon (PR 10095)
- Fix following stub imports in daemon when using --follow-imports=skip (PR 10092)
- Use sys.executable instead of python3 for --install-types (Anthony Sottile, PR 10086)
- Add build-requirements.txt to MANIFEST.in (PR 10071)
- Add separate requirements file for mypy self-compile (PR 10069)
- Expand user home for cache_dir (Marco Zatta, PR 10051)
- Fix daemon crash when deleting packages (PR 10036)
- Keep track of fine-grained dependencies for modules in typeshed (PR 10034)
- Fix import following issue in daemon (PR 10032)
- Fix mypy daemon crash when following from a new module (PR 10030)
- Detect invalid value for --custom-typeshed-dir (PR 9985)
- Fix pip install for new typeshed (Ivan Levkivskyi, PR 9976)
- Report incompatible assignments for descriptors with overloaded __set__ methods (Christoph Tyralla, PR 9893)
- Fix TypedDict.get("missing_key") with string literal (Adrian Freund, PR 9906)
- update to version0.812L
- Improved Source File Finding
- Mypy 0.800 changed how mypy finds modules if you run mypy as mypy directory/ or mypy -p package. Mypy started looking for source files in directories without a __init__.py file. This is often the expected behavior, and it avoids excluding some files that should be type checked.
- However, this caused issues for some users, such as when using mypy . to type check all files under the current directory. Mypy could now try to type check files inside nested virtual environments and node_modules directories, which is usually not desirable. This could result in mypy needlessly complaining about duplicate module names, in particular.
- Now mypy will skip directories named site-packages or node_modules, and any directory beginning with a dot (such as .git) when recursively looking for files to check.
- This doesn’t affect how mypy resolves imports — it only affects when mypy is given a directory or a package to type check. You can override the exclusions by explicitly passing the files on the command line.
- Excluding Paths
- Mypy now supports the --exclude regex command line option to exclude paths matching a regular expression when searching for files to type check. For example, mypy --exclude '/setup\.py$' skips all setup.py files. This lets you exclude additional paths that mypy started finding after mypy 0.800 changed module finding behavior, as discussed above.
- You can also specify this in the config file (exclude=regex). The option expects forward slashes as directory separators on all platforms, including Windows, for consistency.
Sat Feb 20 11:05:11 UTC 2021 - Sebastian Wagner <sebix+novell.com@sebix.at>
- Update to version 0.812
- Improved Source File Finding
- Mypy 0.800 changed how mypy finds modules if you run mypy as mypy directory/ or mypy -p package. Mypy started looking for source files in directories without a __init__.py file. This is often the expected behavior, and it avoids excluding some files that should be type checked.
However, this caused issues for some users, such as when using mypy . to type check all files under the current directory. Mypy could now try to type check files inside nested virtual environments and node_modules directories, which is usually not desirable. This could result in mypy needlessly complaining about duplicate module names, in particular.
Now mypy will skip directories named site-packages or node_modules, and any directory beginning with a dot (such as .git) when recursively looking for files to check.
This doesn’t affect how mypy resolves imports — it only affects when mypy is given a directory or a package to type check. You can override the exclusions by explicitly passing the files on the command line.
- Excluding Paths
- Mypy now supports the --exclude regex command line option to exclude paths matching a regular expression when searching for files to type check. For example, mypy --exclude '/setup\.py$' skips all setup.py files. This lets you exclude additional paths that mypy started finding after mypy 0.800 changed module finding behavior, as discussed above.
- You can also specify this in the config file (exclude=regex). The option expects forward slashes as directory separators on all platforms, including Windows, for consistency.
Sat Jan 23 19:22:44 UTC 2021 - Sebastian Wagner <sebix+novell.com@sebix.at>
- Update to version 0.800:
- Python 3.9 Support
- Typing Usability Improvements (PEP 585 and PEP 604)
The necessity to repeatedly import various types and special forms from typing has been a long-term nuisance for users of static type checking and Python.
Two new Python features improve this situation and are now supported by mypy:
PEP 585 lets you use list[int] instead of List[int] (no need to import List and other generic collections from typing).
PEP 604 lets you write X | Y instead of Union[X, Y], and X | None instead of Optional[X] (no need to import Union or Optional from typing).
Note: Using list[int] requires Python 3.9 and X | Y requires Python 3.10 (alpha) in order to work at runtime. To use them on older versions of Python, use from __future__ import annotations. This allows them to be used in type annotations, but the older variants (or string literal escaping) may be required in non-annotation contexts, such as in type aliases. See the docs for more details.
Here is an example that uses the new features:
from __future__ import annotations
def fields(s: str | None) -> list[str]:
if not s:
return []
else:
return s.split(',')
These were implemented by Allan Daemon in PR 9564 and by Marc Mueller in PR 9647.
- Improvements to Finding Modules
This release adds several improvements to how mypy finds Python source files to type check.
You can now pass paths to files within namespace packages on the command line, and mypy can better infer their module names. As before, use --namespace-packages to enable namespace packages.
When you use --explicit-package-bases together with --namespace-packages, mypy assumes that only the current directory and directories explicitly specified in MYPYPATH (or mypy_path in the config file) are valid package roots. This can help with situations where the module name of a file is ambiguous. For example, it may not be clear whether src/pkg/mod.py should be treated as src.pkg.mod or pkg.mod, and you can use this option to disambiguate between the two (more information in the docs).
The above improvements were implemented in PR 9742 by Shantanu.
Other related improvements (also implemented by Shantanu):
- When you run mypy as mypy <directory>, look for source files recursively also inside directories without a __init__.py (PR 9614)
- Support namespace packages with -p (PR 9683)
- Log encountered source files when running mypy with -v (PR 9672)
- Document the new module finding behavior (PR 9923)
- Other Notable Improvements and Bug Fixes
- Only treat import X as X as a re-export in stubs (Shantanu, PR 9515)
- Fix package imports with aliases in stubgen (Chad Dombrova, PR 9534)
- Require first argument of namedtuple() to match the variable name (Momoko Hattori, PR 9577)
- Add error code for name mismatches in named tuples and TypedDicts to make it easy to disable these error messages (Jukka Lehtosalo, PR 9811)
Sun Oct 11 06:53:29 UTC 2020 - Sebastian Wagner <sebix+novell.com@sebix.at>
- update to version 0.790:
- 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.
- 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.
Sat Jul 4 12:28:39 UTC 2020 - Sebastian Wagner <sebix+novell.com@sebix.at>
- update to version 0.780:
- Following Imports in Mypy Daemon
- You can now leave out the --follow-imports option when running dmypy, and mypy daemon will follow imports, similar to a non-daemon mypy run.
Previously mypy daemon did not support this, and it was necessary to use --follow-imports and explicitly mention all files to check on the command line. (Following imports in mypy daemon is an experimental feature.)
See the docs about following import in mypy.
- Miscellaneous New Features:
- Support environment variable interpolation for junit_xml configuration key (Mattwmaster58, PR 8479)
- Many small improvements were made to typeshed — too many to list. Browse the typeshed commit log here.
- update to version 0.770:
- Tagged Unions
- Previously, the only way to distinguish between two types in a union was to use an isinstance check. Now, mypy supports distinguishing between two or more types based on the value of some common shared "tag" field.
This feature is most useful when you want to narrow down a union of TypedDicts: since TypedDicts are really just regular dicts at runtime, using isinstance checks won't work. Instead, you can now label or tag each TypedDict with a distinct Literal type and discriminate by checking that tag.
Note that you can import Literal from typing_extensions on Python 3.7 and earlier.
You can also use this technique to discriminate between unions of objects, tuples, or named tuples, so long as: 1. Every item in your union is tagged with a unique value 2. Mypy understands how to narrow the union of the tag values.
For more details and examples, see the documentation on tagged unions.
- Type Inference Improvements
Type inference is now more powerful. Mypy can infer types in some cases where you previously needed an explicit type annotation.
Mypy can infer a built-in collection type from augmented assignment statements.
Some dictionary construction idioms are better supported.
Mypy is better at inferring defaultdict types.
- Multiple Inheritance and isinstance() Checks
Previously, mypy assumed a variable cannot have two unrelated types when analyzing isinstance checks. For example, in the following example B is not a subclass of A, so mypy would incorrectly conclude the isinstance check is always false, and that the if-branch is unreachable — even though var could actually be a subtype of both types.
This meant that mypy skipped type checking anything inside the if statement, since it (by design) skips analyzing unreachable branches.
Now, mypy will instead decide that the narrowed type of x is test.<subclass of "A" and "B">, instead of marking the branch as unreachable.
If it’s impossible for two types to be a subtype of one another, mypy will continue to not attempt to infer this "ad-hoc intersection".
- Other Notable Improvements and Bug Fixes:
- Fix some crash bugs involving import * and import cycles (PR 8450)
- Fix interaction of descriptor methods with plugins (Jan Verbeek, PR 8365)
- Allow strict in config file (Ville Skyttä, PR 8192)
- Don’t crash when a module shadows builtin libraries (such as typing or types, PR 8405)
- Fix type join between subclasses of unicode and str (PR 8402)
- Fix type join of fixed-length tuples with mismatching lengths (Marti Raudsepp, PR 8333)
- Fix type join of Sequence (e.g. variadic tuple) and fixed-length tuple (Marti Raudsepp, PR 8335)
- Make mypy.api.run_dmypy actually capture the output (PR 8375)
- Support determining whether a literal is truthy (Jan Verbeek, PR 8368)
- Update documentation for Literal types (Michael Lee, PR 8152)
- Stubtest rewrite
stubtest is a tool that compares stub definitions to what it finds at runtime with introspection and reports back inconsistencies. It got a complete rewrite. Some features of the new stubtest are:
- Find missing, extraneous or mistyped classes, methods, functions and attributes in the stubs
- Check presence, names and kinds of function arguments, accounting for overloads, decorators, *args and kwargs. Checks argument types against their default values, accounting for type vars.
Mon Jul 15 19:52:39 UTC 2019 - Sebastian Wagner <sebix+novell.com@sebix.at>
- Update to version 0.720:
- New Semantic Analyzer Used by Default
- New Feature: Warn about Unreachable Code
- Plugin API Changes
- Notable Improvements and Bug Fixes
- Have --package usage respect mypy_path (Aaron Batilo, PR 6926)
- Support flexible option specification in config files. Now all the flags support invertible forms so that one can specify either strict_optional = False or no_strict_optional = True. This matches how flags work on the command line (PR 7054)
Sun Jun 30 11:35:29 UTC 2019 - Sebastian Wagner <sebix+novell.com@sebix.at>
- update to version 0.711:
- Revert typeshed PR 2878 (“Define functools.partial as overloaded function instead of its own class”). This caused too many false positive errors in real-world code. (PR 3077)
- Fix MYPYC_BLACKLIST on Windows. This broke running dmypy on Windows. (PR 7032)
Sat Oct 21 20:44:08 UTC 2017 - sebix+novell.com@sebix.at
- update to 0.540
* Switch to More Rapid Releases
new mypy version roughly every 2-4 weeks
* New Features
* Allow assignments to multiple targets from union types (Ivan Levkivskyi, PR 4067)
* Allow definitions of subscripted type aliases such as Item = Tuple[int, str] within functions (Ivan Levkivskyi, PR 4000)
* Narrow type of optional left operand of in operator if the collection items aren’t optional (Ivan Levkivskyi, PR 4072)
* Generate an error if <unknown> type would be inferred for a variable (PR 4112)
* Notable Bugs Fixed
* Fix errors not being reported for some modules with incremental mode by deleting cache file for a module if errors are found (Ivan Levkivskyi, PR 4045)
* Fix incremental mode crash related to Type[...] types (Ivan Levkivskyi, PR 4038)
* Fix crash related to tuple types (Ivan Levkivskyi, PR 4051)