Skip to content

Update mypy to 2.3.0 - #595

Open
pyup-bot wants to merge 1 commit into
masterfrom
pyup-update-mypy-0.670-to-2.3.0
Open

Update mypy to 2.3.0#595
pyup-bot wants to merge 1 commit into
masterfrom
pyup-update-mypy-0.670-to-2.3.0

Conversation

@pyup-bot

@pyup-bot pyup-bot commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

This PR updates mypy from 0.670 to 2.3.0.

Changelog

2.3

We've just uploaded mypy 2.3.0 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).
Mypy is a static type checker for Python. This release includes new features, performance
improvements and bug fixes. 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](http://mypy.readthedocs.io).

The Upcoming Switch to the New Native Parser

We are planning to enable the new native parser (`--native-parser`) by
default soon. We recommend that you test the native parser in your projects and report
any issues in the [mypy issue tracker](https://github.com/python/mypy/issues).

Mypyc Free-threading Memory Safety

Free-threaded Python builds that don't have the GIL require additional synchronization
primitives or lock-free algorithms to ensure memory safety when there are race conditions
(for example, when a thread reads a list item while another thread writes the same list
item concurrently). This release greatly improves memory safety of free threading.

List operations are now memory-safe on free threaded Python builds, even in the presence of
race conditions. This has some performance cost. For list-heavy workloads, using
`librt.vecs.vec` instead of list is often significantly faster, but note that `vec` is not
(and likely won't be) fully memory safe, and the user is expected to avoid race conditions.
The newly introduced `librt.threading.Lock` helps with this. Using variable-length tuples
can also be more efficient than lists, since tuples are immutable and don't require
expensive synchronization to ensure memory safety.

Instance attribute access is also (mostly) memory safe now on free-threaded builds in
the presence of race conditions. We are planning to fix the remaining unsafe cases in a
future release.

Full list of changes:

- Make attribute access memory safe on free-threaded builds (Jukka Lehtosalo, PR [21705](https://github.com/python/mypy/pull/21705))
- Fix unsafe borrowing of instance attributes with free-threading (Jukka Lehtosalo, PR [21688](https://github.com/python/mypy/pull/21688))
- Make list get/set item more memory safe on free-threaded builds (Jukka Lehtosalo, PR [21683](https://github.com/python/mypy/pull/21683))
- Don't borrow list items on free-threaded builds (Jukka Lehtosalo, PR [21679](https://github.com/python/mypy/pull/21679))
- Make multiple assignment from list memory-safe on free-threaded builds (Jukka Lehtosalo, PR [21684](https://github.com/python/mypy/pull/21684))
- Make `for` loop over list memory-safe on free-threaded builds (Jukka Lehtosalo, PR [21686](https://github.com/python/mypy/pull/21686))
- Fix memory safety of `list.count` on free-threaded builds (Jukka Lehtosalo, PR [21680](https://github.com/python/mypy/pull/21680))
- Make `vec` creation from list memory safe on free-threaded builds (Jukka Lehtosalo, PR [21681](https://github.com/python/mypy/pull/21681))

librt.threading: Fast Native Lock Type

Mypyc now supports `librt.threading.Lock`, which is a lock type optimized for use
in compiled code. It can be 2x to 4x faster than `threading.Lock`.

This feature was contributed by Jukka Lehtosalo (PR [21690](https://github.com/python/mypy/pull/21690), PR [21697](https://github.com/python/mypy/pull/21697)).

Mypyc: Read-only Final Instance Attributes

Instance attributes of native classes declared as `Final` are now read-only at runtime.
This enables additional optimizations, and it's now recommended to use `Final` for
all performance-sensitive attributes when feasible.

Related changes:

- Make instance attribute read-only at runtime if `Final` (Jukka Lehtosalo, PR [21666](https://github.com/python/mypy/pull/21666))
- Borrow final attributes more aggressively (Jukka Lehtosalo, PR [21702](https://github.com/python/mypy/pull/21702))
- Improve documentation of `Final` in mypyc (Jukka Lehtosalo, PR [21713](https://github.com/python/mypy/pull/21713))

Mypyc Documentation Updates

- Update documentation of race conditions under free threading (Jukka Lehtosalo, PR [21726](https://github.com/python/mypy/pull/21726))
- Update mypyc free threading Python compatibility docs (Jukka Lehtosalo, PR [21711](https://github.com/python/mypy/pull/21711))
- Document recent additions to `librt.strings`, such as `ispace` (Jukka Lehtosalo, PR [21696](https://github.com/python/mypy/pull/21696))

Miscellaneous Mypyc Improvements

- Fix reference leak when setting unboxed refcounted attributes (Tom Bannink, PR [21657](https://github.com/python/mypy/pull/21657))
- Fix function wrapper memory leak (Piotr Sawicki, PR [21654](https://github.com/python/mypy/pull/21654))
- Fix handling of invalid codepoint values in `librt.strings` (Jukka Lehtosalo, PR [21634](https://github.com/python/mypy/pull/21634))
- Fix non-deterministic ordering of spilled registers (Jukka Lehtosalo, PR [21632](https://github.com/python/mypy/pull/21632))
- Fix non-deterministic compiler output due to frozensets (Jukka Lehtosalo, PR [21631](https://github.com/python/mypy/pull/21631))

Changes to Messages

- Fix error code of note about unbound type variable (Jukka Lehtosalo, PR [21668](https://github.com/python/mypy/pull/21668))

Other Notable Fixes and Improvements

- Use `PYODIDE` environment variable for Emscripten cross-compilation detection (Agriya Khetarpal, PR [21714](https://github.com/python/mypy/pull/21714))
- Narrow for frozendict membership check (Shantanu, PR [21709](https://github.com/python/mypy/pull/21709))
- Fix custom equality handling for membership narrowing in static containers (Shantanu, PR [21706](https://github.com/python/mypy/pull/21706))
- Infer `Coroutine` for unannotated async functions (Jingchen Ye, PR [21651](https://github.com/python/mypy/pull/21651))
- Fix variance inference issues caused by dataclass replace (Shantanu, PR [21694](https://github.com/python/mypy/pull/21694))
- Fix regression in dataclass narrowing for Python >= 3.13 (ygale, PR [21675](https://github.com/python/mypy/pull/21675))
- Fix star import dependencies in mypy daemon (Jukka Lehtosalo, PR [21673](https://github.com/python/mypy/pull/21673))
- Fix skipped imports considered stale (Piotr Sawicki, PR [21639](https://github.com/python/mypy/pull/21639))
- Support `.ff` files with `--cache-map` (Jukka Lehtosalo, PR [21633](https://github.com/python/mypy/pull/21633))

Typeshed Updates

Please see [git log](https://github.com/python/typeshed/commits/main?after=f76037a1eb3923c67a8bc0e302ee9c016ffb3431+0&branch=main&path=stdlib) for full list of standard library typeshed stub changes.

Acknowledgements

Thanks to all mypy contributors who contributed to this release:

- Agriya Khetarpal
- Ethan Sarp
- Ivan Levkivskyi
- Jingchen Ye
- Jukka Lehtosalo
- Piotr Sawicki
- Shantanu
- Tom Bannink
- Viktor Szépe
- ygale

I'd also like to thank my employer, Dropbox, for supporting mypy development.

2.2

We've just uploaded mypy 2.2.0 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).
Mypy is a static type checker for Python. This release includes new features, performance
improvements and bug fixes. 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](http://mypy.readthedocs.io).

Support for Closed TypedDicts (PEP 728)

Mypy now supports closed TypedDicts as specified in PEP 728. A closed TypedDict cannot have extra
keys beyond those explicitly defined. This allows the type checker to determine that certain
operations are safe when they otherwise wouldn't be due to the potential presence of unknown keys.

You can use the `closed` keyword argument with `TypedDict`:

python
HasName = TypedDict("HasName", {"name": str})
HasOnlyName = TypedDict("HasOnlyName", {"name": str}, closed=True)
Movie = TypedDict("Movie", {"name": str, "year": int})

movie: Movie = {"name": "Nimona", "year": 2023}
has_name: HasName = movie   OK: HasName is open (default)
has_only_name: HasOnlyName = movie   Error: HasOnlyName is closed and Movie has extra "year" key


Closed TypedDicts enable more precise type checking because the type checker knows exactly which
keys are present. This is particularly useful when working with TypedDict unions or when you want
to ensure that a TypedDict conforms to an exact shape.

The `closed` keyword also enables safe type narrowing with `in` checks:

python
Book = TypedDict('Book', {'book': str}, closed=True)
DVD = TypedDict('DVD', {'dvd': str}, closed=True)
type Inventory = Book | DVD

def print_type(inventory: Inventory) -> None:
 if "book" in inventory:
      Type is narrowed to Book here - safe because DVD is closed
     print(inventory["book"])
 else:
      Type is narrowed to DVD here
     print(inventory["dvd"])


The `closed` keyword is also supported in class-based syntax:

python
class HasOnlyName(TypedDict, closed=True):
 name: str


Note that closed TypedDicts are structural types, so a closed TypedDict is assignable to an open
TypedDict with the same keys, but not vice versa.

Contributed by Alice (PR [21382](https://github.com/python/mypy/pull/21382)).

Complete Support for Type Variable Defaults (PEP 696)

Mypy now has complete support for type variable defaults as specified in PEP 696. This allows you to
specify default values for type parameters in generic classes, functions, and type aliases.

Traditional syntax (Python 3.12 and earlier):

python
T = TypeVar("T", default=int)   This means that if no type is specified T = int

dataclass
class Box(Generic[T]):
 value: T | None = None

reveal_type(Box())                       type is Box[int]
reveal_type(Box(value="Hello World!"))   type is Box[str]


New syntax (Python 3.13+):

python
class Box[T = int]:
 def __init__(self, value: T) -> None:
     self.value = value

reveal_type(Box())                       type is Box[int]
reveal_type(Box(value="Hello World!"))   type is Box[str]


Type variable defaults work with all forms of generics, including classes, functions, and type aliases.
This release completes the implementation by fixing various edge cases involving recursive defaults,
dependencies between type variables, and interactions with variadic generics.

Contributed by Ivan Levkivskyi (PRs [21491](https://github.com/python/mypy/pull/21491),
[21526](https://github.com/python/mypy/pull/21526), [21544](https://github.com/python/mypy/pull/21544)).

Respect Explicit Return Type of `__new__()`

Mypy now respects explicitly annotated return types in `__new__()` methods. Previously, mypy would
always assume that `__new__()` returns an instance of the current class, ignoring explicit annotations.

With this change, if you explicitly annotate a return type that differs from the implicit type, mypy
will use the explicit annotation:

python
class Factory:
 def __new__(cls) -> Product:
     return Product()

reveal_type(Factory())   type is Product, not Factory


Note that mypy still gives an error at the definition site if the explicit annotation is not a
subtype of the current class, since this is technically not type-safe.

For backwards compatibility, there are two exceptions:
- If the return type is `Any`, mypy will still use the current class as the return type.
- If the explicit return type comes from a superclass and is a supertype of the implicit return type,
mypy will use the implicit (more specific) type:

python
class A:
 def __new__(cls) -> A: ...

reveal_type(A())   type is A

class B:
 def __new__(cls) -> B:
     return cls()

class C(B): ...
reveal_type(C())   type is C


This fixes several long-standing issues where explicit `__new__()` return types were ignored.

Contributed by Ivan Levkivskyi (PR [21441](https://github.com/python/mypy/pull/21441)).

TypeForm Support No Longer Experimental

Support for `TypeForm` is no longer experimental. `TypeForm` (introduced in Python 3.14) allows you
to annotate parameters that accept type expressions, providing better type checking for functions
that work with types as values.

python
from typing import TypeForm

def make_list(tp: TypeForm[T]) -> list[T]:
 ...

Correctly typed as list[int]
int_list = make_list(int)


`TypeForm` support was previously reverted from mypy 2.1 due to a performance regression, but this
has now been mitigated.

Contributed by Ivan Levkivskyi and Jelle Zijlstra (PRs [21262](https://github.com/python/mypy/pull/21262), [21591](https://github.com/python/mypy/pull/21591),
[21459](https://github.com/python/mypy/pull/21459)).

Experimental WASM Wheel for Python 3.14

Mypy now ships an experimental WebAssembly (WASM) wheel for Python 3.14. This allows mypy to run
in WASM environments such as Pyodide and browser-based Python implementations.

The WASM wheel is considered experimental and may have limitations compared to native builds. Please
report any issues you encounter when using mypy in WASM environments.

Contributed by Ivan Levkivskyi (PR [21671](https://github.com/python/mypy/pull/21671)).

Mypyc Free-threading Improvements

- Make function wrappers thread-safe on free-threaded builds (Jukka Lehtosalo, PR [21620](https://github.com/python/mypy/pull/21620))
- Make list remove and index thread-safe on free-threaded builds (Jukka Lehtosalo, PR [21614](https://github.com/python/mypy/pull/21614))
- Fix dict iteration memory safety on free-threaded builds (Jukka Lehtosalo, PR [21617](https://github.com/python/mypy/pull/21617))
- Make some dict primitives thread-safe on free-threading builds (Jukka Lehtosalo, PR [21616](https://github.com/python/mypy/pull/21616))
- Fix free-threading race condition in argument parsing (Jukka Lehtosalo, PR [21613](https://github.com/python/mypy/pull/21613))
- Document free threading and other doc updates (Jukka Lehtosalo, PR [21494](https://github.com/python/mypy/pull/21494))

`librt.strings` Updates

- Add `librt.strings.toupper` and `librt.strings.tolower` codepoint primitives (Vaggelis Danias, PR [21553](https://github.com/python/mypy/pull/21553))
- Add `librt.strings.isidentifier` codepoint primitive (Vaggelis Danias, PR [21522](https://github.com/python/mypy/pull/21522))
- Add `librt.strings.isalpha` codepoint primitive (Vaggelis Danias, PR [21521](https://github.com/python/mypy/pull/21521))
- Add `librt.strings.isalnum` codepoint primitive (Vaggelis Danias, PR [21509](https://github.com/python/mypy/pull/21509))
- Add `librt.strings.isdigit` codepoint primitive (Vaggelis Danias, PR [21504](https://github.com/python/mypy/pull/21504))
- Add `librt.strings.isspace` char primitive (Vaggelis Danias, PR [21462](https://github.com/python/mypy/pull/21462))

Mypyc Improvements

- Fix name lookup when class var and module var have the same name (Jukka Lehtosalo, PR [21594](https://github.com/python/mypy/pull/21594))
- Report file and line number on uncaught exceptions (Jukka Lehtosalo, PR [21584](https://github.com/python/mypy/pull/21584))
- Use `other` arg instead of `self` for RHS type (Ryan Heard, PR [21569](https://github.com/python/mypy/pull/21569))
- Use `method_sig` to get the method signature (Ryan Heard, PR [21567](https://github.com/python/mypy/pull/21567))
- Preserve inherited attribute defaults under `separate=True` (Jo, PR [21547](https://github.com/python/mypy/pull/21547))
- Fix missing cross-group header deps in incremental builds (Jo, PR [21490](https://github.com/python/mypy/pull/21490))
- Fix cross-group call to inherited `__mypyc_defaults_setup` (Jo, PR [21481](https://github.com/python/mypy/pull/21481))
- Fix non-deterministic class struct layout under `separate=True` (Vaggelis Danias, PR [21530](https://github.com/python/mypy/pull/21530))
- Specialize `s[i] == 'x'` to a codepoint int compare (Vaggelis Danias, PR [21579](https://github.com/python/mypy/pull/21579))
- Fix reference leak in mypyc bytes concatenation (Colinxu2020, PR [21469](https://github.com/python/mypy/pull/21469))

Fixes to Crashes

- Fix crash on invalid recursive variadic alias (Ivan Levkivskyi, PR [21572](https://github.com/python/mypy/pull/21572))
- Fix crashes on variadic unpacking in synthetic types (Ivan Levkivskyi, PR [21555](https://github.com/python/mypy/pull/21555))
- Fix crash on unhandled meet variadic tuple vs instance (Ivan Levkivskyi, PR [21558](https://github.com/python/mypy/pull/21558))
- Fix crash on deferred generic class nested in function (Ivan Levkivskyi, PR [21557](https://github.com/python/mypy/pull/21557))
- Fix crash in new-style type alias with variadic unpack (Ivan Levkivskyi, PR [21551](https://github.com/python/mypy/pull/21551))
- Fix various crashes on recursive type variable defaults (Ivan Levkivskyi, PR [21491](https://github.com/python/mypy/pull/21491))
- Fix crash for empty `Annotated` type application (Rayan Salhab, PR [21503](https://github.com/python/mypy/pull/21503))
- Fix crash on `Unpack` used without arguments in class bases (Sai Asish Y, PR [21470](https://github.com/python/mypy/pull/21470))

Performance Improvements

- Memoize the options snapshot (Kevin Kannammalil, PR [21354](https://github.com/python/mypy/pull/21354))
- Don't include `not_ready_deps` tracking as relating to mypy internals (Kevin Kannammalil, PR [21389](https://github.com/python/mypy/pull/21389))
- Speed up transitive dependency hash for singleton SCCs (Kevin Kannammalil, PR [21390](https://github.com/python/mypy/pull/21390))
- Optimize typeform checks (Jelle Zijlstra, PR [21459](https://github.com/python/mypy/pull/21459))

Improvements to the Native Parser

- Support `--shadow-file` with `--native-parser` (Jukka Lehtosalo, PR [21623](https://github.com/python/mypy/pull/21623))
- Add Python version checks to native parser (Kevin Kannammalil, PR [21539](https://github.com/python/mypy/pull/21539))
- Allow nativeparse to parse source code directly (bzoracler, PR [21260](https://github.com/python/mypy/pull/21260))

Other Notable Fixes and Improvements

- Add function definition notes for `too many positional arguments` errors (Kevin Kannammalil, PR [21410](https://github.com/python/mypy/pull/21410))
- Fix the exportjson tool (.ff cache to .json conversion) (Jukka Lehtosalo, PR [21628](https://github.com/python/mypy/pull/21628))
- Support floats in JSON in fixed-format cache (Ivan Levkivskyi, PR [21603](https://github.com/python/mypy/pull/21603))
- Update `TypedDictType.__init__` signature to preserve backward compat (Jukka Lehtosalo, PR [21590](https://github.com/python/mypy/pull/21590))
- Fix constructor calls for union-bounded `TypeVar`s (Jingchen Ye, PR [21571](https://github.com/python/mypy/pull/21571))
- Fix `TypedDict` indexing with literal keys in comprehensions (Jingchen Ye, PR [21556](https://github.com/python/mypy/pull/21556))
- Correctly handle empty tuple index when unpacked (Ivan Levkivskyi, PR [21545](https://github.com/python/mypy/pull/21545))
- Support protocol checks for self-types in tuple types (Ivan Levkivskyi, PR [21535](https://github.com/python/mypy/pull/21535))
- Fix edge cases in variadic tuple subclasses (Ivan Levkivskyi, PR [21518](https://github.com/python/mypy/pull/21518))
- Special-case constructor for tuple types (Ivan Levkivskyi, PR [21502](https://github.com/python/mypy/pull/21502))
- Fix false positive "Expected TypedDict key to be string literal" for `Union[TypedDict, dict[K, V]]` (Zakir Jiwani, PR [21511](https://github.com/python/mypy/pull/21511))
- Use explicit `Never` for type inference (Ivan Levkivskyi, PR [21497](https://github.com/python/mypy/pull/21497))
- Narrow membership in statically known containers (Shantanu, PR [21461](https://github.com/python/mypy/pull/21461))
- Improve negative narrowing for membership checks on tuples (Shantanu, PR [21456](https://github.com/python/mypy/pull/21456))
- Analyze `TypedDict` decorators (Pranav Manglik, PR [21267](https://github.com/python/mypy/pull/21267))
- Start testing Python 3.15 (Marc Mueller, PR [21439](https://github.com/python/mypy/pull/21439))
- Improved handling of `NamedTuple`, `TypedDict`, `Enum`, and regular classes nested in functions (Ivan Levkivskyi, PR [21478](https://github.com/python/mypy/pull/21478))

Typeshed Updates

Please see [git log](https://github.com/python/typeshed/commits/main?after=616424285beccaa76f90e87e1e922b1dc68710ca+0&branch=main&path=stdlib) for full list of standard library typeshed stub changes.

Acknowledgements

Thanks to all mypy contributors who contributed to this release:

- Adam Turner
- alicederyn
- bzoracler
- Colinxu2020
- georgesittas
- Ivan Levkivskyi
- Jelle Zijlstra
- Jingchen Ye
- Jukka Lehtosalo
- Kevin Kannammalil
- lphuc2250gma
- Marc Mueller
- Pranav Manglik
- Rayan Salhab
- Ryan Heard
- Sai Asish Y
- Shantanu
- sobolevn
- Vaggelis Danias
- Victor Letichevsky
- Zakir Jiwani

I'd also like to thank my employer, Dropbox, for supporting mypy development.

2.1

We’ve just uploaded mypy 2.1.0 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).
Mypy is a static type checker for Python. This release includes new features, performance
improvements and bug fixes. 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](http://mypy.readthedocs.io).

librt.vecs: Fast Growable Array Type for Mypyc

The new `librt.vecs` module provides an efficient growable array type `vec` that is
optimized for mypyc use. It provides fast, packed arrays with integer and floating point
value types, which can be **several times faster** than `list`, and tens of times faster
than `array.array` in code compiled using mypyc. It also supports nested `vec` objects and
non-value-type items, such as ``vec[vec[str]]``.

Refer to the [documentation](https://mypyc.readthedocs.io/en/latest/librt_vecs.html) for
the details.

Contributed by Jukka Lehtosalo.

librt.random: Fast Pseudo-Random Number Generation

The new `librt.random` module provides fast pseudo-random number generation that is
optimized for code compiled using mypyc. It can be 3x to 10x faster than the stdlib
`random` module in compiled code.

Refer to the [documentation](https://mypyc.readthedocs.io/en/latest/librt_random.html) for
the details.

Contributed by Jukka Lehtosalo (PR [21433](https://github.com/python/mypy/pull/21433)).

Mypyc Improvements

- Enable incremental self-compilation (Vaggelis Danias, PR [21369](https://github.com/python/mypy/pull/21369))
- Make compilation order with multiple files consistent (Piotr Sawicki, PR [21419](https://github.com/python/mypy/pull/21419))
- Fix crash on accessing `StopAsyncIteration` (Piotr Sawicki, PR [21406](https://github.com/python/mypy/pull/21406))
- Fix incremental compilation with `separate` flag (Vaggelis Danias, PR [21299](https://github.com/python/mypy/pull/21299))

Fixes to Crashes

- Fix crash on partial type with `--allow-redefinition` and `global` declaration (Jukka Lehtosalo, PR [21428](https://github.com/python/mypy/pull/21428))
- Fix broken awaitable generator patching (Ivan Levkivskyi, PR [21435](https://github.com/python/mypy/pull/21435))

Changes to Messages

- Fix function call error message for small number of arguments (sobolevn, PR [21432](https://github.com/python/mypy/pull/21432))

Other Notable Fixes and Improvements

- Rely on typeshed stubs for `slice` typing (Ivan Levkivskyi, PR [21401](https://github.com/python/mypy/pull/21401))
- Narrow match captures based on previous cases (Shantanu, PR [21405](https://github.com/python/mypy/pull/21405))
- Fix nondeterminism in overload resolution (Shantanu, PR [21455](https://github.com/python/mypy/pull/21455))
- Respect file config comments for stale modules (Adam Turner, PR [21444](https://github.com/python/mypy/pull/21444))
- Fix JSON output mode for syntax errors in parallel mode (Adam Turner, PR [21434](https://github.com/python/mypy/pull/21434))
- Fix type variable with values as a supertype (Ivan Levkivskyi, PR [21431](https://github.com/python/mypy/pull/21431))
- Add support for configuring `--num-workers` with an environment variable (Kevin Kannammalil, PR [21407](https://github.com/python/mypy/pull/21407))
- Respect JSON output mode for syntax errors (Adam Turner, PR [21386](https://github.com/python/mypy/pull/21386))

Typeshed Updates

Please see [git log](https://github.com/python/typeshed/commits/main?after=e4d32e01bee44241a5e7c33298c261175b9f1bdb+0&branch=main&path=stdlib) for full list of standard library typeshed stub changes.

Acknowledgements

Thanks to all mypy contributors who contributed to this release:

- Adam Turner
- Ivan Levkivskyi
- Jukka Lehtosalo
- Kevin Kannammalil
- Piotr Sawicki
- Shantanu
- sobolevn
- Vaggelis Danias

I’d also like to thank my employer, Dropbox, for supporting mypy development.

2.0

We’ve just uploaded mypy 2.0.0 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).
Mypy is a static type checker for Python. This release includes new features, performance
improvements and bug fixes. There are also changes to options and defaults.
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](http://mypy.readthedocs.io).

Enable `--local-partial-types` by Default

This flag affects the inference of types based on assignments in other scopes.
For now, explicitly disabling this continues to be supported, but this support will be removed
in the future as the legacy behaviour is hard to support with other current and future features
in mypy, like the daemon or the new implementation of flexible redefinitions.

Contributed by Ivan Levkivskyi, Jukka Lehtosalo, Shantanu in [PR 21163](https://github.com/python/mypy/pull/21163).

Enable `--strict-bytes` by Default

Per [PEP 688](https://peps.python.org/pep-0688), mypy no longer treats `bytearray` and `memoryview`
values as assignable to the `bytes` type.

Contributed by Shantanu in [PR 18371](https://github.com/python/mypy/pull/18371).

New Behavior for `--allow-redefinition`

The `--allow-redefinition` flag now behaves like `--allow-redefinition-new` in mypy 1.20
and earlier. The new behavior is generally more flexible. For example, you can have different
types for a variable in different blocks:

python
mypy: allow-redefinition

def foo(cond: bool) -> None:
 if cond:
     for x in ["a", "b"]:
          Type of "x" is "str" here
         ...
 else:
     for x in [1, 2]:
          Type of "x" is "int" here
         ...


The new behavior requires `--local-partial-types`, which is now enabled by default.

However, `--allow-redefinition` doesn't allow giving two type annotations for the same
variable. The old behavior (sometimes) allows this. Code like this now generates an error
when using `--allow-redefinition`:

python
def foo() -> None:
 x: list[int] = []
 ...
 x: list[str] = []   Error: "x" redefined
 ...


You can still use `--allow-redefinition-old` to fall back to the old behavior. We have no
plans to remove the legacy behavior, but the old functionality is maintained on a best effort
basis.

Contributed by Jukka Lehtosalo in [PR 21276](https://github.com/python/mypy/pull/21276).

Parallel Type Checking

Mypy now supports experimental parallel and incremental type checking. Use `--num-workers N`
or `-nN` to use `N` worker processes to type check in parallel. The speedup depends on the
import structure of your codebase and your environment, but for large projects we've seen
performance gains of **up to 5x** when using 8 worker processes.

Parallel type checking implicitly enables the new native parser. There are still some
minor semantic differences between parallel and non-parallel modes, which we will be fixing
in future mypy releases.

Contributed by Ivan Levkivskyi, with additional contributions from Emma Smith and Jukka
Lehtosalo.

Recent related changes since the last release:

- Freeze garbage collection in parallel workers for 4-5% speedup (Ivan Levkivskyi, PR [21302](https://github.com/python/mypy/pull/21302))
- Expose `--num-workers` and `--native-parser` (Ivan Levkivskyi, PR [21387](https://github.com/python/mypy/pull/21387))
- Split type checking into interface and implementation in parallel workers (Ivan Levkivskyi, PR [21119](https://github.com/python/mypy/pull/21119))
- Batch module groups for parallel processing (Ivan Levkivskyi, PR [21287](https://github.com/python/mypy/pull/21287))
- Optimize parallel worker startup (Ivan Levkivskyi, PR [21203](https://github.com/python/mypy/pull/21203))
- Parse files in parallel when possible (Ivan Levkivskyi, PR [21175](https://github.com/python/mypy/pull/21175))
- Use parallel parsing at all stages (Ivan Levkivskyi, PR [21266](https://github.com/python/mypy/pull/21266))
- Fix sequential bottleneck in parallel parsing (Jukka Lehtosalo, PR [21291](https://github.com/python/mypy/pull/21291))
- Fail fast when a user tries to generate reports with parallel workers (Ivan Levkivskyi, PR [21341](https://github.com/python/mypy/pull/21341))
- Partially support old NumPy plugin in parallel type checking (Ivan Levkivskyi, PR [21324](https://github.com/python/mypy/pull/21324))
- Handle reachability consistently in parallel type checking (Ivan Levkivskyi, PR [21322](https://github.com/python/mypy/pull/21322))
- Always respect `no_type_check` in parallel type checking (Ivan Levkivskyi, PR [21320](https://github.com/python/mypy/pull/21320))
- Minor fixes in parallel checking (Ivan Levkivskyi, PR [21319](https://github.com/python/mypy/pull/21319))
- Fix plugin logic in parallel type checking (Ivan Levkivskyi, PR [21252](https://github.com/python/mypy/pull/21252))
- Fix Windows IPC race condition when using parallel checking (Jukka Lehtosalo, PR [21228](https://github.com/python/mypy/pull/21228))
- Report parallel worker exit status on receive failure (Jukka Lehtosalo, PR [21224](https://github.com/python/mypy/pull/21224))

Drop Support for Targeting Python 3.9

Mypy no longer supports type checking code with `--python-version 3.9`.
Use `--python-version 3.10` or newer.

Contributed by Shantanu, Marc Mueller in [PR 21243](https://github.com/python/mypy/pull/21243).

Remove Special Casing of Legacy Bundled Stubs

Mypy used to bundle stubs for a few packages in versions 0.812 and earlier. To navigate the
transition, mypy used to report missing types for these packages even if `--ignore-missing-imports`
was set. Mypy now consistently respects `--ignore-missing-imports` for all packages.

Contributed by Shantanu in [PR 18372](https://github.com/python/mypy/pull/18372).

Prevent Assignment to None for Non-Optional Class Variables with Type Comments

Mypy used to allow assignment to None for class variables when using type comments. This was a
common idiom in Python 3.5 and earlier, prior to the introduction of variable annotations.
However, this was a soundness hole and has now been removed.

Contributed by Shantanu in [PR 20054](https://github.com/python/mypy/pull/20054).

librt.strings: String and Bytes Primitives for Mypyc

In mypy 1.20, we introduced [librt](https://pypi.org/project/librt/) as a standard library
for mypyc that fills in some gaps in the Python standard library and the C API.
This release adds the new module `librt.strings`, which contains utilities for building
string and bytes objects, and for accessing and generating binary data:

* `StringWriter` and `BytesWriter` classes allow quickly building `str` and `bytes` objects
from parts.
* `read_*` and `write_*` functions provide fast reading and writing of binary-encoded data.

Refer to the [documentation](https://mypyc.readthedocs.io/en/latest/librt_strings.html) for
the details.

Contributed by Jukka Lehtosalo.

Mypyc Improvements

- Document `librt.time` (Jukka Lehtosalo, PR [21372](https://github.com/python/mypy/pull/21372))
- Mark `librt.time.time()` non-experimental (Ivan Levkivskyi, PR [21310](https://github.com/python/mypy/pull/21310))
- Fix `librt.time` primitive now that it is no longer experimental (Ivan Levkivskyi, PR [21318](https://github.com/python/mypy/pull/21318))
- Fix `librt` API/ABI version checks (Jukka Lehtosalo, PR [21311](https://github.com/python/mypy/pull/21311))
- Generate more type methods for classes with attribute dictionaries (Piotr Sawicki, PR [21290](https://github.com/python/mypy/pull/21290))
- Fix reference counting for tuple items during deallocation (Shantanu, PR [21245](https://github.com/python/mypy/pull/21245))
- Release new instances when `__init__` raises (Shantanu, PR [21248](https://github.com/python/mypy/pull/21248))
- Fix `property` getter memory leak (Vaggelis Danias, PR [21230](https://github.com/python/mypy/pull/21230))
- Fix semantics for walrus expression in tuple (Shantanu, PR [21249](https://github.com/python/mypy/pull/21249))
- Fix crash on import errors during cleanup (Shantanu, PR [21247](https://github.com/python/mypy/pull/21247))
- Fix reference leak in str index (Shantanu, PR [21251](https://github.com/python/mypy/pull/21251))
- Fix memory leak in integer true division (Shantanu, PR [21246](https://github.com/python/mypy/pull/21246))
- Fix reference leaks in `list.clear()`/`dict.clear()` (Shantanu, PR [21244](https://github.com/python/mypy/pull/21244))
- Resolve type aliases in function specialization (esarp, PR [21233](https://github.com/python/mypy/pull/21233))
- Report an error if an acyclic class inherits from non-acyclic (Piotr Sawicki, PR [21227](https://github.com/python/mypy/pull/21227))
- Fix `b64decode` to match new CPython behavior (Piotr Sawicki, PR [21200](https://github.com/python/mypy/pull/21200))

Fixes to Crashes

- Fix crash when a file does not exist during semantic analysis (Ivan Levkivskyi, PR [21379](https://github.com/python/mypy/pull/21379))
- Fix parallel worker crash on syntax error (Ivan Levkivskyi, PR [21202](https://github.com/python/mypy/pull/21202))

Changes to Messages

- Improve error messages for unexpected keyword arguments in overloaded functions (Kevin Kannammalil, PR [20592](https://github.com/python/mypy/pull/20592))
- Don't suggest `Foo[...]` when `Foo(arg=...)` is used in annotation (Yosof Badr, PR [21238](https://github.com/python/mypy/pull/21238))
- Mention what codes are actually ignored in "not covered by type: ignore comment" note (wyattscarpenter, PR [19904](https://github.com/python/mypy/pull/19904))
- Improve error messages when positional argument is missing (Kevin Kannammalil, PR [20591](https://github.com/python/mypy/pull/20591))
- Improve "name is not defined" errors with fuzzy matching (Kevin Kannammalil, PR [20693](https://github.com/python/mypy/pull/20693))
- Add suggestions for misspelled module imports (Kevin Kannammalil, PR [20695](https://github.com/python/mypy/pull/20695))

Performance Improvements

- Replace `NamedTuple` with faster regular classes in hot paths (Shantanu, PR [21326](https://github.com/python/mypy/pull/21326))
- Avoid calling best-match suggestions unless the message is shown (Ivan Levkivskyi, PR [21307](https://github.com/python/mypy/pull/21307))
- Order cases in native parser based on AST node frequency (Jukka Lehtosalo, PR [21219](https://github.com/python/mypy/pull/21219))

Stubtest Improvements

- Basic support for unpack kwargs (Shantanu, PR [21024](https://github.com/python/mypy/pull/21024))
- Fix false positive for properties with a deleter (Pranav Manglik, PR [21259](https://github.com/python/mypy/pull/21259))

Documentation Updates

- Rename "value restriction" to "value-constrained type variable" (Leo Ji, PR [21112](https://github.com/python/mypy/pull/21112))
- Clarify that invariant-by-default applies to legacy `TypeVar` syntax (Leo Ji, PR [21108](https://github.com/python/mypy/pull/21108))

Improvements to the Native Parser

The new native parser is still experimental.

- Make new parser consistent with the old one (Ivan Levkivskyi, PR [21377](https://github.com/python/mypy/pull/21377))
- Support `--package-root` with the native parser (Ivan Levkivskyi, PR [21321](https://github.com/python/mypy/pull/21321))
- Improve call expressions in type annotations with the native parser (Jukka Lehtosalo, PR [21300](https://github.com/python/mypy/pull/21300))
- Depend on `ast-serialize` by default (Jukka Lehtosalo, PR [21297](https://github.com/python/mypy/pull/21297))

Other Notable Fixes and Improvements

- Fix narrowing for `AbstractSet` and `Mapping` (Shantanu, PR [21352](https://github.com/python/mypy/pull/21352))
- Preserve gradual guarantee when narrowing `Any` union via equality (Shantanu, PR [21368](https://github.com/python/mypy/pull/21368))
- Make type variable upper bound narrowing symmetric (Ivan Levkivskyi, PR [21350](https://github.com/python/mypy/pull/21350))
- Behave consistently when type-checking a stub package directly (Ivan Levkivskyi, PR [21330](https://github.com/python/mypy/pull/21330))
- Add support for `Final[...]` in dataclasses (Ivan Levkivskyi, PR [21334](https://github.com/python/mypy/pull/21334))
- Narrow more sequence parents (Shantanu, PR [21327](https://github.com/python/mypy/pull/21327))
- Better narrowing for enums and other types with known equality (Shantanu, PR [21281](https://github.com/python/mypy/pull/21281))
- Fix pathspec error (Ivan Levkivskyi, PR [21296](https://github.com/python/mypy/pull/21296))
- Use sharding for the SQLite cache (Jukka Lehtosalo, PR [21292](https://github.com/python/mypy/pull/21292))
- Limit type inference context fallback to the walrus operator only (Ivan Levkivskyi, PR [21294](https://github.com/python/mypy/pull/21294))
- Support `.git/info/exclude` for `--exclude-gitignore` (RogerJinIS, PR [21286](https://github.com/python/mypy/pull/21286))
- Let `--allow-redefinition` widen a global in a function with `None` initialization (Jukka Lehtosalo, PR [21285](https://github.com/python/mypy/pull/21285))
- Delete Python 2 extra (Shantanu, PR [18374](https://github.com/python/mypy/pull/18374))
- No longer narrow final globals in functions (Ivan Levkivskyi, PR [21241](https://github.com/python/mypy/pull/21241))
- Narrow unions containing `Any` in conditional branches (Shantanu, PR [21231](https://github.com/python/mypy/pull/21231))
- Propagate narrowing within chained comparisons (Shantanu, PR [21160](https://github.com/python/mypy/pull/21160))
- Add proper lazy deserialization (Ivan Levkivskyi, PR [21198](https://github.com/python/mypy/pull/21198))
- Add `install_types` to options affecting cache (Brian Schubert, PR [21070](https://github.com/python/mypy/pull/21070))
- Narrow `Any` in conditional type checks (Shantanu, PR [21167](https://github.com/python/mypy/pull/21167))
- Fix exception handler target location in new parser (Ivan Levkivskyi, PR [21185](https://github.com/python/mypy/pull/21185))
- Improve traceback display (Shantanu, PR [21155](https://github.com/python/mypy/pull/21155))
- Include two more files in the sdist: `CREDITS` and the typeshed `README` (Michael R. Crusoe, PR [21131](https://github.com/python/mypy/pull/21131))

Typeshed Updates

Please see [git log](https://github.com/python/typeshed/commits/main?after=c5e47faeda2cf9d233f91bc1dc95814b0cc7ccba+0&branch=main&path=stdlib) for full list of standard library typeshed stub changes.

Acknowledgements

Thanks to all mypy contributors who contributed to this release:
- Brian Schubert
- Ethan Sarp
- Ivan Levkivskyi
- Jukka Lehtosalo
- Kevin Kannammalil
- Leo Ji
- Marc Mueller
- Michael R. Crusoe
- Piotr Sawicki
- Pranav Manglik
- RogerJinIS
- Shantanu
- Vaggelis Danias
- wyattscarpenter
- Yosof Badr

I’d also like to thank my employer, Dropbox, for supporting mypy development.

1.20.2

- Use WAL with SQLite cache and fix close (Shantanu, PR [21154](https://github.com/python/mypy/pull/21154))
- Adjust SQLite journal mode (Ivan Levkivskyi, PR [21217](https://github.com/python/mypy/pull/21217))
- Correctly aggregate narrowing information on parent expressions (Shantanu, PR [21206](https://github.com/python/mypy/pull/21206))
- Fix regression related to generic callables (Shantanu, PR [21208](https://github.com/python/mypy/pull/21208))
- Fix regression by avoiding widening types in some contexts (Shantanu, PR [21242](https://github.com/python/mypy/pull/21242))
- Fix slicing in non-strict optional mode (Shantanu, PR [21282](https://github.com/python/mypy/pull/21282))
- mypyc: Fix match statement semantics for "or" pattern (Shantanu, PR [21156](https://github.com/python/mypy/pull/21156))
- mypyc: Fix issue with module dunder attributes (Piotr Sawicki, PR [21275](https://github.com/python/mypy/pull/21275))
- Initial support for Python 3.15.0a8 (Marc Mueller, PR [21255](https://github.com/python/mypy/pull/21255))

Acknowledgements

Thanks to all mypy contributors who contributed to this release:
- A5rocks
- Aaron Wieczorek
- Adam Turner
- Ali Hamdan
- asce
- BobTheBuidler
- Brent Westbrook
- Brian Schubert
- bzoracler
- Chris Burroughs
- Christoph Tyralla
- Colin Watson
- Donghoon Nam
- E. M. Bray
- Emma Smith
- Ethan Sarp
- George Ogden
- getzze
- grayjk
- Gregor Riepl
- Ivan Levkivskyi
- James Hilliard
- James Le Cuirot
- Jeremy Nimmer
- Joren Hammudoglu
- Kai (Kazuya Ito)
- kaushal trivedi
- Kevin Kannammalil
- Lukas Geiger
- Łukasz Langa
- Marc Mueller
- Michael R. Crusoe
- michaelm-openai
- Neil Schemenauer
- Piotr Sawicki
- Randolf Scholz
- Roberto Fernández Iglesias
- Saul Shanabrook
- Shantanu Jain
- Sjoerd Job Postmus
- sobolevn
- Stanislav Terliakov
- Steven Pitman
- Vaggelis Danias
- Vikash Kumar
- wyattscarpenter

I’d also like to thank my employer, Dropbox, for supporting mypy development.

1.20.1

- Always disable sync in SQLite cache (Ivan Levkivskyi, PR [21184](https://github.com/python/mypy/pull/21184))
- Temporarily skip few base64 tests (Ivan Levkivskyi, PR [21193](https://github.com/python/mypy/pull/21193))
- Revert `dict.__or__` typeshed change (Ivan Levkivskyi, PR [21186](https://github.com/python/mypy/pull/21186))
- Fix narrowing for match case with variadic tuples (Shantanu, PR [21192](https://github.com/python/mypy/pull/21192))
- Avoid narrowing `type[T]` in type calls (Shantanu, PR [21174](https://github.com/python/mypy/pull/21174))
- Fix regression for catching empty tuple in except (Shantanu, PR [21153](https://github.com/python/mypy/pull/21153))
- Fix reachability for frozenset and dict view narrowing (Shantanu, PR [21151](https://github.com/python/mypy/pull/21151))
- Fix narrowing with chained comparison (Shantanu, PR [21150](https://github.com/python/mypy/pull/21150))
- Avoid narrowing to unreachable at module level (Shantanu, PR [21144](https://github.com/python/mypy/pull/21144))
- Allow dangerous identity comparisons to `Any` typed variables (Shantanu, PR [21142](https://github.com/python/mypy/pull/21142))
- `--warn-unused-config` should not be a strict flag (Ivan Levkivskyi, PR [21139](https://github.com/python/mypy/pull/21139))

1.20

We’ve just uploaded mypy 1.20.0 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).
Mypy is a static type checker for Python. This release includes new features, performance
improvements and bug fixes. 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](http://mypy.readthedocs.io).

Planned Changes to Defaults and Flags in Mypy 2.0

As a reminder, we are planning to enable `--local-partial-types` by default in mypy 2.0, which
will likely be the next feature release. This will often require at least minor code changes. This
option is implicitly enabled by mypy daemon, so this makes the behavior of daemon and non-daemon
modes consistent.

Note that this release improves the compatibility of `--local-partial-types` significantly to
make the switch easier (see below for more).

This can also be configured in a mypy configuration file (use `False` to disable):


local_partial_types = True


For more information, refer to the
[documentation](https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-local-partial-types).

We will also enable `--strict-bytes` by default in mypy 2.0. This usually requires at most
minor code changes to adopt. For more information, refer to the
[documentation](https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-strict-bytes).

Finally, `--allow-redefinition-new` will be renamed to `--allow-redefinition`. If you want
to continue using the older `--allow-redefinition` semantics which are less flexible (e.g.
limited support for conditional redefinitions), you can switch to `--allow-redefinition-old`,
which is currently supported as an alias to the legacy `--allow-redefinition` behavior.
To use `--allow-redefinition` in the upcoming mypy 2.0, you can't use `--no-local-partial-types`.
For more information, refer to the
[documentation](https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-allow-redefinition-new).

Better Type Narrowing

Mypy's implementation of narrowing has been substantially reworked. Mypy will now narrow more
aggressively, more consistently, and more correctly. In particular, you are likely to notice new
narrowing behavior in equality expressions (`==`), containment expressions (`in`),
match statements, and additional expressions providing type guards.

Note that mypy (and other Python type checkers) do not model the potential for various non-local
operations to invalidate narrowing assumptions. This means mypy may conclude that some of your code
is [unreachable](https://mypy.readthedocs.io/en/stable/common_issues.html#unreachable-code) and
avoid further checking of it. The `--warn-unreachable` flag is useful for highlighting these cases.
To reset narrowing, you can insert dummy reassignments, for instance `var = var` will reset
all narrowing of `var.attr`.

Future work includes better narrowing on initial assignments, more narrowing to `Literal` types,
and better checking of unreachable code.

Contributed by Shantanu Jain.

- Rework narrowing logic for equality and identity (Shantanu, PR [20492](https://github.com/python/mypy/pull/20492))
- Refactor equality and identity narrowing for clarity (Shantanu, PR [20595](https://github.com/python/mypy/pull/20595))
- Treat NotImplemented as a singleton type (Shantanu, PR [20601](https://github.com/python/mypy/pull/20601))
- Improve narrowing logic for Enum int and str subclasses (Shantanu, PR [20609](https://github.com/python/mypy/pull/20609))
- Narrow types based on collection containment (Shantanu, PR [20602](https://github.com/python/mypy/pull/20602))
- Refactor and improve narrowing for type(x) == t checks (Shantanu, PR [20634](https://github.com/python/mypy/pull/20634))
- Narrow for type expr comparisons to type exprs (Shantanu, PR [20639](https://github.com/python/mypy/pull/20639))
- Narrowing for comparisons against `x.__class__` (Shantanu, PR [20642](https://github.com/python/mypy/pull/20642))
- Better narrowing with custom equality (Shantanu, PR [20643](https://github.com/python/mypy/pull/20643))
- Use a single pass for core narrowing logic, add comments (Shantanu, PR [20659](https://github.com/python/mypy/pull/20659))
- Narrowing for final type objects (Shantanu, PR [20661](https://github.com/python/mypy/pull/20661))
- Avoid narrowing type[T] (Shantanu, PR [20662](https://github.com/python/mypy/pull/20662))
- Avoid widening to Any for checks like `type(x) is type(y: Any)` (Shantanu, PR [20663](https://github.com/python/mypy/pull/20663))
- Preserve some lost narrowing, cleanup (Shantanu, PR [20674](https://github.com/python/mypy/pull/20674))
- Fix narrowing related code for types with overloaded `__new__` (Shantanu, PR [20676](https://github.com/python/mypy/pull/20676))
- Fix isinstance with unions of tuples (Shantanu, PR [20677](https://github.com/python/mypy/pull/20677))
- Fix regression to chained containment (Shantanu, PR [20688](https://github.com/python/mypy/pull/20688))
- Improve else handling with custom equality (Shantanu, PR [20692](https://github.com/python/mypy/pull/20692))
- Better model runtime in isinstance and type checks (Shantanu, PR [20675](https://github.com/python/mypy/pull/20675))
- Use --warn-unreachable and --strict-equality in more tests (Shantanu, PR [20707](https://github.com/python/mypy/pull/20707))
- Model exact narrowing with type(x) checks (Shantanu, PR [20703](https://github.com/python/mypy/pull/20703))
- Short term fix for bytes narrowing (Shantanu, PR [20704](https://github.com/python/mypy/pull/20704))
- Preserve narrowing in unreachable code (Shantanu, PR [20710](https://github.com/python/mypy/pull/20710))
- Fix bug when narrowing union containing custom eq against custom eq (Shantanu, PR [20754](https://github.com/python/mypy/pull/20754))
- Fix narrowing for unions (Shantanu, PR [20728](https://github.com/python/mypy/pull/20728))
- Unsoundly narrow away from None with custom eq (Shantanu, PR [20756](https://github.com/python/mypy/pull/20756))
- Improve narrowing with numeric types (Shantanu, PR [20727](https://github.com/python/mypy/pull/20727))
- Fix narrowing with final type objects (Shantanu, PR [20743](https://github.com/python/mypy/pull/20743))
- Further improve match statement narrowing against unions (Shantanu, PR [20744](https://github.com/python/mypy/pull/20744))
- Avoid narrowing to NewType (Shantanu, PR [20766](https://github.com/python/mypy/pull/20766))
- Better match narrowing for irrefutable sequence patterns (Shantanu, PR [20782](https://github.com/python/mypy/pull/20782))
- Remove prohibit_none_typevar_overlap (Shantanu, PR [20864](https://github.com/python/mypy/pull/20864))
- Fix match statement narrowing reachability for tuples (Shantanu, PR [20896](https://github.com/python/mypy/pull/20896))
- Better handling of generics when narrowing (Shantanu, PR [20863](https://github.com/python/mypy/pull/20863))
- Better match narrowing for type objects (Shantanu, PR [20872](https://github.com/python/mypy/pull/20872))
- Narrow Callable generic return types (Shantanu, PR [20868](https://github.com/python/mypy/pull/20868))
- Better match narrowing for unions of type objects (Shantanu, PR [20905](https://github.com/python/mypy/pull/20905))
- Improve reachability in narrowing logic (Shantanu, PR [20660](https://github.com/python/mypy/pull/20660))
- Better match narrowing for irrefutable mapping patterns (Shantanu, PR [20906](https://github.com/python/mypy/pull/20906))
- Fix match statement semantic reachability (Shantanu, PR [20968](https://github.com/python/mypy/pull/20968))
- Add some additional narrowing test cases (Shantanu, PR [20598](https://github.com/python/mypy/pull/20598))
- Move tests to check-narrowing , improve them slightly (Shantanu, PR [20637](https://github.com/python/mypy/pull/20637))
- Add more tests for narrowing logic (Shantanu, PR [20672](https://github.com/python/mypy/pull/20672))
- More testing related improvements and updates (Shantanu, PR [20709](https://github.com/python/mypy/pull/20709))
- Add --warn-unreachable to more tests (Shantanu, PR [20977](https://github.com/python/mypy/pull/20977))

Drop Support for Python 3.9

Mypy no longer supports running with Python 3.9, which has reached end of life.
When running mypy with Python 3.10+, it is still possible to type check code
that needs to support Python 3.9 with the `--python-version 3.9` argument.
Support for this will be dropped in the first half of 2026!

Contributed by Marc Mueller (PR [20156](https://github.com/python/mypy/pull/20156)).

Mypyc Accelerated Mypy Wheels for ARM Windows and Free Threading

For best performance, mypy can be compiled to C extension modules using mypyc. This makes
mypy 3-5x faster than when interpreted with pure Python. We now build and upload mypyc
accelerated mypy wheels for `win_arm64` and `cp314t-...` to PyPI, making it easy for Windows
users on ARM and those using the free threading builds for Python 3.14 to realise this speedup
-- just `pip install` the latest mypy.

Contributed by Marc Mueller
(PR [mypy_mypyc-wheels106](https://github.com/mypyc/mypy_mypyc-wheels/pull/106),
PR [mypy_mypyc-wheels110](https://github.com/mypyc/mypy_mypyc-wheels/pull/110)).

Improved Compatibility for Local Partial Types

Compatibility between mypy's default behavior and the `--local-partial-types` flag
is now improved. This improves compatibility between mypy daemon and non-daemon modes,
since the mypy daemon requires local partial types to be enabled.

In particular, code like this now behaves consistently independent of
whether local partial types are enabled or not:

python
x = None

def foo() -> None:
 global x
 x = 1

The inferred type of 'x' is always 'int | None'.


Also, we are planning to turn local partial types on by default in mypy 2.0 (to be
released soon), and this makes the change much less disruptive. Explicitly disabling local
partial types will continue to be supported, but the support will likely be
deprecated and removed eventually, as the legacy behavior is hard to support together with
some important changes we are working on, in addition to being incompatible with the mypy
daemon.

This feature was contributed by Ivan Levkivskyi (PR [20938](https://github.com/python/mypy/pull/20938)).

Python 3.14 T-String Support (PEP 750)

Mypy now supports t-strings that were introduced in Python 3.14.

- Add support for Python 3.14 t-strings (PEP 750) (Neil Schemenauer and Brian Schubert, PR [20850](https://github.com/python/mypy/pull/20850))
- Add implicit module dependency if using t-string (Jukka Lehtosalo, PR [20900](https://github.com/python/mypy/pull/20900))

Experimental New Parser

If you install mypy using `pip install mypy[native-parser]` and run mypy with
`--native-parser`, you can experiment with a new Python parser. It is based on
the Ruff parser, and it's more efficient than the default parser. It will also enable
access to all Python syntax independent of which Python version you use to run mypy.
The new parser is still not feature-complete and has known issues.

Related changes:

- Add work-in-progress implementation of a new Python parser (Jukka Lehtosalo, PR [20856](https://github.com/python/mypy/pull/20856))
- Skip redundant analysis pass when using the native parser (Ivan Levkivskyi, PR [21015](https://github.com/python/mypy/pull/21015))
- Add t-string support to native parser (Ivan Levkivskyi, PR [21007](https://github.com/python/mypy/pull/21007))
- Handle hex bigint literals in native parser (Ivan Levkivskyi, PR [20988](https://github.com/python/mypy/pull/20988))
- Pass all relevant options to native parser (Ivan Levkivskyi, PR [20984](https://github.com/python/mypy/pull/20984))
- Support `no_type_check` with native parser (Ivan Levkivskyi, PR [20959](https://github.com/python/mypy/pull/20959))
- Fix error code handling in native parser (Ivan Levkivskyi, PR [20952](https://github.com/python/mypy/pull/20952))
- Add `ast-serialize` as an optional dependency (Ivan Levkivskyi, PR [21028](https://github.com/python/mypy/pull/21028))
- Use `native-parser` instead of `native-parse` for optional dependency (Jukka Lehtosalo, PR [21115](https://github.com/python/mypy/pull/21115))

Performance Improvements

Mypy now uses a binary cache format (fixed-format cache) by default to speed up incremental
checking. You can still use `--no-fixed-format-cache` to use the legacy JSON cache format,
but we will remove the JSON cache format in a future release. Mypy includes a tool to convert
individual fixed-format cache files (.ff) to the JSON format to make it possible to inspect
cache contents:

python
python -m mypy.exportjson <path> ...


If the SQLite cache is enabled, you will first need to convert the SQLite cache into
individual files using the [`misc/convert-cache.py`](https://github.com/python/mypy/blob/master/misc/convert-cache.py)
tool available in the mypy GitHub repository. You can also disable the SQLite
cache using `--no-sqlite-cache`.

The SQLite cache (`--sqlite-cache`) is now enabled by default. It improves mypy
performance significantly in certain environments where slow file system operations
used to be a bottleneck.

List of all performance improvements (for mypyc improvements there is a separate section below):

- Flip fixed-format cache to on by default (Ivan Levkivskyi, PR [20758](https://github.com/python/mypy/pull/20758))
- Enable `--sqlite-cache` by default (Shantanu, PR [21041](https://github.com/python/mypy/pull/21041))
- Save work on emitting ignored diagnostics (Shantanu, PR [20621](https://github.com/python/mypy/pull/20621))
- Skip logging and stats collection calls if they are no-ops (Jukka Lehtosalo, PR [20839](https://github.com/python/mypy/pull/20839))
- Speed up large incremental builds by optimizing internal state construction (Jukka Lehtosalo, PR [20838](https://github.com/python/mypy/pull/20838))
- Speed up suppressed dependencies options processing (Jukka Lehtosalo, PR [20806](https://github.com/python/mypy/pull/20806))
- Avoid path operations that need syscalls (Jukka Lehtosalo, PR [20802](https://github.com/python/mypy/pull/20802))
- Use faster algorithm for topological sort (Jukka Lehtosalo, PR [20790](https://github.com/python/mypy/pull/20790))
- Replace old topological sort (Jukka Lehtosalo, PR [20805](https://github.com/python/mypy/pull/20805))
- Fix quadratic performance in dependency graph loading for incremental builds (Jukka Lehtosalo, PR [20786](https://github.com/python/mypy/pull/20786))
- Micro-optimize transitive dependency hash calculation (Jukka Lehtosalo, PR [20798](https://github.com/python/mypy/pull/20798))
- Speed up options snapshot calculation (Jukka Lehtosalo, PR [20797](https://github.com/python/mypy/pull/20797))
- Micro-optimize read buffering, metastore `abspath`, path joining (Shantanu, PR [20810](https://github.com/python/mypy/pull/20810))
- Speed up type comparisons and hashing for literal types (Shantanu, PR [20423](https://github.com/python/mypy/pull/20423))
- Optimize overloaded signatures check (asce, PR [20378](https://github.com/python/mypy/pull/20378))
- Avoid unnecessary work when checking deferred functions (Ivan Levkivskyi, PR [20860](https://github.com/python/mypy/pull/20860))
- Improve `--allow-redefinition-new` performance for code with loops (Ivan Levkivskyi, PR [20862](https://github.com/python/mypy/pull/20862))
- Avoid `setattr`/`getattr` with fixed format cache (Ivan Levkivskyi, PR [20826](https://github.com/python/mypy/pull/20826))

Improvements to Allowing Redefinitions

Mypy now allows significantly more flexible variable redefinitions when using `--allow-redefinition-new`.
In particular, function parameters can now be redefined with a different type:

python
mypy: allow-redefinition-new, local-partial-types

def process(items: list[str]) -> None:
  Reassign parameter to a completely different type.
  Without --allow-redefinition-new, this is a type error because
  list[list[str]] is not compatible with list[str].
 items = [item.split() for item in items]
 ...


In mypy 2.0, we will update `--allow-redefinition` to mean `--allow-redefinition-new`.
This release adds `--allow-redefinition-old` as an alias of `--allow-redefinition`, which
can be used to continue using the old redefinition behavior in mypy 2.0 and later.

List of changes:

- Add `--allow-redefinition-old` as an alias of `--allow-redefinition` (Ivan Levkivskyi, PR [20764](https://github.com/python/mypy/pull/20764))
- Allow redefinitions for function arguments (Ivan Levkivskyi, PR [20853](https://github.com/python/mypy/pull/20853))
- Fix regression on redefinition in deferred loop (Ivan Levkivskyi, PR [20879](https://github.com/python/mypy/pull/20879))
- Fix loop convergence with redefinitions (Ivan Levkivskyi, PR [20865](https://github.com/python/mypy/pull/20865))
- Make sure new redefinition semantics only apply to inferred variables (Ivan Levkivskyi, PR [20909](https://github.com/python/mypy/pull/20909))
- Fix union edge case in function argument redefinition (Ivan Levkivskyi, PR [20908](https://github.com/python/mypy/pull/20908))
- Show an error when old and new redefinition are enabled in a file (Ivan Levkivskyi, PR [20920](https://github.com/python/mypy/pull/20920))
- `--allow-redefinition-new` is no longer experimental (Jukka Lehtosalo, PR [21110](https://github.com/python/mypy/pull/21110))
- Fix type inference for nested union types (Ivan Levkivskyi, PR [20912](https://github.com/python/mypy/pull/20912))
- Fix type inference regression for multiple variables in loops (Ivan Levkivskyi, PR [20892](https://github.com/python/mypy/pull/20892))
- Improve type inference for empty collections in conditional contexts (Ivan Levkivskyi, PR [20851](https://github.com/python/mypy/pull/20851))

Incremental Checking Improvements

This release includes multiple fixes to incremental type checking:

- Invalidate cache when `--enable-incomplete-feature` changes (kaushal trivedi, PR [20849](https://github.com/python/mypy/pull/20849))
- Add back support for `warn_unused_configs` (Ivan Levkivskyi, PR [20801](https://github.com/python/mypy/pull/20801))
- Recover from corrupted fixed-format cache meta file (Jukka Lehtosalo, PR [20780](https://github.com/python/mypy/pull/20780))
- Distinguish not found versus skipped modules (Ivan Levkivskyi, PR [20812](https://github.com/python/mypy/pull/20812))
- Fix undetected submodule deletion on warm run (Ivan Levkivskyi, PR [20784](https://github.com/python/mypy/pull/20784))
- Fix staleness on changed follow-imports options (Ivan Levkivskyi, PR [20773](https://github.com/python/mypy/pull/20773))
- Verify indirect dependencies reachable on incremental run (Ivan Levkivskyi, PR [20735](https://github.com/python/mypy/pull/20735))
- Fix indirect dependencies for protocols (Ivan Levkivskyi, PR [20752](https://github.com/python/mypy/pull/20752))
- Show error locations in other modules on warm runs (Ivan Levkivskyi, PR [20635](https://github.com/python/mypy/pull/20635))
- Don't read errors from cache on silent import (Sjoerd Job Postmus, PR [20509](https://github.com/python/mypy/pull/20509))
- More robust fix for re-export of `__all__` (Ivan Levkivskyi, PR [20487](https://github.com/python/mypy/pull/20487))

Fixes to Crashes

- Fix crash on partially typed namespace package (Ivan Levkivskyi, PR [20742](https://github.com/python/mypy/pull/20742))
- Fix internal error caused by the generic type alias with an unpacked list (Kai (Kazuya Ito), PR [20689](https://github.com/python/mypy/pull/20689))
- Fix crash when missing format character (Shantanu, PR [20524](https://github.com/python/mypy/pull/20524))
- Fix crash when passing literal values as type arguments to variadic generics (Aaron Wieczorek, PR [20543](https://github.com/python/mypy/pull/20543))
- Fix crash on circular star import in incremental mode (Ivan Levkivskyi, PR [20511](https://github.com/python/mypy/pull/20511))
- Fix crash with tuple unpack inside TypeVar default (Marc Mueller, PR [20456](https://github.com/python/mypy/pull/20456))
- Fix crash on typevar with forward reference used in other module (Ivan Levkivskyi, PR [20334](https://github.com/python/mypy/pull/20334))
- Fix crash on star import of redefinition (Ivan Levkivskyi, PR [20333](https://github.com/python/mypy/pull/20333))
- Fix crash involving Unpack-ed `TypeVarTuple` (Shantanu, PR [20323](https://github.com/python/mypy/pull/20323))
- Fix crashes caused by type variable defaults in-place modifications (Stanislav Terliakov, PR [20139](https://github.com/python/mypy/pull/20139))
- Fix crash when calling `len()` with no arguments (Jukka Lehtosalo, PR [20774](https://github.com/python/mypy/pull/20774))
- Fix crash when checking `async for` inside nested comprehensions (A5rocks, PR [20540](https://github.com/python/mypy/pull/20540))
- Fix `ParamSpec` related crash (Stanislav Terliakov, PR [20119](https://github.com/python/mypy/pull/20119))

Mypyc: Faster Imports on macOS

Imports in native (compiled) modules that target other native modules that are compiled
together are now significantly faster on macOS, especially on the first run after a compiled
package has been installed. This also speeds up the first mypy run after installation/update
on macOS.

This was contributed by Jukka Lehtosalo (PR [21101](https://github.com/python/mypy/pull/21101)).

librt: Mypyc Standard Library

Mypyc now has a dedicated standard library, `librt`, to provide basic features that are optimized
for compiled code. They are faster than corresponding Python stdlib functionality. There is no
plan to replace the Python stdlib, though. We'll only include a carefully selected set of features
that help with common performance bottlenecks in compiled code.

Currently, we provide `librt.base64` that has optimized SIMD (Single Instruction, Multiple
Data) base64 encoding and de

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

* **Chores**
* Updated the development type-checking tool to a newer version.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

@pyup-bot pyup-bot mentioned this pull request Jul 13, 2026
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b1d445d9-5a0e-4679-bbae-647d0e776c7e

📥 Commits

Reviewing files that changed from the base of the PR and between d377ad0 and 8b83fa9.

📒 Files selected for processing (1)
  • src/requirements_dev.txt

📝 Walkthrough

Walkthrough

The development requirements update replaces the pinned mypy version 0.670 with 2.3.0.

Changes

Development Tooling

Layer / File(s) Summary
Update mypy development pin
src/requirements_dev.txt
Changes the pinned mypy version from 0.670 to 2.3.0.

Estimated code review effort: 1 (Trivial) | ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: upgrading mypy to version 2.3.0.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pyup-update-mypy-0.670-to-2.3.0

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant