From 01bc979b639f16e1c3ce5ba957fab158590c9d82 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Tue, 5 May 2026 11:48:51 +0100 Subject: [PATCH 1/5] Mention --allow-redefinition changes in changelog --- CHANGELOG.md | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0700475fa3022..e43f29c99bc12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Next Release -### Enabling `--local-partial-types` by default +### Enabling `--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 @@ -11,13 +11,52 @@ 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) -### Enabling `--strict-bytes` by default +### Enabling `--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. + +Contributed by Jukka Lehtosalo in [PR 21276](https://github.com/python/mypy/pull/21276). + ### Drop Support for Targeting Python 3.9 Mypy no longer supports type checking code with `--python-version 3.9`. @@ -25,7 +64,7 @@ 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 +### 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` @@ -33,7 +72,7 @@ was set. Mypy now consistently respects `--ignore-missing-imports` for all packa 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 +### 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. From 147393901e0198c8b6f21e733b1872dee0adbb0b Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Tue, 5 May 2026 12:00:14 +0100 Subject: [PATCH 2/5] Mention parallel type checking in changelog --- CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e43f29c99bc12..76b9d770611d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,20 @@ plans to remove the legacy behavior. 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. + +This was contributed by Ivan Levkivskyi, with additional contributions from Jukka Lehtosalo +and Emma Smith. + ### Drop Support for Targeting Python 3.9 Mypy no longer supports type checking code with `--python-version 3.9`. From 4b497a436a1228a9da02ee20c080ab7fe0063598 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Tue, 5 May 2026 13:21:41 +0100 Subject: [PATCH 3/5] Document librt.strings --- CHANGELOG.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76b9d770611d6..f2b89d1158622 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -94,6 +94,22 @@ 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 addds 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. + ## Mypy 1.20 We’ve just uploaded mypy 1.20.0 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)). From 15806435e9fee22c8cd235fb3022a5c3693388a4 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Tue, 5 May 2026 13:25:02 +0100 Subject: [PATCH 4/5] Minor updates --- CHANGELOG.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2b89d1158622..a66687edda202 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,14 +9,14 @@ For now, explicitly disabling this continues to be supported, but this support w 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) +Contributed by Ivan Levkivskyi, Jukka Lehtosalo, Shantanu in [PR 21163](https://github.com/python/mypy/pull/21163). ### Enabling `--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) +Contributed by Shantanu in [PR 18371](https://github.com/python/mypy/pull/18371). ### New Behavior for `--allow-redefinition` @@ -68,15 +68,15 @@ Parallel type checking implicitly enables the new native parser. There are still minor semantic differences between parallel and non-parallel modes, which we will be fixing in future mypy releases. -This was contributed by Ivan Levkivskyi, with additional contributions from Jukka Lehtosalo -and Emma Smith. +Contributed by Ivan Levkivskyi, with additional contributions from Emma Smith and Jukka +Lehtosalo. ### 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) +Contributed by Shantanu, Marc Mueller in [PR 21243](https://github.com/python/mypy/pull/21243). ### Remove Special Casing of Legacy Bundled Stubs @@ -84,7 +84,7 @@ Mypy used to bundle stubs for a few packages in versions 0.812 and earlier. To n 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) +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 @@ -92,18 +92,18 @@ Mypy used to allow assignment to None for class variables when using type commen 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) +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 addds the new module `librt.strings`, which contains utilities for building +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 + * `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. + * `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. From 332cc62adb7c1dc1b9c6d7642a8d6009d113bec1 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Tue, 5 May 2026 16:42:02 +0100 Subject: [PATCH 5/5] Address feedback --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a66687edda202..cf5548d0bcaae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,7 +53,8 @@ def foo() -> None: ``` You can still use `--allow-redefinition-old` to fall back to the old behavior. We have no -plans to remove the legacy behavior. +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).