Debian Codegraph @

CHANGELOG.md

raw
1 # Mypy Release Notes
2
3 ## Next Release
4
5 ## Mypy 2.2
6
7 We've just uploaded mypy 2.2.0 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).
8 Mypy is a static type checker for Python. This release includes new features, performance
9 improvements and bug fixes. You can install it as follows:
10
11 python3 -m pip install -U mypy
12
13 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
14
15 ### Support for Closed TypedDicts (PEP 728)
16
17 Mypy now supports closed TypedDicts as specified in PEP 728. A closed TypedDict cannot have extra
18 keys beyond those explicitly defined. This allows the type checker to determine that certain
19 operations are safe when they otherwise wouldn't be due to the potential presence of unknown keys.
20
21 You can use the `closed` keyword argument with `TypedDict`:
22
23 ```python
24 HasName = TypedDict("HasName", {"name": str})
25 HasOnlyName = TypedDict("HasOnlyName", {"name": str}, closed=True)
26 Movie = TypedDict("Movie", {"name": str, "year": int})
27
28 movie: Movie = {"name": "Nimona", "year": 2023}
29 has_name: HasName = movie # OK: HasName is open (default)
30 has_only_name: HasOnlyName = movie # Error: HasOnlyName is closed and Movie has extra "year" key
31 ```
32
33 Closed TypedDicts enable more precise type checking because the type checker knows exactly which
34 keys are present. This is particularly useful when working with TypedDict unions or when you want
35 to ensure that a TypedDict conforms to an exact shape.
36
37 The `closed` keyword also enables safe type narrowing with `in` checks:
38
39 ```python
40 Book = TypedDict('Book', {'book': str}, closed=True)
41 DVD = TypedDict('DVD', {'dvd': str}, closed=True)
42 type Inventory = Book | DVD
43
44 def print_type(inventory: Inventory) -> None:
45 if "book" in inventory:
46 # Type is narrowed to Book here - safe because DVD is closed
47 print(inventory["book"])
48 else:
49 # Type is narrowed to DVD here
50 print(inventory["dvd"])
51 ```
52
53 The `closed` keyword is also supported in class-based syntax:
54
55 ```python
56 class HasOnlyName(TypedDict, closed=True):
57 name: str
58 ```
59
60 Note that closed TypedDicts are structural types, so a closed TypedDict is assignable to an open
61 TypedDict with the same keys, but not vice versa.
62
63 Contributed by Alice (PR [21382](https://github.com/python/mypy/pull/21382)).
64
65 ### Complete Support for Type Variable Defaults (PEP 696)
66
67 Mypy now has complete support for type variable defaults as specified in PEP 696. This allows you to
68 specify default values for type parameters in generic classes, functions, and type aliases.
69
70 Traditional syntax (Python 3.11 and earlier):
71
72 ```python
73 T = TypeVar("T", default=int) # This means that if no type is specified T = int
74
75 @dataclass
76 class Box(Generic[T]):
77 value: T | None = None
78
79 reveal_type(Box()) # type is Box[int]
80 reveal_type(Box(value="Hello World!")) # type is Box[str]
81 ```
82
83 New syntax (Python 3.12+):
84
85 ```python
86 class Box[T = int]:
87 def __init__(self, value: T) -> None:
88 self.value = value
89
90 reveal_type(Box()) # type is Box[int]
91 reveal_type(Box(value="Hello World!")) # type is Box[str]
92 ```
93
94 Type variable defaults work with all forms of generics, including classes, functions, and type aliases.
95 This release completes the implementation by fixing various edge cases involving recursive defaults,
96 dependencies between type variables, and interactions with variadic generics.
97
98 Contributed by Ivan Levkivskyi (PRs [21491](https://github.com/python/mypy/pull/21491),
99 [21526](https://github.com/python/mypy/pull/21526), [21544](https://github.com/python/mypy/pull/21544)).
100
101 ### Respect Explicit Return Type of `__new__()`
102
103 Mypy now respects explicitly annotated return types in `__new__()` methods. Previously, mypy would
104 always assume that `__new__()` returns an instance of the current class, ignoring explicit annotations.
105
106 With this change, if you explicitly annotate a return type that differs from the implicit type, mypy
107 will use the explicit annotation:
108
109 ```python
110 class Factory:
111 def __new__(cls) -> Product:
112 return Product()
113
114 reveal_type(Factory()) # type is Product, not Factory
115 ```
116
117 Note that mypy still gives an error at the definition site if the explicit annotation is not a
118 subtype of the current class, since this is technically not type-safe.
119
120 For backwards compatibility, there are two exceptions:
121 - If the return type is `Any`, mypy will still use the current class as the return type.
122 - If the explicit return type comes from a superclass and is a supertype of the implicit return type,
123 mypy will use the implicit (more specific) type:
124
125 ```python
126 class A:
127 def __new__(cls) -> A: ...
128
129 reveal_type(A()) # type is A
130
131 class B:
132 def __new__(cls) -> B:
133 return cls()
134
135 class C(B): ...
136 reveal_type(C()) # type is C
137 ```
138
139 This fixes several long-standing issues where explicit `__new__()` return types were ignored.
140
141 Contributed by Ivan Levkivskyi (PR [21441](https://github.com/python/mypy/pull/21441)).
142
143 ### TypeForm Support No Longer Experimental
144
145 Support for `TypeForm` is no longer experimental. `TypeForm` (introduced in Python 3.14) allows you
146 to annotate parameters that accept type expressions, providing better type checking for functions
147 that work with types as values.
148
149 ```python
150 from typing import TypeForm
151
152 def make_list(tp: TypeForm[T]) -> list[T]:
153 ...
154
155 # Correctly typed as list[int]
156 int_list = make_list(int)
157 ```
158
159 `TypeForm` support was previously reverted from mypy 2.1 due to a performance regression, but this
160 has now been mitigated.
161
162 Contributed by Ivan Levkivskyi and Jelle Zijlstra (PRs [21262](https://github.com/python/mypy/pull/21262), [21591](https://github.com/python/mypy/pull/21591),
163 [21459](https://github.com/python/mypy/pull/21459)).
164
165 ### Experimental WASM Wheel for Python 3.14
166
167 Mypy now ships an experimental WebAssembly (WASM) wheel for Python 3.14. This allows mypy to run
168 in WASM environments such as Pyodide and browser-based Python implementations.
169
170 The WASM wheel is considered experimental and may have limitations compared to native builds. Please
171 report any issues you encounter when using mypy in WASM environments.
172
173 Contributed by Ivan Levkivskyi (PR [21671](https://github.com/python/mypy/pull/21671)).
174
175 ### Mypyc Free-threading Improvements
176
177 - Make function wrappers thread-safe on free-threaded builds (Jukka Lehtosalo, PR [21620](https://github.com/python/mypy/pull/21620))
178 - Make list remove and index thread-safe on free-threaded builds (Jukka Lehtosalo, PR [21614](https://github.com/python/mypy/pull/21614))
179 - Fix dict iteration memory safety on free-threaded builds (Jukka Lehtosalo, PR [21617](https://github.com/python/mypy/pull/21617))
180 - Make some dict primitives thread-safe on free-threading builds (Jukka Lehtosalo, PR [21616](https://github.com/python/mypy/pull/21616))
181 - Fix free-threading race condition in argument parsing (Jukka Lehtosalo, PR [21613](https://github.com/python/mypy/pull/21613))
182 - Document free threading and other doc updates (Jukka Lehtosalo, PR [21494](https://github.com/python/mypy/pull/21494))
183
184 ### `librt.strings` Updates
185
186 - Add `librt.strings.toupper` and `librt.strings.tolower` codepoint primitives (Vaggelis Danias, PR [21553](https://github.com/python/mypy/pull/21553))
187 - Add `librt.strings.isidentifier` codepoint primitive (Vaggelis Danias, PR [21522](https://github.com/python/mypy/pull/21522))
188 - Add `librt.strings.isalpha` codepoint primitive (Vaggelis Danias, PR [21521](https://github.com/python/mypy/pull/21521))
189 - Add `librt.strings.isalnum` codepoint primitive (Vaggelis Danias, PR [21509](https://github.com/python/mypy/pull/21509))
190 - Add `librt.strings.isdigit` codepoint primitive (Vaggelis Danias, PR [21504](https://github.com/python/mypy/pull/21504))
191 - Add `librt.strings.isspace` char primitive (Vaggelis Danias, PR [21462](https://github.com/python/mypy/pull/21462))
192
193 ### Mypyc Improvements
194
195 - Fix name lookup when class var and module var have the same name (Jukka Lehtosalo, PR [21594](https://github.com/python/mypy/pull/21594))
196 - Report file and line number on uncaught exceptions (Jukka Lehtosalo, PR [21584](https://github.com/python/mypy/pull/21584))
197 - Use `other` arg instead of `self` for RHS type (Ryan Heard, PR [21569](https://github.com/python/mypy/pull/21569))
198 - Use `method_sig` to get the method signature (Ryan Heard, PR [21567](https://github.com/python/mypy/pull/21567))
199 - Preserve inherited attribute defaults under `separate=True` (Jo, PR [21547](https://github.com/python/mypy/pull/21547))
200 - Fix missing cross-group header deps in incremental builds (Jo, PR [21490](https://github.com/python/mypy/pull/21490))
201 - Fix cross-group call to inherited `__mypyc_defaults_setup` (Jo, PR [21481](https://github.com/python/mypy/pull/21481))
202 - Fix non-deterministic class struct layout under `separate=True` (Vaggelis Danias, PR [21530](https://github.com/python/mypy/pull/21530))
203 - Specialize `s[i] == 'x'` to a codepoint int compare (Vaggelis Danias, PR [21579](https://github.com/python/mypy/pull/21579))
204 - Fix reference leak in mypyc bytes concatenation (Colinxu2020, PR [21469](https://github.com/python/mypy/pull/21469))
205
206 ### Fixes to Crashes
207
208 - Fix crash on invalid recursive variadic alias (Ivan Levkivskyi, PR [21572](https://github.com/python/mypy/pull/21572))
209 - Fix crashes on variadic unpacking in synthetic types (Ivan Levkivskyi, PR [21555](https://github.com/python/mypy/pull/21555))
210 - Fix crash on unhandled meet variadic tuple vs instance (Ivan Levkivskyi, PR [21558](https://github.com/python/mypy/pull/21558))
211 - Fix crash on deferred generic class nested in function (Ivan Levkivskyi, PR [21557](https://github.com/python/mypy/pull/21557))
212 - Fix crash in new-style type alias with variadic unpack (Ivan Levkivskyi, PR [21551](https://github.com/python/mypy/pull/21551))
213 - Fix various crashes on recursive type variable defaults (Ivan Levkivskyi, PR [21491](https://github.com/python/mypy/pull/21491))
214 - Fix crash for empty `Annotated` type application (Rayan Salhab, PR [21503](https://github.com/python/mypy/pull/21503))
215 - Fix crash on `Unpack` used without arguments in class bases (Sai Asish Y, PR [21470](https://github.com/python/mypy/pull/21470))
216
217 ### Performance Improvements
218
219 - Memoize the options snapshot (Kevin Kannammalil, PR [21354](https://github.com/python/mypy/pull/21354))
220 - Don't include `not_ready_deps` tracking as relating to mypy internals (Kevin Kannammalil, PR [21389](https://github.com/python/mypy/pull/21389))
221 - Speed up transitive dependency hash for singleton SCCs (Kevin Kannammalil, PR [21390](https://github.com/python/mypy/pull/21390))
222 - Optimize typeform checks (Jelle Zijlstra, PR [21459](https://github.com/python/mypy/pull/21459))
223
224 ### Improvements to the Native Parser
225
226 - Support `--shadow-file` with `--native-parser` (Jukka Lehtosalo, PR [21623](https://github.com/python/mypy/pull/21623))
227 - Add Python version checks to native parser (Kevin Kannammalil, PR [21539](https://github.com/python/mypy/pull/21539))
228 - Allow nativeparse to parse source code directly (bzoracler, PR [21260](https://github.com/python/mypy/pull/21260))
229
230 ### Other Notable Fixes and Improvements
231
232 - Add function definition notes for `too many positional arguments` errors (Kevin Kannammalil, PR [21410](https://github.com/python/mypy/pull/21410))
233 - Fix the exportjson tool (.ff cache to .json conversion) (Jukka Lehtosalo, PR [21628](https://github.com/python/mypy/pull/21628))
234 - Support floats in JSON in fixed-format cache (Ivan Levkivskyi, PR [21603](https://github.com/python/mypy/pull/21603))
235 - Update `TypedDictType.__init__` signature to preserve backward compat (Jukka Lehtosalo, PR [21590](https://github.com/python/mypy/pull/21590))
236 - Fix constructor calls for union-bounded `TypeVar`s (Jingchen Ye, PR [21571](https://github.com/python/mypy/pull/21571))
237 - Fix `TypedDict` indexing with literal keys in comprehensions (Jingchen Ye, PR [21556](https://github.com/python/mypy/pull/21556))
238 - Correctly handle empty tuple index when unpacked (Ivan Levkivskyi, PR [21545](https://github.com/python/mypy/pull/21545))
239 - Support protocol checks for self-types in tuple types (Ivan Levkivskyi, PR [21535](https://github.com/python/mypy/pull/21535))
240 - Fix edge cases in variadic tuple subclasses (Ivan Levkivskyi, PR [21518](https://github.com/python/mypy/pull/21518))
241 - Special-case constructor for tuple types (Ivan Levkivskyi, PR [21502](https://github.com/python/mypy/pull/21502))
242 - 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))
243 - Use explicit `Never` for type inference (Ivan Levkivskyi, PR [21497](https://github.com/python/mypy/pull/21497))
244 - Narrow membership in statically known containers (Shantanu, PR [21461](https://github.com/python/mypy/pull/21461))
245 - Improve negative narrowing for membership checks on tuples (Shantanu, PR [21456](https://github.com/python/mypy/pull/21456))
246 - Analyze `TypedDict` decorators (Pranav Manglik, PR [21267](https://github.com/python/mypy/pull/21267))
247 - Start testing Python 3.15 (Marc Mueller, PR [21439](https://github.com/python/mypy/pull/21439))
248 - Improved handling of `NamedTuple`, `TypedDict`, `Enum`, and regular classes nested in functions (Ivan Levkivskyi, PR [21478](https://github.com/python/mypy/pull/21478))
249
250 ### Typeshed Updates
251
252 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.
253
254 ### Acknowledgements
255
256 Thanks to all mypy contributors who contributed to this release:
257
258 - Adam Turner
259 - alicederyn
260 - bzoracler
261 - Colinxu2020
262 - georgesittas
263 - Ivan Levkivskyi
264 - Jelle Zijlstra
265 - Jingchen Ye
266 - Jukka Lehtosalo
267 - Kevin Kannammalil
268 - lphuc2250gma
269 - Marc Mueller
270 - Pranav Manglik
271 - Rayan Salhab
272 - Ryan Heard
273 - Sai Asish Y
274 - Shantanu
275 - sobolevn
276 - Vaggelis Danias
277 - Victor Letichevsky
278 - Zakir Jiwani
279
280 I'd also like to thank my employer, Dropbox, for supporting mypy development.
281
282 ## Mypy 2.1
283
284 We’ve just uploaded mypy 2.1.0 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).
285 Mypy is a static type checker for Python. This release includes new features, performance
286 improvements and bug fixes. You can install it as follows:
287
288 python3 -m pip install -U mypy
289
290 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
291
292 ### librt.vecs: Fast Growable Array Type for Mypyc
293
294 The new `librt.vecs` module provides an efficient growable array type `vec` that is
295 optimized for mypyc use. It provides fast, packed arrays with integer and floating point
296 value types, which can be **several times faster** than `list`, and tens of times faster
297 than `array.array` in code compiled using mypyc. It also supports nested `vec` objects and
298 non-value-type items, such as ``vec[vec[str]]``.
299
300 Refer to the [documentation](https://mypyc.readthedocs.io/en/latest/librt_vecs.html) for
301 the details.
302
303 Contributed by Jukka Lehtosalo.
304
305 ### librt.random: Fast Pseudo-Random Number Generation
306
307 The new `librt.random` module provides fast pseudo-random number generation that is
308 optimized for code compiled using mypyc. It can be 3x to 10x faster than the stdlib
309 `random` module in compiled code.
310
311 Refer to the [documentation](https://mypyc.readthedocs.io/en/latest/librt_random.html) for
312 the details.
313
314 Contributed by Jukka Lehtosalo (PR [21433](https://github.com/python/mypy/pull/21433)).
315
316 ### Mypyc Improvements
317
318 - Enable incremental self-compilation (Vaggelis Danias, PR [21369](https://github.com/python/mypy/pull/21369))
319 - Make compilation order with multiple files consistent (Piotr Sawicki, PR [21419](https://github.com/python/mypy/pull/21419))
320 - Fix crash on accessing `StopAsyncIteration` (Piotr Sawicki, PR [21406](https://github.com/python/mypy/pull/21406))
321 - Fix incremental compilation with `separate` flag (Vaggelis Danias, PR [21299](https://github.com/python/mypy/pull/21299))
322
323 ### Fixes to Crashes
324
325 - Fix crash on partial type with `--allow-redefinition` and `global` declaration (Jukka Lehtosalo, PR [21428](https://github.com/python/mypy/pull/21428))
326 - Fix broken awaitable generator patching (Ivan Levkivskyi, PR [21435](https://github.com/python/mypy/pull/21435))
327
328 ### Changes to Messages
329
330 - Fix function call error message for small number of arguments (sobolevn, PR [21432](https://github.com/python/mypy/pull/21432))
331
332 ### Other Notable Fixes and Improvements
333
334 - Rely on typeshed stubs for `slice` typing (Ivan Levkivskyi, PR [21401](https://github.com/python/mypy/pull/21401))
335 - Narrow match captures based on previous cases (Shantanu, PR [21405](https://github.com/python/mypy/pull/21405))
336 - Fix nondeterminism in overload resolution (Shantanu, PR [21455](https://github.com/python/mypy/pull/21455))
337 - Respect file config comments for stale modules (Adam Turner, PR [21444](https://github.com/python/mypy/pull/21444))
338 - Fix JSON output mode for syntax errors in parallel mode (Adam Turner, PR [21434](https://github.com/python/mypy/pull/21434))
339 - Fix type variable with values as a supertype (Ivan Levkivskyi, PR [21431](https://github.com/python/mypy/pull/21431))
340 - Add support for configuring `--num-workers` with an environment variable (Kevin Kannammalil, PR [21407](https://github.com/python/mypy/pull/21407))
341 - Respect JSON output mode for syntax errors (Adam Turner, PR [21386](https://github.com/python/mypy/pull/21386))
342
343 ### Typeshed Updates
344
345 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.
346
347 ### Acknowledgements
348
349 Thanks to all mypy contributors who contributed to this release:
350
351 - Adam Turner
352 - Ivan Levkivskyi
353 - Jukka Lehtosalo
354 - Kevin Kannammalil
355 - Piotr Sawicki
356 - Shantanu
357 - sobolevn
358 - Vaggelis Danias
359
360 I’d also like to thank my employer, Dropbox, for supporting mypy development.
361
362 ## Mypy 2.0
363
364 We’ve just uploaded mypy 2.0.0 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).
365 Mypy is a static type checker for Python. This release includes new features, performance
366 improvements and bug fixes. There are also changes to options and defaults.
367 You can install it as follows:
368
369 python3 -m pip install -U mypy
370
371 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
372
373 ### Enable `--local-partial-types` by Default
374
375 This flag affects the inference of types based on assignments in other scopes.
376 For now, explicitly disabling this continues to be supported, but this support will be removed
377 in the future as the legacy behaviour is hard to support with other current and future features
378 in mypy, like the daemon or the new implementation of flexible redefinitions.
379
380 Contributed by Ivan Levkivskyi, Jukka Lehtosalo, Shantanu in [PR 21163](https://github.com/python/mypy/pull/21163).
381
382 ### Enable `--strict-bytes` by Default
383
384 Per [PEP 688](https://peps.python.org/pep-0688), mypy no longer treats `bytearray` and `memoryview`
385 values as assignable to the `bytes` type.
386
387 Contributed by Shantanu in [PR 18371](https://github.com/python/mypy/pull/18371).
388
389 ### New Behavior for `--allow-redefinition`
390
391 The `--allow-redefinition` flag now behaves like `--allow-redefinition-new` in mypy 1.20
392 and earlier. The new behavior is generally more flexible. For example, you can have different
393 types for a variable in different blocks:
394
395 ```python
396 # mypy: allow-redefinition
397
398 def foo(cond: bool) -> None:
399 if cond:
400 for x in ["a", "b"]:
401 # Type of "x" is "str" here
402 ...
403 else:
404 for x in [1, 2]:
405 # Type of "x" is "int" here
406 ...
407 ```
408
409 The new behavior requires `--local-partial-types`, which is now enabled by default.
410
411 However, `--allow-redefinition` doesn't allow giving two type annotations for the same
412 variable. The old behavior (sometimes) allows this. Code like this now generates an error
413 when using `--allow-redefinition`:
414
415 ```python
416 def foo() -> None:
417 x: list[int] = []
418 ...
419 x: list[str] = [] # Error: "x" redefined
420 ...
421 ```
422
423 You can still use `--allow-redefinition-old` to fall back to the old behavior. We have no
424 plans to remove the legacy behavior, but the old functionality is maintained on a best effort
425 basis.
426
427 Contributed by Jukka Lehtosalo in [PR 21276](https://github.com/python/mypy/pull/21276).
428
429 ### Parallel Type Checking
430
431 Mypy now supports experimental parallel and incremental type checking. Use `--num-workers N`
432 or `-nN` to use `N` worker processes to type check in parallel. The speedup depends on the
433 import structure of your codebase and your environment, but for large projects we've seen
434 performance gains of **up to 5x** when using 8 worker processes.
435
436 Parallel type checking implicitly enables the new native parser. There are still some
437 minor semantic differences between parallel and non-parallel modes, which we will be fixing
438 in future mypy releases.
439
440 Contributed by Ivan Levkivskyi, with additional contributions from Emma Smith and Jukka
441 Lehtosalo.
442
443 Recent related changes since the last release:
444
445 - Freeze garbage collection in parallel workers for 4-5% speedup (Ivan Levkivskyi, PR [21302](https://github.com/python/mypy/pull/21302))
446 - Expose `--num-workers` and `--native-parser` (Ivan Levkivskyi, PR [21387](https://github.com/python/mypy/pull/21387))
447 - Split type checking into interface and implementation in parallel workers (Ivan Levkivskyi, PR [21119](https://github.com/python/mypy/pull/21119))
448 - Batch module groups for parallel processing (Ivan Levkivskyi, PR [21287](https://github.com/python/mypy/pull/21287))
449 - Optimize parallel worker startup (Ivan Levkivskyi, PR [21203](https://github.com/python/mypy/pull/21203))
450 - Parse files in parallel when possible (Ivan Levkivskyi, PR [21175](https://github.com/python/mypy/pull/21175))
451 - Use parallel parsing at all stages (Ivan Levkivskyi, PR [21266](https://github.com/python/mypy/pull/21266))
452 - Fix sequential bottleneck in parallel parsing (Jukka Lehtosalo, PR [21291](https://github.com/python/mypy/pull/21291))
453 - Fail fast when a user tries to generate reports with parallel workers (Ivan Levkivskyi, PR [21341](https://github.com/python/mypy/pull/21341))
454 - Partially support old NumPy plugin in parallel type checking (Ivan Levkivskyi, PR [21324](https://github.com/python/mypy/pull/21324))
455 - Handle reachability consistently in parallel type checking (Ivan Levkivskyi, PR [21322](https://github.com/python/mypy/pull/21322))
456 - Always respect `@no_type_check` in parallel type checking (Ivan Levkivskyi, PR [21320](https://github.com/python/mypy/pull/21320))
457 - Minor fixes in parallel checking (Ivan Levkivskyi, PR [21319](https://github.com/python/mypy/pull/21319))
458 - Fix plugin logic in parallel type checking (Ivan Levkivskyi, PR [21252](https://github.com/python/mypy/pull/21252))
459 - Fix Windows IPC race condition when using parallel checking (Jukka Lehtosalo, PR [21228](https://github.com/python/mypy/pull/21228))
460 - Report parallel worker exit status on receive failure (Jukka Lehtosalo, PR [21224](https://github.com/python/mypy/pull/21224))
461
462 ### Drop Support for Targeting Python 3.9
463
464 Mypy no longer supports type checking code with `--python-version 3.9`.
465 Use `--python-version 3.10` or newer.
466
467 Contributed by Shantanu, Marc Mueller in [PR 21243](https://github.com/python/mypy/pull/21243).
468
469 ### Remove Special Casing of Legacy Bundled Stubs
470
471 Mypy used to bundle stubs for a few packages in versions 0.812 and earlier. To navigate the
472 transition, mypy used to report missing types for these packages even if `--ignore-missing-imports`
473 was set. Mypy now consistently respects `--ignore-missing-imports` for all packages.
474
475 Contributed by Shantanu in [PR 18372](https://github.com/python/mypy/pull/18372).
476
477 ### Prevent Assignment to None for Non-Optional Class Variables with Type Comments
478
479 Mypy used to allow assignment to None for class variables when using type comments. This was a
480 common idiom in Python 3.5 and earlier, prior to the introduction of variable annotations.
481 However, this was a soundness hole and has now been removed.
482
483 Contributed by Shantanu in [PR 20054](https://github.com/python/mypy/pull/20054).
484
485 ### librt.strings: String and Bytes Primitives for Mypyc
486
487 In mypy 1.20, we introduced [librt](https://pypi.org/project/librt/) as a standard library
488 for mypyc that fills in some gaps in the Python standard library and the C API.
489 This release adds the new module `librt.strings`, which contains utilities for building
490 string and bytes objects, and for accessing and generating binary data:
491
492 * `StringWriter` and `BytesWriter` classes allow quickly building `str` and `bytes` objects
493 from parts.
494 * `read_*` and `write_*` functions provide fast reading and writing of binary-encoded data.
495
496 Refer to the [documentation](https://mypyc.readthedocs.io/en/latest/librt_strings.html) for
497 the details.
498
499 Contributed by Jukka Lehtosalo.
500
501 ### Mypyc Improvements
502
503 - Document `librt.time` (Jukka Lehtosalo, PR [21372](https://github.com/python/mypy/pull/21372))
504 - Mark `librt.time.time()` non-experimental (Ivan Levkivskyi, PR [21310](https://github.com/python/mypy/pull/21310))
505 - Fix `librt.time` primitive now that it is no longer experimental (Ivan Levkivskyi, PR [21318](https://github.com/python/mypy/pull/21318))
506 - Fix `librt` API/ABI version checks (Jukka Lehtosalo, PR [21311](https://github.com/python/mypy/pull/21311))
507 - Generate more type methods for classes with attribute dictionaries (Piotr Sawicki, PR [21290](https://github.com/python/mypy/pull/21290))
508 - Fix reference counting for tuple items during deallocation (Shantanu, PR [21245](https://github.com/python/mypy/pull/21245))
509 - Release new instances when `__init__` raises (Shantanu, PR [21248](https://github.com/python/mypy/pull/21248))
510 - Fix `@property` getter memory leak (Vaggelis Danias, PR [21230](https://github.com/python/mypy/pull/21230))
511 - Fix semantics for walrus expression in tuple (Shantanu, PR [21249](https://github.com/python/mypy/pull/21249))
512 - Fix crash on import errors during cleanup (Shantanu, PR [21247](https://github.com/python/mypy/pull/21247))
513 - Fix reference leak in str index (Shantanu, PR [21251](https://github.com/python/mypy/pull/21251))
514 - Fix memory leak in integer true division (Shantanu, PR [21246](https://github.com/python/mypy/pull/21246))
515 - Fix reference leaks in `list.clear()`/`dict.clear()` (Shantanu, PR [21244](https://github.com/python/mypy/pull/21244))
516 - Resolve type aliases in function specialization (esarp, PR [21233](https://github.com/python/mypy/pull/21233))
517 - Report an error if an acyclic class inherits from non-acyclic (Piotr Sawicki, PR [21227](https://github.com/python/mypy/pull/21227))
518 - Fix `b64decode` to match new CPython behavior (Piotr Sawicki, PR [21200](https://github.com/python/mypy/pull/21200))
519
520 ### Fixes to Crashes
521
522 - Fix crash when a file does not exist during semantic analysis (Ivan Levkivskyi, PR [21379](https://github.com/python/mypy/pull/21379))
523 - Fix parallel worker crash on syntax error (Ivan Levkivskyi, PR [21202](https://github.com/python/mypy/pull/21202))
524
525 ### Changes to Messages
526
527 - Improve error messages for unexpected keyword arguments in overloaded functions (Kevin Kannammalil, PR [20592](https://github.com/python/mypy/pull/20592))
528 - Don't suggest `Foo[...]` when `Foo(arg=...)` is used in annotation (Yosof Badr, PR [21238](https://github.com/python/mypy/pull/21238))
529 - Mention what codes are actually ignored in "not covered by type: ignore comment" note (wyattscarpenter, PR [19904](https://github.com/python/mypy/pull/19904))
530 - Improve error messages when positional argument is missing (Kevin Kannammalil, PR [20591](https://github.com/python/mypy/pull/20591))
531 - Improve "name is not defined" errors with fuzzy matching (Kevin Kannammalil, PR [20693](https://github.com/python/mypy/pull/20693))
532 - Add suggestions for misspelled module imports (Kevin Kannammalil, PR [20695](https://github.com/python/mypy/pull/20695))
533
534 ### Performance Improvements
535
536 - Replace `NamedTuple` with faster regular classes in hot paths (Shantanu, PR [21326](https://github.com/python/mypy/pull/21326))
537 - Avoid calling best-match suggestions unless the message is shown (Ivan Levkivskyi, PR [21307](https://github.com/python/mypy/pull/21307))
538 - Order cases in native parser based on AST node frequency (Jukka Lehtosalo, PR [21219](https://github.com/python/mypy/pull/21219))
539
540 ### Stubtest Improvements
541
542 - Basic support for unpack kwargs (Shantanu, PR [21024](https://github.com/python/mypy/pull/21024))
543 - Fix false positive for properties with a deleter (Pranav Manglik, PR [21259](https://github.com/python/mypy/pull/21259))
544
545 ### Documentation Updates
546
547 - Rename "value restriction" to "value-constrained type variable" (Leo Ji, PR [21112](https://github.com/python/mypy/pull/21112))
548 - Clarify that invariant-by-default applies to legacy `TypeVar` syntax (Leo Ji, PR [21108](https://github.com/python/mypy/pull/21108))
549
550 ### Improvements to the Native Parser
551
552 The new native parser is still experimental.
553
554 - Make new parser consistent with the old one (Ivan Levkivskyi, PR [21377](https://github.com/python/mypy/pull/21377))
555 - Support `--package-root` with the native parser (Ivan Levkivskyi, PR [21321](https://github.com/python/mypy/pull/21321))
556 - Improve call expressions in type annotations with the native parser (Jukka Lehtosalo, PR [21300](https://github.com/python/mypy/pull/21300))
557 - Depend on `ast-serialize` by default (Jukka Lehtosalo, PR [21297](https://github.com/python/mypy/pull/21297))
558
559 ### Other Notable Fixes and Improvements
560
561 - Fix narrowing for `AbstractSet` and `Mapping` (Shantanu, PR [21352](https://github.com/python/mypy/pull/21352))
562 - Preserve gradual guarantee when narrowing `Any` union via equality (Shantanu, PR [21368](https://github.com/python/mypy/pull/21368))
563 - Make type variable upper bound narrowing symmetric (Ivan Levkivskyi, PR [21350](https://github.com/python/mypy/pull/21350))
564 - Behave consistently when type-checking a stub package directly (Ivan Levkivskyi, PR [21330](https://github.com/python/mypy/pull/21330))
565 - Add support for `Final[...]` in dataclasses (Ivan Levkivskyi, PR [21334](https://github.com/python/mypy/pull/21334))
566 - Narrow more sequence parents (Shantanu, PR [21327](https://github.com/python/mypy/pull/21327))
567 - Better narrowing for enums and other types with known equality (Shantanu, PR [21281](https://github.com/python/mypy/pull/21281))
568 - Fix pathspec error (Ivan Levkivskyi, PR [21296](https://github.com/python/mypy/pull/21296))
569 - Use sharding for the SQLite cache (Jukka Lehtosalo, PR [21292](https://github.com/python/mypy/pull/21292))
570 - Limit type inference context fallback to the walrus operator only (Ivan Levkivskyi, PR [21294](https://github.com/python/mypy/pull/21294))
571 - Support `.git/info/exclude` for `--exclude-gitignore` (RogerJinIS, PR [21286](https://github.com/python/mypy/pull/21286))
572 - Let `--allow-redefinition` widen a global in a function with `None` initialization (Jukka Lehtosalo, PR [21285](https://github.com/python/mypy/pull/21285))
573 - Delete Python 2 extra (Shantanu, PR [18374](https://github.com/python/mypy/pull/18374))
574 - No longer narrow final globals in functions (Ivan Levkivskyi, PR [21241](https://github.com/python/mypy/pull/21241))
575 - Narrow unions containing `Any` in conditional branches (Shantanu, PR [21231](https://github.com/python/mypy/pull/21231))
576 - Propagate narrowing within chained comparisons (Shantanu, PR [21160](https://github.com/python/mypy/pull/21160))
577 - Add proper lazy deserialization (Ivan Levkivskyi, PR [21198](https://github.com/python/mypy/pull/21198))
578 - Add `install_types` to options affecting cache (Brian Schubert, PR [21070](https://github.com/python/mypy/pull/21070))
579 - Narrow `Any` in conditional type checks (Shantanu, PR [21167](https://github.com/python/mypy/pull/21167))
580 - Fix exception handler target location in new parser (Ivan Levkivskyi, PR [21185](https://github.com/python/mypy/pull/21185))
581 - Improve traceback display (Shantanu, PR [21155](https://github.com/python/mypy/pull/21155))
582 - Include two more files in the sdist: `CREDITS` and the typeshed `README` (Michael R. Crusoe, PR [21131](https://github.com/python/mypy/pull/21131))
583
584 ### Typeshed Updates
585
586 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.
587
588 ### Acknowledgements
589
590 Thanks to all mypy contributors who contributed to this release:
591 - Brian Schubert
592 - Ethan Sarp
593 - Ivan Levkivskyi
594 - Jukka Lehtosalo
595 - Kevin Kannammalil
596 - Leo Ji
597 - Marc Mueller
598 - Michael R. Crusoe
599 - Piotr Sawicki
600 - Pranav Manglik
601 - RogerJinIS
602 - Shantanu
603 - Vaggelis Danias
604 - wyattscarpenter
605 - Yosof Badr
606
607 I’d also like to thank my employer, Dropbox, for supporting mypy development.
608
609 ## Mypy 1.20
610
611 We’ve just uploaded mypy 1.20.0 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).
612 Mypy is a static type checker for Python. This release includes new features, performance
613 improvements and bug fixes. You can install it as follows:
614
615 python3 -m pip install -U mypy
616
617 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
618
619 ### Planned Changes to Defaults and Flags in Mypy 2.0
620
621 As a reminder, we are planning to enable `--local-partial-types` by default in mypy 2.0, which
622 will likely be the next feature release. This will often require at least minor code changes. This
623 option is implicitly enabled by mypy daemon, so this makes the behavior of daemon and non-daemon
624 modes consistent.
625
626 Note that this release improves the compatibility of `--local-partial-types` significantly to
627 make the switch easier (see below for more).
628
629 This can also be configured in a mypy configuration file (use `False` to disable):
630
631 ```
632 local_partial_types = True
633 ```
634
635 For more information, refer to the
636 [documentation](https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-local-partial-types).
637
638 We will also enable `--strict-bytes` by default in mypy 2.0. This usually requires at most
639 minor code changes to adopt. For more information, refer to the
640 [documentation](https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-strict-bytes).
641
642 Finally, `--allow-redefinition-new` will be renamed to `--allow-redefinition`. If you want
643 to continue using the older `--allow-redefinition` semantics which are less flexible (e.g.
644 limited support for conditional redefinitions), you can switch to `--allow-redefinition-old`,
645 which is currently supported as an alias to the legacy `--allow-redefinition` behavior.
646 To use `--allow-redefinition` in the upcoming mypy 2.0, you can't use `--no-local-partial-types`.
647 For more information, refer to the
648 [documentation](https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-allow-redefinition-new).
649
650 ### Better Type Narrowing
651
652 Mypy's implementation of narrowing has been substantially reworked. Mypy will now narrow more
653 aggressively, more consistently, and more correctly. In particular, you are likely to notice new
654 narrowing behavior in equality expressions (`==`), containment expressions (`in`),
655 match statements, and additional expressions providing type guards.
656
657 Note that mypy (and other Python type checkers) do not model the potential for various non-local
658 operations to invalidate narrowing assumptions. This means mypy may conclude that some of your code
659 is [unreachable](https://mypy.readthedocs.io/en/stable/common_issues.html#unreachable-code) and
660 avoid further checking of it. The `--warn-unreachable` flag is useful for highlighting these cases.
661 To reset narrowing, you can insert dummy reassignments, for instance `var = var` will reset
662 all narrowing of `var.attr`.
663
664 Future work includes better narrowing on initial assignments, more narrowing to `Literal` types,
665 and better checking of unreachable code.
666
667 Contributed by Shantanu Jain.
668
669 - Rework narrowing logic for equality and identity (Shantanu, PR [20492](https://github.com/python/mypy/pull/20492))
670 - Refactor equality and identity narrowing for clarity (Shantanu, PR [20595](https://github.com/python/mypy/pull/20595))
671 - Treat NotImplemented as a singleton type (Shantanu, PR [20601](https://github.com/python/mypy/pull/20601))
672 - Improve narrowing logic for Enum int and str subclasses (Shantanu, PR [20609](https://github.com/python/mypy/pull/20609))
673 - Narrow types based on collection containment (Shantanu, PR [20602](https://github.com/python/mypy/pull/20602))
674 - Refactor and improve narrowing for type(x) == t checks (Shantanu, PR [20634](https://github.com/python/mypy/pull/20634))
675 - Narrow for type expr comparisons to type exprs (Shantanu, PR [20639](https://github.com/python/mypy/pull/20639))
676 - Narrowing for comparisons against `x.__class__` (Shantanu, PR [20642](https://github.com/python/mypy/pull/20642))
677 - Better narrowing with custom equality (Shantanu, PR [20643](https://github.com/python/mypy/pull/20643))
678 - Use a single pass for core narrowing logic, add comments (Shantanu, PR [20659](https://github.com/python/mypy/pull/20659))
679 - Narrowing for final type objects (Shantanu, PR [20661](https://github.com/python/mypy/pull/20661))
680 - Avoid narrowing type[T] (Shantanu, PR [20662](https://github.com/python/mypy/pull/20662))
681 - Avoid widening to Any for checks like `type(x) is type(y: Any)` (Shantanu, PR [20663](https://github.com/python/mypy/pull/20663))
682 - Preserve some lost narrowing, cleanup (Shantanu, PR [20674](https://github.com/python/mypy/pull/20674))
683 - Fix narrowing related code for types with overloaded `__new__` (Shantanu, PR [20676](https://github.com/python/mypy/pull/20676))
684 - Fix isinstance with unions of tuples (Shantanu, PR [20677](https://github.com/python/mypy/pull/20677))
685 - Fix regression to chained containment (Shantanu, PR [20688](https://github.com/python/mypy/pull/20688))
686 - Improve else handling with custom equality (Shantanu, PR [20692](https://github.com/python/mypy/pull/20692))
687 - Better model runtime in isinstance and type checks (Shantanu, PR [20675](https://github.com/python/mypy/pull/20675))
688 - Use --warn-unreachable and --strict-equality in more tests (Shantanu, PR [20707](https://github.com/python/mypy/pull/20707))
689 - Model exact narrowing with type(x) checks (Shantanu, PR [20703](https://github.com/python/mypy/pull/20703))
690 - Short term fix for bytes narrowing (Shantanu, PR [20704](https://github.com/python/mypy/pull/20704))
691 - Preserve narrowing in unreachable code (Shantanu, PR [20710](https://github.com/python/mypy/pull/20710))
692 - Fix bug when narrowing union containing custom eq against custom eq (Shantanu, PR [20754](https://github.com/python/mypy/pull/20754))
693 - Fix narrowing for unions (Shantanu, PR [20728](https://github.com/python/mypy/pull/20728))
694 - Unsoundly narrow away from None with custom eq (Shantanu, PR [20756](https://github.com/python/mypy/pull/20756))
695 - Improve narrowing with numeric types (Shantanu, PR [20727](https://github.com/python/mypy/pull/20727))
696 - Fix narrowing with final type objects (Shantanu, PR [20743](https://github.com/python/mypy/pull/20743))
697 - Further improve match statement narrowing against unions (Shantanu, PR [20744](https://github.com/python/mypy/pull/20744))
698 - Avoid narrowing to NewType (Shantanu, PR [20766](https://github.com/python/mypy/pull/20766))
699 - Better match narrowing for irrefutable sequence patterns (Shantanu, PR [20782](https://github.com/python/mypy/pull/20782))
700 - Remove prohibit_none_typevar_overlap (Shantanu, PR [20864](https://github.com/python/mypy/pull/20864))
701 - Fix match statement narrowing reachability for tuples (Shantanu, PR [20896](https://github.com/python/mypy/pull/20896))
702 - Better handling of generics when narrowing (Shantanu, PR [20863](https://github.com/python/mypy/pull/20863))
703 - Better match narrowing for type objects (Shantanu, PR [20872](https://github.com/python/mypy/pull/20872))
704 - Narrow Callable generic return types (Shantanu, PR [20868](https://github.com/python/mypy/pull/20868))
705 - Better match narrowing for unions of type objects (Shantanu, PR [20905](https://github.com/python/mypy/pull/20905))
706 - Improve reachability in narrowing logic (Shantanu, PR [20660](https://github.com/python/mypy/pull/20660))
707 - Better match narrowing for irrefutable mapping patterns (Shantanu, PR [20906](https://github.com/python/mypy/pull/20906))
708 - Fix match statement semantic reachability (Shantanu, PR [20968](https://github.com/python/mypy/pull/20968))
709 - Add some additional narrowing test cases (Shantanu, PR [20598](https://github.com/python/mypy/pull/20598))
710 - Move tests to check-narrowing , improve them slightly (Shantanu, PR [20637](https://github.com/python/mypy/pull/20637))
711 - Add more tests for narrowing logic (Shantanu, PR [20672](https://github.com/python/mypy/pull/20672))
712 - More testing related improvements and updates (Shantanu, PR [20709](https://github.com/python/mypy/pull/20709))
713 - Add --warn-unreachable to more tests (Shantanu, PR [20977](https://github.com/python/mypy/pull/20977))
714
715 ### Drop Support for Python 3.9
716
717 Mypy no longer supports running with Python 3.9, which has reached end of life.
718 When running mypy with Python 3.10+, it is still possible to type check code
719 that needs to support Python 3.9 with the `--python-version 3.9` argument.
720 Support for this will be dropped in the first half of 2026!
721
722 Contributed by Marc Mueller (PR [20156](https://github.com/python/mypy/pull/20156)).
723
724 ### Mypyc Accelerated Mypy Wheels for ARM Windows and Free Threading
725
726 For best performance, mypy can be compiled to C extension modules using mypyc. This makes
727 mypy 3-5x faster than when interpreted with pure Python. We now build and upload mypyc
728 accelerated mypy wheels for `win_arm64` and `cp314t-...` to PyPI, making it easy for Windows
729 users on ARM and those using the free theading builds for Python 3.14 to realise this speedup
730 -- just `pip install` the latest mypy.
731
732 Contributed by Marc Mueller
733 (PR [mypy_mypyc-wheels#106](https://github.com/mypyc/mypy_mypyc-wheels/pull/106),
734 PR [mypy_mypyc-wheels#110](https://github.com/mypyc/mypy_mypyc-wheels/pull/110)).
735
736 ### Improved Compatibility for Local Partial Types
737
738 Compatibility between mypy's default behavior and the `--local-partial-types` flag
739 is now improved. This improves compatibility between mypy daemon and non-daemon modes,
740 since the mypy daemon requires local partial types to be enabled.
741
742 In particular, code like this now behaves consistently independent of
743 whether local partial types are enabled or not:
744
745 ```python
746 x = None
747
748 def foo() -> None:
749 global x
750 x = 1
751
752 # The inferred type of 'x' is always 'int | None'.
753 ```
754
755 Also, we are planning to turn local partial types on by default in mypy 2.0 (to be
756 released soon), and this makes the change much less disruptive. Explicitly disabling local
757 partial types will continue to be supported, but the support will likely be
758 deprecated and removed eventually, as the legacy behavior is hard to support together with
759 some important changes we are working on, in addition to being incompatible with the mypy
760 daemon.
761
762 This feature was contributed by Ivan Levkivskyi (PR [20938](https://github.com/python/mypy/pull/20938)).
763
764 ### Python 3.14 T-String Support (PEP 750)
765
766 Mypy now supports t-strings that were introduced in Python 3.14.
767
768 - Add support for Python 3.14 t-strings (PEP 750) (Neil Schemenauer and Brian Schubert, PR [20850](https://github.com/python/mypy/pull/20850))
769 - Add implicit module dependency if using t-string (Jukka Lehtosalo, PR [20900](https://github.com/python/mypy/pull/20900))
770
771 ### Experimental New Parser
772
773 If you install mypy using `pip install mypy[native-parser]` and run mypy with
774 `--native-parser`, you can experiment with a new Python parser. It is based on
775 the Ruff parser, and it's more efficient than the default parser. It will also enable
776 access to all Python syntax independent of which Python version you use to run mypy.
777 The new parser is still not feature-complete and has known issues.
778
779 Related changes:
780
781 - Add work-in-progress implementation of a new Python parser (Jukka Lehtosalo, PR [20856](https://github.com/python/mypy/pull/20856))
782 - Skip redundant analysis pass when using the native parser (Ivan Levkivskyi, PR [21015](https://github.com/python/mypy/pull/21015))
783 - Add t-string support to native parser (Ivan Levkivskyi, PR [21007](https://github.com/python/mypy/pull/21007))
784 - Handle hex bigint literals in native parser (Ivan Levkivskyi, PR [20988](https://github.com/python/mypy/pull/20988))
785 - Pass all relevant options to native parser (Ivan Levkivskyi, PR [20984](https://github.com/python/mypy/pull/20984))
786 - Support `@no_type_check` with native parser (Ivan Levkivskyi, PR [20959](https://github.com/python/mypy/pull/20959))
787 - Fix error code handling in native parser (Ivan Levkivskyi, PR [20952](https://github.com/python/mypy/pull/20952))
788 - Add `ast-serialize` as an optional dependency (Ivan Levkivskyi, PR [21028](https://github.com/python/mypy/pull/21028))
789 - Use `native-parser` instead of `native-parse` for optional dependency (Jukka Lehtosalo, PR [21115](https://github.com/python/mypy/pull/21115))
790
791 ### Performance Improvements
792
793 Mypy now uses a binary cache format (fixed-format cache) by default to speed up incremental
794 checking. You can still use `--no-fixed-format-cache` to use the legacy JSON cache format,
795 but we will remove the JSON cache format in a future release. Mypy includes a tool to convert
796 individual fixed-format cache files (.ff) to the JSON format to make it possible to inspect
797 cache contents:
798
799 ```python
800 python -m mypy.exportjson <path> ...
801 ```
802
803 If the SQLite cache is enabled, you will first need to convert the SQLite cache into
804 individual files using the [`misc/convert-cache.py`](https://github.com/python/mypy/blob/master/misc/convert-cache.py)
805 tool available in the mypy GitHub repository. You can also disable the SQLite
806 cache using `--no-sqlite-cache`.
807
808 The SQLite cache (`--sqlite-cache`) is now enabled by default. It improves mypy
809 performance significantly in certain environments where slow file system operations
810 used to be a bottleneck.
811
812 List of all performance improvements (for mypyc improvements there is a separate section below):
813
814 - Flip fixed-format cache to on by default (Ivan Levkivskyi, PR [20758](https://github.com/python/mypy/pull/20758))
815 - Enable `--sqlite-cache` by default (Shantanu, PR [21041](https://github.com/python/mypy/pull/21041))
816 - Save work on emitting ignored diagnostics (Shantanu, PR [20621](https://github.com/python/mypy/pull/20621))
817 - Skip logging and stats collection calls if they are no-ops (Jukka Lehtosalo, PR [20839](https://github.com/python/mypy/pull/20839))
818 - Speed up large incremental builds by optimizing internal state construction (Jukka Lehtosalo, PR [20838](https://github.com/python/mypy/pull/20838))
819 - Speed up suppressed dependencies options processing (Jukka Lehtosalo, PR [20806](https://github.com/python/mypy/pull/20806))
820 - Avoid path operations that need syscalls (Jukka Lehtosalo, PR [20802](https://github.com/python/mypy/pull/20802))
821 - Use faster algorithm for topological sort (Jukka Lehtosalo, PR [20790](https://github.com/python/mypy/pull/20790))
822 - Replace old topological sort (Jukka Lehtosalo, PR [20805](https://github.com/python/mypy/pull/20805))
823 - Fix quadratic performance in dependency graph loading for incremental builds (Jukka Lehtosalo, PR [20786](https://github.com/python/mypy/pull/20786))
824 - Micro-optimize transitive dependency hash calculation (Jukka Lehtosalo, PR [20798](https://github.com/python/mypy/pull/20798))
825 - Speed up options snapshot calculation (Jukka Lehtosalo, PR [20797](https://github.com/python/mypy/pull/20797))
826 - Micro-optimize read buffering, metastore `abspath`, path joining (Shantanu, PR [20810](https://github.com/python/mypy/pull/20810))
827 - Speed up type comparisons and hashing for literal types (Shantanu, PR [20423](https://github.com/python/mypy/pull/20423))
828 - Optimize overloaded signatures check (asce, PR [20378](https://github.com/python/mypy/pull/20378))
829 - Avoid unnecessary work when checking deferred functions (Ivan Levkivskyi, PR [20860](https://github.com/python/mypy/pull/20860))
830 - Improve `--allow-redefinition-new` performance for code with loops (Ivan Levkivskyi, PR [20862](https://github.com/python/mypy/pull/20862))
831 - Avoid `setattr`/`getattr` with fixed format cache (Ivan Levkivskyi, PR [20826](https://github.com/python/mypy/pull/20826))
832
833 ### Improvements to Allowing Redefinitions
834
835 Mypy now allows significantly more flexible variable redefinitions when using `--allow-redefinition-new`.
836 In particular, function parameters can now be redefined with a different type:
837
838 ```python
839 # mypy: allow-redefinition-new, local-partial-types
840
841 def process(items: list[str]) -> None:
842 # Reassign parameter to a completely different type.
843 # Without --allow-redefinition-new, this is a type error because
844 # list[list[str]] is not compatible with list[str].
845 items = [item.split() for item in items]
846 ...
847 ```
848
849 In mypy 2.0, we will update `--allow-redefinition` to mean `--allow-redefinition-new`.
850 This release adds `--allow-redefinition-old` as an alias of `--allow-redefinition`, which
851 can be used to continue using the old redefinition behavior in mypy 2.0 and later.
852
853 List of changes:
854
855 - Add `--allow-redefinition-old` as an alias of `--allow-redefinition` (Ivan Levkivskyi, PR [20764](https://github.com/python/mypy/pull/20764))
856 - Allow redefinitions for function arguments (Ivan Levkivskyi, PR [20853](https://github.com/python/mypy/pull/20853))
857 - Fix regression on redefinition in deferred loop (Ivan Levkivskyi, PR [20879](https://github.com/python/mypy/pull/20879))
858 - Fix loop convergence with redefinitions (Ivan Levkivskyi, PR [20865](https://github.com/python/mypy/pull/20865))
859 - Make sure new redefinition semantics only apply to inferred variables (Ivan Levkivskyi, PR [20909](https://github.com/python/mypy/pull/20909))
860 - Fix union edge case in function argument redefinition (Ivan Levkivskyi, PR [20908](https://github.com/python/mypy/pull/20908))
861 - Show an error when old and new redefinition are enabled in a file (Ivan Levkivskyi, PR [20920](https://github.com/python/mypy/pull/20920))
862 - `--allow-redefinition-new` is no longer experimental (Jukka Lehtosalo, PR [21110](https://github.com/python/mypy/pull/21110))
863 - Fix type inference for nested union types (Ivan Levkivskyi, PR [20912](https://github.com/python/mypy/pull/20912))
864 - Fix type inference regression for multiple variables in loops (Ivan Levkivskyi, PR [20892](https://github.com/python/mypy/pull/20892))
865 - Improve type inference for empty collections in conditional contexts (Ivan Levkivskyi, PR [20851](https://github.com/python/mypy/pull/20851))
866
867 ### Incremental Checking Improvements
868
869 This release includes multiple fixes to incremental type checking:
870
871 - Invalidate cache when `--enable-incomplete-feature` changes (kaushal trivedi, PR [20849](https://github.com/python/mypy/pull/20849))
872 - Add back support for `warn_unused_configs` (Ivan Levkivskyi, PR [20801](https://github.com/python/mypy/pull/20801))
873 - Recover from corrupted fixed-format cache meta file (Jukka Lehtosalo, PR [20780](https://github.com/python/mypy/pull/20780))
874 - Distinguish not found versus skipped modules (Ivan Levkivskyi, PR [20812](https://github.com/python/mypy/pull/20812))
875 - Fix undetected submodule deletion on warm run (Ivan Levkivskyi, PR [20784](https://github.com/python/mypy/pull/20784))
876 - Fix staleness on changed follow-imports options (Ivan Levkivskyi, PR [20773](https://github.com/python/mypy/pull/20773))
877 - Verify indirect dependencies reachable on incremental run (Ivan Levkivskyi, PR [20735](https://github.com/python/mypy/pull/20735))
878 - Fix indirect dependencies for protocols (Ivan Levkivskyi, PR [20752](https://github.com/python/mypy/pull/20752))
879 - Show error locations in other modules on warm runs (Ivan Levkivskyi, PR [20635](https://github.com/python/mypy/pull/20635))
880 - Don't read errors from cache on silent import (Sjoerd Job Postmus, PR [20509](https://github.com/python/mypy/pull/20509))
881 - More robust fix for re-export of `__all__` (Ivan Levkivskyi, PR [20487](https://github.com/python/mypy/pull/20487))
882
883 ### Fixes to Crashes
884
885 - Fix crash on partially typed namespace package (Ivan Levkivskyi, PR [20742](https://github.com/python/mypy/pull/20742))
886 - 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))
887 - Fix crash when missing format character (Shantanu, PR [20524](https://github.com/python/mypy/pull/20524))
888 - Fix crash when passing literal values as type arguments to variadic generics (Aaron Wieczorek, PR [20543](https://github.com/python/mypy/pull/20543))
889 - Fix crash on circular star import in incremental mode (Ivan Levkivskyi, PR [20511](https://github.com/python/mypy/pull/20511))
890 - Fix crash with tuple unpack inside TypeVar default (Marc Mueller, PR [20456](https://github.com/python/mypy/pull/20456))
891 - Fix crash on typevar with forward reference used in other module (Ivan Levkivskyi, PR [20334](https://github.com/python/mypy/pull/20334))
892 - Fix crash on star import of redefinition (Ivan Levkivskyi, PR [20333](https://github.com/python/mypy/pull/20333))
893 - Fix crash involving Unpack-ed `TypeVarTuple` (Shantanu, PR [20323](https://github.com/python/mypy/pull/20323))
894 - Fix crashes caused by type variable defaults in-place modifications (Stanislav Terliakov, PR [20139](https://github.com/python/mypy/pull/20139))
895 - Fix crash when calling `len()` with no arguments (Jukka Lehtosalo, PR [20774](https://github.com/python/mypy/pull/20774))
896 - Fix crash when checking `async for` inside nested comprehensions (A5rocks, PR [20540](https://github.com/python/mypy/pull/20540))
897 - Fix `ParamSpec` related crash (Stanislav Terliakov, PR [20119](https://github.com/python/mypy/pull/20119))
898
899 ### Mypyc: Faster Imports on macOS
900
901 Imports in native (compiled) modules that target other native modules that are compiled
902 together are now significantly faster on macOS, especially on the first run after a compiled
903 package has been installed. This also speeds up the first mypy run after installation/update
904 on macOS.
905
906 This was contributed by Jukka Lehtosalo (PR [21101](https://github.com/python/mypy/pull/21101)).
907
908 ### librt: Mypyc Standard Library
909
910 Mypyc now has a dedicated standard library, `librt`, to provide basic features that are optimized
911 for compiled code. They are faster than corresponding Python stdlib functionality. There is no
912 plan to replace the Python stdlib, though. We'll only include a carefully selected set of features
913 that help with common performance bottlenecks in compiled code.
914
915 Currently, we provide `librt.base64` that has optimized SIMD (Single Instruction, Multiple
916 Data) base64 encoding and decoding functions. In future mypyc releases we are planning to
917 add efficient data structures, string/bytes utilities, and more.
918
919 Use `python3 -m pip install librt` to make `librt` available to compiled modules. Compiled
920 modules don't require `librt` unless they explicitly import `librt`. If you install mypy, you
921 will also get a compatible version of `librt` as a dependency. We will keep `librt` backward
922 compatible, so you should always be able to update to a newer version of the library.
923
924 Related changes:
925
926 - Add minimal, experimental `librt.base64` module (Jukka Lehtosalo, PR [20226](https://github.com/python/mypy/pull/20226))
927 - Use faster base64 encode implementation in `librt.base64` (Jukka Lehtosalo, PR [20237](https://github.com/python/mypy/pull/20237))
928 - Add efficient `librt.base64.b64decode` (Jukka Lehtosalo, PR [20263](https://github.com/python/mypy/pull/20263))
929 - Enable SIMD for `librt.base64` on x86-64 (Jukka Lehtosalo, PR [20244](https://github.com/python/mypy/pull/20244))
930 - Add primitive for `librt.base64.b64decode` (Jukka Lehtosalo, PR [20272](https://github.com/python/mypy/pull/20272))
931 - Add `urlsafe_b64encode` and `urlsafe_b64decode` to `librt.base64` (Jukka Lehtosalo, PR [20274](https://github.com/python/mypy/pull/20274))
932 - Make `librt.base64` non-experimental (Ivan Levkivskyi, PR [20783](https://github.com/python/mypy/pull/20783))
933 - Support pyodide for Python 3.12 (Michael R. Crusoe, PR [20342](https://github.com/python/mypy/pull/20342))
934 - Support pyodide via the NEON intrinsics (Michael R. Crusoe, PR [20316](https://github.com/python/mypy/pull/20316))
935 - Fix `librt` compilation on platforms with OpenMP (Ivan Levkivskyi, PR [20583](https://github.com/python/mypy/pull/20583))
936 - Fix cross-compiling `librt` by enabling x86_64 optimizations with pragmas (James Le Cuirot, PR [20815](https://github.com/python/mypy/pull/20815))
937 - Use existing SIMD CPU dispatch by customizing build flags (Michael R. Crusoe, PR [20253](https://github.com/python/mypy/pull/20253))
938 - Document `librt` and `librt.base64` (Jukka Lehtosalo, PR [21114](https://github.com/python/mypy/pull/21114))
939
940 ### Mypyc: Acyclic Classes
941
942 Mypyc now supports defining acyclic native classes that don't participate in the tracing
943 garbage collection:
944
945 ```python
946 from mypy_extensions import mypyc_attr
947
948 @mypyc_attr(acyclic=True)
949 class Item:
950 def __init__(self, key: str, value: str) -> None:
951 self.key = key
952 self.value = value
953 ```
954
955 Allocating and freeing instances of acyclic classes is faster than regular native class
956 instances, and they use less memory, but if they participate in reference cycles, there
957 may be memory leaks.
958
959 This was contributed by Jukka Lehtosalo (PR [20795](https://github.com/python/mypy/pull/20795)).
960
961 ### Additional Mypyc Fixes and Improvements
962
963 - Fix range loop variable off-by-one after loop exit (Vaggelis Danias, PR [21098](https://github.com/python/mypy/pull/21098))
964 - Fix memory leak on property setter call (Piotr Sawicki, PR [21095](https://github.com/python/mypy/pull/21095))
965 - Fix `ClassVar` self-references in class bodies (Vaggelis Danias, PR [21011](https://github.com/python/mypy/pull/21011))
966 - Fix cross-module class attribute defaults causing KeyError (Vaggelis Danias, PR [21012](https://github.com/python/mypy/pull/21012))
967 - Fix shadow vtable misalignment for `@property` getters/setters (Vaggelis Danias, PR [21010](https://github.com/python/mypy/pull/21010))
968 - Fix lambda inside comprehension (Vaggelis Danias, PR [21009](https://github.com/python/mypy/pull/21009))
969 - Use cached ASCII characters in `CPyStr_GetItem` (Vaggelis Danias, PR [21035](https://github.com/python/mypy/pull/21035))
970 - Speed up int to bytes conversion (Piotr Sawicki, PR [21036](https://github.com/python/mypy/pull/21036))
971 - Add missing primitive documentation (Jukka Lehtosalo, PR [21037](https://github.com/python/mypy/pull/21037))
972 - Fix undefined behavior in generated C (Jukka Lehtosalo, PR [21094](https://github.com/python/mypy/pull/21094))
973 - Fix vtable construction for deep trait inheritance (Vaggelis Danias, PR [20917](https://github.com/python/mypy/pull/20917))
974 - Fix `__init_subclass__` running before `ClassVar` instantiations (Vaggelis Danias, PR [20916](https://github.com/python/mypy/pull/20916))
975 - Add support for `str.lower()` and `str.upper()` (Vaggelis Danias, PR [20948](https://github.com/python/mypy/pull/20948))
976 - Add `str.isdigit()` primitive (Vaggelis Danias, PR [20893](https://github.com/python/mypy/pull/20893))
977 - Add `str.isalnum()` primitive (Vaggelis Danias, PR [20852](https://github.com/python/mypy/pull/20852))
978 - Add `str.isspace()` primitive (Vaggelis Danias, PR [20842](https://github.com/python/mypy/pull/20842))
979 - Reduce memory usage when compiling large files (Vaggelis Danias, PR [20897](https://github.com/python/mypy/pull/20897))
980 - Generate error if using Python 3.14 t-string (Jukka Lehtosalo, PR [20899](https://github.com/python/mypy/pull/20899))
981 - Fix undefined attribute in nested coroutines (Piotr Sawicki, PR [20654](https://github.com/python/mypy/pull/20654))
982 - Do not emit tracebacks with negative line numbers (Piotr Sawicki, PR [20641](https://github.com/python/mypy/pull/20641))
983 - Fix crash on multiple nested decorated functions with same name (Piotr Sawicki, PR [20666](https://github.com/python/mypy/pull/20666))
984 - Fix `Final` load in unreachable branches (BobTheBuidler, PR [20617](https://github.com/python/mypy/pull/20617))
985 - Add new primitive for `int.to_bytes` (BobTheBuidler, PR [19674](https://github.com/python/mypy/pull/19674))
986 - Support constant folding in f-string to `str` conversion (BobTheBuidler, PR [19970](https://github.com/python/mypy/pull/19970))
987 - Implement `bytes.endswith` (esarp, PR [20447](https://github.com/python/mypy/pull/20447))
988 - Fix coercion from short tagged int to fixed-width int (Jukka Lehtosalo, PR [20587](https://github.com/python/mypy/pull/20587))
989 - Fix generation of function wrappers for decorated functions (Piotr Sawicki, PR [20584](https://github.com/python/mypy/pull/20584))
990 - Generate function wrappers for each callable class instance (Piotr Sawicki, PR [20575](https://github.com/python/mypy/pull/20575))
991 - Speed up `ord(str[n])` by inlining (Jukka Lehtosalo, PR [20578](https://github.com/python/mypy/pull/20578))
992 - Add inline primitives for `bytes.__getitem__` (Jukka Lehtosalo, PR [20552](https://github.com/python/mypy/pull/20552))
993 - Add primitive type for `bytearray` (Jukka Lehtosalo, PR [20551](https://github.com/python/mypy/pull/20551))
994 - Fix and clean up `bytearray` support in primitives (Jukka Lehtosalo, PR [20550](https://github.com/python/mypy/pull/20550))
995 - Enable `--strict-bytes` by default in mypyc (and require it) (Jukka Lehtosalo, PR [20548](https://github.com/python/mypy/pull/20548))
996 - Fix exception reraising when awaiting a future (Piotr Sawicki, PR [20547](https://github.com/python/mypy/pull/20547))
997 - Add inline primitives for BytesBuilder get item and set item (Jukka Lehtosalo, PR [20546](https://github.com/python/mypy/pull/20546))
998 - Optimize loops over `enumerate`, `map`, `zip`, `range`, and other builtins with known lengths (BobTheBuidler, PR [19927](https://github.com/python/mypy/pull/19927))
999 - Raise `ValueError` if int too big for native int type (Jukka Lehtosalo, PR [20385](https://github.com/python/mypy/pull/20385))
1000 - Fix generator regression with empty tuple (BobTheBuidler, PR [20371](https://github.com/python/mypy/pull/20371))
1001 - Improve constant folding for `len()` of string literals and Final values (BobTheBuidler, PR [20074](https://github.com/python/mypy/pull/20074))
1002 - Add primitive for `bytes.startswith` (esarp, PR [20387](https://github.com/python/mypy/pull/20387))
1003 - Fix calling async methods through vectorcall (Piotr Sawicki, PR [20393](https://github.com/python/mypy/pull/20393))
1004 - Extend loop optimization to use constant folding for determining sequence lengths (BobTheBuidler, PR [19930](https://github.com/python/mypy/pull/19930))
1005 - Wrap async functions with function-like type (Piotr Sawicki, PR [20260](https://github.com/python/mypy/pull/20260))
1006 - Add a primitive for bytes `translate` method (Jukka Lehtosalo, PR [20305](https://github.com/python/mypy/pull/20305))
1007 - Add primitives for bytes and str multiply (Jukka Lehtosalo, PR [20303](https://github.com/python/mypy/pull/20303))
1008 - Match int arguments to primitives with native int parameters (Jukka Lehtosalo, PR [20299](https://github.com/python/mypy/pull/20299))
1009 - Allow disabling extra flags with `MYPYC_NO_EXTRA_FLAGS` environment variable (James Hilliard, PR [20507](https://github.com/python/mypy/pull/20507))
1010 - Fix unsupported imports for type annotations (Lukas Geiger, PR [20390](https://github.com/python/mypy/pull/20390))
1011 - Fix unaligned memory access in librt internal helper function (Gregor Riepl, PR [20474](https://github.com/python/mypy/pull/20474))
1012 - Fix build issue (James Hilliard, PR [20510](https://github.com/python/mypy/pull/20510))
1013
1014 ### Removed Flags `--force-uppercase-builtins` and `--force-union-syntax`
1015
1016 The `--force-uppercase-builtins` flag was deprecated and has been a no-op since mypy 1.17.0.
1017 Since mypy has dropped support for Python 3.9, the `--force-union-syntax` flag is no longer
1018 necessary.
1019
1020 Contributed by Marc Mueller (PR [20410](https://github.com/python/mypy/pull/20410))
1021 and (PR [20405](https://github.com/python/mypy/pull/20405)).
1022
1023 ### Stubgen Improvements
1024
1025 - Fix mis-parsing of double colon ("::") (Jeremy Nimmer, PR [20285](https://github.com/python/mypy/pull/20285))
1026
1027 ### Stubtest Improvements
1028
1029 - Attempt to resolve decorators from their type (Shantanu, PR [20867](https://github.com/python/mypy/pull/20867))
1030 - Fix crash on instances with redefined `__class__` (sobolevn, PR [20926](https://github.com/python/mypy/pull/20926))
1031 - Improve checking of positional-only parameters in dunder methods (Brian Schubert, PR [19593](https://github.com/python/mypy/pull/19593))
1032 - Check `Final` variables with literal values against runtime (Vikash Kumar, PR [20858](https://github.com/python/mypy/pull/20858))
1033 - Fix duplicate errors with invalid line numbers (Joren Hammudoglu, PR [20417](https://github.com/python/mypy/pull/20417))
1034 - Ignore `__conditional_annotations__` (Joren Hammudoglu, PR [20392](https://github.com/python/mypy/pull/20392))
1035 - Transparent `@type_check_only` types (Joren Hammudoglu, PR [20352](https://github.com/python/mypy/pull/20352))
1036 - Check runtime availability of private types not marked `@type_check_only` (Brian Schubert, PR [19574](https://github.com/python/mypy/pull/19574))
1037
1038 ### Documentation Updates
1039
1040 - Document semantics of function argument redefinition (Ivan Levkivskyi, PR [20910](https://github.com/python/mypy/pull/20910))
1041 - Update common issues: document how the type ignore must come first (wyattscarpenter, PR [20886](https://github.com/python/mypy/pull/20886))
1042 - Update "type inference and annotations" (Kai (Kazuya Ito), PR [20619](https://github.com/python/mypy/pull/20619))
1043 - Document unreachability handling of `return NotImplemented` (wyattscarpenter, PR [20561](https://github.com/python/mypy/pull/20561))
1044
1045 ### Changes to Messages
1046
1047 - Simpler/cleaner `reveal_type()` (Ivan Levkivskyi, PR [20929](https://github.com/python/mypy/pull/20929))
1048 - Use "parameter" instead of "argument" in overload error (Kai (Kazuya Ito), PR [20994](https://github.com/python/mypy/pull/20994))
1049 - Use "parameter" instead of "argument" in unpacking error (Kai (Kazuya Ito), PR [20683](https://github.com/python/mypy/pull/20683))
1050 - Use "type arguments" instead of "type parameters" for bare generics (Kai (Kazuya Ito), PR [20494](https://github.com/python/mypy/pull/20494))
1051 - Update "arguments" to "parameters" (Kai (Kazuya Ito), PR [20711](https://github.com/python/mypy/pull/20711))
1052 - Use "parameter" instead of "argument" in default value error messages (Kai (Kazuya Ito), PR [20964](https://github.com/python/mypy/pull/20964))
1053 - Update error message for parameter overlap in TypedDict (Kai (Kazuya Ito), PR [20956](https://github.com/python/mypy/pull/20956))
1054 - Correct "Duplicate argument" error messages (Kai (Kazuya Ito), PR [20957](https://github.com/python/mypy/pull/20957))
1055 - Use standard formatting for note on unexpected keyword (Ivan Levkivskyi, PR [20808](https://github.com/python/mypy/pull/20808))
1056 - Fix edge cases in pretty formatting (Ivan Levkivskyi, PR [20809](https://github.com/python/mypy/pull/20809))
1057 - Add function definition notes for missing named argument errors (Kevin Kannammalil, PR [20794](https://github.com/python/mypy/pull/20794))
1058 - Make overloaded constructors consistent in error messages (Ivan Levkivskyi, PR [20483](https://github.com/python/mypy/pull/20483))
1059 - Improve error message for invalid Python package (Shantanu, PR [20482](https://github.com/python/mypy/pull/20482))
1060 - Emit end line/column in JSON format for span tracking (Adam Turner, PR [20734](https://github.com/python/mypy/pull/20734))
1061 - Wrap callable in union syntax (Marc Mueller, PR [20406](https://github.com/python/mypy/pull/20406))
1062
1063 ### Other Notable Fixes and Improvements
1064
1065 - Unify handling of self attributes in daemon (Ivan Levkivskyi, PR [21025](https://github.com/python/mypy/pull/21025))
1066 - Improve support for `hasattr()` (Ivan Levkivskyi, PR [20914](https://github.com/python/mypy/pull/20914))
1067 - Warn when `@disjoint_base` is used on protocols or TypedDicts (Brian Schubert, PR [21029](https://github.com/python/mypy/pull/21029))
1068 - Model tuple type aliases better (Shantanu, PR [20967](https://github.com/python/mypy/pull/20967))
1069 - Fix incorrect type inference for container literals inside loops (Ivan Levkivskyi, PR [20875](https://github.com/python/mypy/pull/20875))
1070 - Fix edge case in type comparison for type variables with narrowed bounds (Ivan Levkivskyi, PR [20874](https://github.com/python/mypy/pull/20874))
1071 - Prohibit access via class for instance-only attributes (Ivan Levkivskyi, PR [20855](https://github.com/python/mypy/pull/20855))
1072 - Update JSON export tool to support binary meta cache files (Jukka Lehtosalo, PR [20096](https://github.com/python/mypy/pull/20096))
1073 - Better handling for uncaught top-level exceptions (Ivan Levkivskyi, PR [20749](https://github.com/python/mypy/pull/20749))
1074 - Attrs field level `kw_only=False` overrides `kw_only=True` at class level (getzze, PR [20949](https://github.com/python/mypy/pull/20949))
1075 - Fix `__slots__` issue with deferred base (Shantanu, PR [20573](https://github.com/python/mypy/pull/20573))
1076 - Fix deferral logic for special types (Ivan Levkivskyi, PR [20678](https://github.com/python/mypy/pull/20678))
1077 - Fix false negatives in walrus versus inference fallback logic (Ivan Levkivskyi, PR [20622](https://github.com/python/mypy/pull/20622))
1078 - Fix enum value inference with user-defined data type mixin (E. M. Bray, PR [16320](https://github.com/python/mypy/pull/16320))
1079 - Fix incorrect classification of class attributes versus enum members (Stanislav Terliakov, PR [19687](https://github.com/python/mypy/pull/19687))
1080 - Improve type inference when finding common types for callable types (Shantanu, PR [18406](https://github.com/python/mypy/pull/18406))
1081 - Remove special case for Union type context (Shantanu, PR [20610](https://github.com/python/mypy/pull/20610))
1082 - Evaluate argument expressions in runtime evaluation order (Shantanu, PR [20491](https://github.com/python/mypy/pull/20491))
1083 - Allow empty type applications for `ParamSpec` (A5rocks, PR [20572](https://github.com/python/mypy/pull/20572))
1084 - Make `X[()]` count as a type application (A5rocks, PR [20568](https://github.com/python/mypy/pull/20568))
1085 - Accept `value` as keyword argument in `TypeAliasType` (Ali Hamdan, PR [20556](https://github.com/python/mypy/pull/20556))
1086 - Avoid treating `pass` and `...` as no-op for reachability (Shantanu, PR [20488](https://github.com/python/mypy/pull/20488))
1087 - Fix specialization leak in generic `TypedDict.update()` (Aaron Wieczorek, PR [20517](https://github.com/python/mypy/pull/20517))
1088 - Fix false positive redundant expression warnings with `isinstance()` on `Any | Protocol` unions (Randolf Scholz, PR [20450](https://github.com/python/mypy/pull/20450))
1089 - Fix type checking of class-scope imports accessed via `self` or `cls` (bzoracler, PR [20480](https://github.com/python/mypy/pull/20480))
1090 - Prevent synthetic intersections from leaking to module public interfaces (bzoracler, PR [20459](https://github.com/python/mypy/pull/20459))
1091 - Fix package build failure when the compiler types are not defined (Steven Pitman, PR [20429](https://github.com/python/mypy/pull/20429))
1092 - Fix `--strict-equality` for iteratively visited code (Christoph Tyralla, PR [19635](https://github.com/python/mypy/pull/19635))
1093 - Allow literals as kwargs dict keys (Shantanu, PR [20416](https://github.com/python/mypy/pull/20416))
1094 - Error for invalid varargs and varkwargs to `Any` call (Shantanu, PR [20324](https://github.com/python/mypy/pull/20324))
1095 - Fix type inference for binary operators with tuple subclasses (Randolf Scholz, PR [19046](https://github.com/python/mypy/pull/19046))
1096 - Improve type inference for ternary expressions with literals and collections (Randolf Scholz, PR [19563](https://github.com/python/mypy/pull/19563))
1097 - Do not treat match value patterns as `isinstance` checks (Stanislav Terliakov, PR [20146](https://github.com/python/mypy/pull/20146))
1098 - Fix noncommutative joins with bounded TypeVars (Shantanu, PR [20345](https://github.com/python/mypy/pull/20345))
1099 - Fix error location reporting for `**rest` patterns in match statements (Marc Mueller, PR [20407](https://github.com/python/mypy/pull/20407))
1100 - Fix matching against union of tuples (Saul Shanabrook, PR [19600](https://github.com/python/mypy/pull/19600))
1101 - Allow `types.NoneType` in match cases (A5rocks, PR [20383](https://github.com/python/mypy/pull/20383))
1102 - Treat `Literal["xyz"]` as iterable (Shantanu, PR [20347](https://github.com/python/mypy/pull/20347))
1103 - Treat functions that return `None` as returning `None` (Shantanu, PR [20350](https://github.com/python/mypy/pull/20350))
1104 - Fix str unpack type propagation, use dedicated error code (Shantanu, PR [20325](https://github.com/python/mypy/pull/20325))
1105 - Unpack unions inside tuples in except handlers (asce, PR [17762](https://github.com/python/mypy/pull/17762))
1106 - Ignore empty error codes from `type: ignore` (Donghoon Nam, PR [20052](https://github.com/python/mypy/pull/20052))
1107 - Make `NoneType` annotation error use a new error code (wyattscarpenter, PR [20222](https://github.com/python/mypy/pull/20222))
1108 - Fail with an explicit error on PyPy (Ivan Levkivskyi, PR [20384](https://github.com/python/mypy/pull/20384))
1109 - Add hidden `--overwrite-union-syntax` option (Marc Mueller, PR [20332](https://github.com/python/mypy/pull/20332))
1110 - Fix `possibly-undefined` false-positive with nesting (grayjk, PR [20276](https://github.com/python/mypy/pull/20276))
1111 - Fix spurious `possibly-undefined` errors in for-else with `break` (Łukasz Langa, PR [19696](https://github.com/python/mypy/pull/19696))
1112 - Avoid false `possibly-undefined` errors due to omitted unrequired else statements (Christoph Tyralla, PR [20149](https://github.com/python/mypy/pull/20149))
1113 - Fix generator expression behavior for `reveal_type` (michaelm-openai, PR [20594](https://github.com/python/mypy/pull/20594))
1114 - Fix error on instance property and init-only variable with the same name in a dataclass (Roberto Fernández Iglesias, PR [17219](https://github.com/python/mypy/pull/17219))
1115 - Improve error messages when `__module__` or `__qualname__` are used as type annotations (A5rocks, PR [20288](https://github.com/python/mypy/pull/20288))
1116 - Check for multiple type var tuples for PEP 695 (A5rocks, PR [20289](https://github.com/python/mypy/pull/20289))
1117 - Improve interaction between `--local-partial-types` and hashability (Shantanu, PR [20719](https://github.com/python/mypy/pull/20719))
1118 - Stop looking for `.gitignore` at top level of working tree (Colin Watson, PR [20775](https://github.com/python/mypy/pull/20775))
1119 - Try fixing Cygwin build (Ivan Levkivskyi, PR [20830](https://github.com/python/mypy/pull/20830))
1120 - Fix daemon dependencies in `diff-cache.py` tool (Jukka Lehtosalo, PR [20837](https://github.com/python/mypy/pull/20837))
1121 - Support fixed-format cache in `diff-cache.py` tool (Jukka Lehtosalo, PR [20827](https://github.com/python/mypy/pull/20827))
1122 - Update `convert-cache.py` tool to work with fixed-format caches (Ivan Levkivskyi, PR [20761](https://github.com/python/mypy/pull/20761))
1123 - Write errors to a separate cache file (Ivan Levkivskyi, PR [21022](https://github.com/python/mypy/pull/21022))
1124 - Write ignored lines to cache meta (Ivan Levkivskyi, PR [20747](https://github.com/python/mypy/pull/20747))
1125 - Serialize raw errors in cache metas (Ivan Levkivskyi, PR [20372](https://github.com/python/mypy/pull/20372))
1126 - Include `misc/{diff-cache,apply-cache-diff}.py` in sdist (Michael R. Crusoe, PR [21096](https://github.com/python/mypy/pull/21096))
1127
1128 ### Typeshed updates
1129
1130 Please see [git log](https://github.com/python/typeshed/commits/main?after=f8f0794d0fe249c06dc9f31a004d85be6cca6ced+0&branch=main&path=stdlib) for full list of standard library typeshed stub changes.
1131
1132 ### Mypy 1.20.1
1133
1134 - Always disable sync in SQLite cache (Ivan Levkivskyi, PR [21184](https://github.com/python/mypy/pull/21184))
1135 - Temporarily skip few base64 tests (Ivan Levkivskyi, PR [21193](https://github.com/python/mypy/pull/21193))
1136 - Revert `dict.__or__` typeshed change (Ivan Levkivskyi, PR [21186](https://github.com/python/mypy/pull/21186))
1137 - Fix narrowing for match case with variadic tuples (Shantanu, PR [21192](https://github.com/python/mypy/pull/21192))
1138 - Avoid narrowing `type[T]` in type calls (Shantanu, PR [21174](https://github.com/python/mypy/pull/21174))
1139 - Fix regression for catching empty tuple in except (Shantanu, PR [21153](https://github.com/python/mypy/pull/21153))
1140 - Fix reachability for frozenset and dict view narrowing (Shantanu, PR [21151](https://github.com/python/mypy/pull/21151))
1141 - Fix narrowing with chained comparison (Shantanu, PR [21150](https://github.com/python/mypy/pull/21150))
1142 - Avoid narrowing to unreachable at module level (Shantanu, PR [21144](https://github.com/python/mypy/pull/21144))
1143 - Allow dangerous identity comparisons to `Any` typed variables (Shantanu, PR [21142](https://github.com/python/mypy/pull/21142))
1144 - `--warn-unused-config` should not be a strict flag (Ivan Levkivskyi, PR [21139](https://github.com/python/mypy/pull/21139))
1145
1146 ### Mypy 1.20.2
1147
1148 - Use WAL with SQLite cache and fix close (Shantanu, PR [21154](https://github.com/python/mypy/pull/21154))
1149 - Adjust SQLite journal mode (Ivan Levkivskyi, PR [21217](https://github.com/python/mypy/pull/21217))
1150 - Correctly aggregate narrowing information on parent expressions (Shantanu, PR [21206](https://github.com/python/mypy/pull/21206))
1151 - Fix regression related to generic callables (Shantanu, PR [21208](https://github.com/python/mypy/pull/21208))
1152 - Fix regression by avoiding widening types in some contexts (Shantanu, PR [21242](https://github.com/python/mypy/pull/21242))
1153 - Fix slicing in non-strict optional mode (Shantanu, PR [21282](https://github.com/python/mypy/pull/21282))
1154 - mypyc: Fix match statement semantics for "or" pattern (Shantanu, PR [21156](https://github.com/python/mypy/pull/21156))
1155 - mypyc: Fix issue with module dunder attributes (Piotr Sawicki, PR [21275](https://github.com/python/mypy/pull/21275))
1156 - Initial support for Python 3.15.0a8 (Marc Mueller, PR [21255](https://github.com/python/mypy/pull/21255))
1157
1158 ### Acknowledgements
1159
1160 Thanks to all mypy contributors who contributed to this release:
1161 - A5rocks
1162 - Aaron Wieczorek
1163 - Adam Turner
1164 - Ali Hamdan
1165 - asce
1166 - BobTheBuidler
1167 - Brent Westbrook
1168 - Brian Schubert
1169 - bzoracler
1170 - Chris Burroughs
1171 - Christoph Tyralla
1172 - Colin Watson
1173 - Donghoon Nam
1174 - E. M. Bray
1175 - Emma Smith
1176 - Ethan Sarp
1177 - George Ogden
1178 - getzze
1179 - grayjk
1180 - Gregor Riepl
1181 - Ivan Levkivskyi
1182 - James Hilliard
1183 - James Le Cuirot
1184 - Jeremy Nimmer
1185 - Joren Hammudoglu
1186 - Kai (Kazuya Ito)
1187 - kaushal trivedi
1188 - Kevin Kannammalil
1189 - Lukas Geiger
1190 - Łukasz Langa
1191 - Marc Mueller
1192 - Michael R. Crusoe
1193 - michaelm-openai
1194 - Neil Schemenauer
1195 - Piotr Sawicki
1196 - Randolf Scholz
1197 - Roberto Fernández Iglesias
1198 - Saul Shanabrook
1199 - Shantanu Jain
1200 - Sjoerd Job Postmus
1201 - sobolevn
1202 - Stanislav Terliakov
1203 - Steven Pitman
1204 - Vaggelis Danias
1205 - Vikash Kumar
1206 - wyattscarpenter
1207
1208 I’d also like to thank my employer, Dropbox, for supporting mypy development.
1209
1210 ## Mypy 1.19
1211
1212 We’ve just uploaded mypy 1.19.0 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).
1213 Mypy is a static type checker for Python. This release includes new features, performance
1214 improvements and bug fixes. You can install it as follows:
1215
1216 python3 -m pip install -U mypy
1217
1218 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
1219
1220 ### Python 3.9 Support Ending Soon
1221
1222 This is the last mypy feature release that supports Python 3.9, which reached
1223 end of life in October 2025.
1224
1225 ### Performance Improvements
1226 - Switch to a more dynamic SCC processing logic (Ivan Levkivskyi, PR [20053](https://github.com/python/mypy/pull/20053))
1227 - Speed up type aliases (Ivan Levkivskyi, PR [19810](https://github.com/python/mypy/pull/19810))
1228
1229 ### Fixed‑Format Cache Improvements
1230
1231 Mypy uses a cache by default to speed up incremental runs by reusing partial results
1232 from earlier runs. Mypy 1.18 added a new binary fixed-format cache representation as
1233 an experimental feature. The feature is no longer experimental, and we are planning
1234 to enable it by default in a future mypy release (possibly 1.20), since it's faster
1235 and uses less space than the original, JSON-based cache format. Use
1236 `--fixed-format-cache` to enable the fixed-format cache.
1237
1238 Mypy now has an extra dependency on the `librt` PyPI package, as it's needed for
1239 cache serialization and deserialization.
1240
1241 Mypy ships with a tool to convert fixed-format cache files to the old JSON format.
1242 Example of how to use this:
1243 ```
1244 $ python -m mypy.exportjson .mypy_cache/.../my_module.data.ff
1245 ```
1246
1247 This way existing use cases that parse JSON cache files can be supported when using
1248 the new format, though an extra conversion step is needed.
1249
1250 This release includes these improvements:
1251
1252 - Force-discard cache if cache format changed (Ivan Levkivskyi, PR [20152](https://github.com/python/mypy/pull/20152))
1253 - Add tool to convert binary cache files to JSON (Jukka Lehtosalo, PR [20071](https://github.com/python/mypy/pull/20071))
1254 - Use more efficient serialization format for long integers in cache files (Jukka Lehtosalo, PR [20151](https://github.com/python/mypy/pull/20151))
1255 - More robust packing of floats in fixed-format cache (Ivan Levkivskyi, PR [20150](https://github.com/python/mypy/pull/20150))
1256 - Use self-descriptive cache with type tags (Ivan Levkivskyi, PR [20137](https://github.com/python/mypy/pull/20137))
1257 - Use fixed format for cache metas (Ivan Levkivskyi, PR [20088](https://github.com/python/mypy/pull/20088))
1258 - Make metas more compact; fix indirect suppression (Ivan Levkivskyi, PR [20075](https://github.com/python/mypy/pull/20075))
1259 - Use dedicated tags for most common cached instances (Ivan Levkivskyi, PR [19762](https://github.com/python/mypy/pull/19762))
1260
1261 ### PEP 747: Annotating Type Forms
1262
1263 Mypy now recognizes `TypeForm[T]` as a type and implements
1264 [PEP 747](https://peps.python.org/pep-0747/). The feature is still experimental,
1265 and it's disabled by default. Use `--enable-incomplete-feature=TypeForm` to
1266 enable type forms. A type form object captures the type information provided by a
1267 runtime type expression. Example:
1268
1269 ```python
1270 from typing_extensions import TypeForm
1271
1272 def trycast[T](typx: TypeForm[T], value: object) -> T | None: ...
1273
1274 def example(o: object) -> None:
1275 # 'int | str' below is an expression that represents a type.
1276 # Unlike type[T], TypeForm[T] can be used with all kinds of types,
1277 # including union types.
1278 x = trycast(int | str, o)
1279 if x is not None:
1280 # Type of 'x' is 'int | str' here
1281 ...
1282 ```
1283
1284 This feature was contributed by David Foster (PR [19596](https://github.com/python/mypy/pull/19596)).
1285
1286 ### Fixes to Crashes
1287 - Do not push partial types to the binder (Stanislav Terliakov, PR [20202](https://github.com/python/mypy/pull/20202))
1288 - Fix crash on recursive tuple with Hashable (Ivan Levkivskyi, PR [20232](https://github.com/python/mypy/pull/20232))
1289 - Fix crash related to decorated functions (Stanislav Terliakov, PR [20203](https://github.com/python/mypy/pull/20203))
1290 - Do not abort constructing TypeAlias if only type parameters hold us back (Stanislav Terliakov, PR [20162](https://github.com/python/mypy/pull/20162))
1291 - Use the fallback for `ModuleSpec` early if it can never be resolved (Stanislav Terliakov, PR [20167](https://github.com/python/mypy/pull/20167))
1292 - Do not store deferred NamedTuple fields as redefinitions (Stanislav Terliakov, PR [20147](https://github.com/python/mypy/pull/20147))
1293 - Discard partial types remaining after inference failure (Stanislav Terliakov, PR [20126](https://github.com/python/mypy/pull/20126))
1294 - Fix an infinite recursion bug (Stanislav Terliakov, PR [20127](https://github.com/python/mypy/pull/20127))
1295 - Fix IsADirectoryError for namespace packages when using --linecoverage-report (wyattscarpenter, PR [20109](https://github.com/python/mypy/pull/20109))
1296 - Fix an internal error when creating cobertura output for namespace package (wyattscarpenter, PR [20112](https://github.com/python/mypy/pull/20112))
1297 - Allow type parameters reusing the name missing from current module (Stanislav Terliakov, PR [20081](https://github.com/python/mypy/pull/20081))
1298 - Prevent TypeGuardedType leak from narrowing declared type as part of type variable bound (Stanislav Terliakov, PR [20046](https://github.com/python/mypy/pull/20046))
1299 - Fix crash on invalid unpack in base class (Ivan Levkivskyi, PR [19962](https://github.com/python/mypy/pull/19962))
1300 - Traverse ParamSpec prefix where we should (Ivan Levkivskyi, PR [19800](https://github.com/python/mypy/pull/19800))
1301 - Fix daemon crash related to imports (Ivan Levkivskyi, PR [20271](https://github.com/python/mypy/pull/20271))
1302
1303 ### Mypyc: Support for `__getattr__`, `__setattr__`, and `__delattr__`
1304
1305 Mypyc now has partial support for `__getattr__`, `__setattr__` and
1306 `__delattr__` methods in native classes.
1307
1308 Note that native attributes are not stored using `__dict__`. Setting attributes
1309 directly while bypassing `__setattr__` is possible by using
1310 `super().__setattr__(...)` or `object.__setattr__(...)`, but not via `__dict__`.
1311
1312 Example:
1313 ```python
1314 class Demo:
1315 _data: dict[str, str]
1316
1317 def __init__(self) -> None:
1318 # Initialize data dict without calling our __setattr__
1319 super().__setattr__("_data", {})
1320
1321 def __setattr__(self, name: str, value: str) -> None:
1322 print(f"Setting {name} = {value!r}")
1323
1324 if name == "_data":
1325 raise AttributeError("'_data' cannot be set")
1326
1327 self._data[name] = value
1328
1329 def __getattr__(self, name: str) -> str:
1330 print(f"Getting {name}")
1331
1332 try:
1333 return self._data[name]
1334 except KeyError:
1335 raise AttributeError(name)
1336
1337 d = Demo()
1338 d.x = "hello"
1339 d.y = "world"
1340
1341 print(d.x)
1342 print(d.y)
1343 ```
1344
1345 Related PRs:
1346 - Generate `__setattr__` wrapper (Piotr Sawicki, PR [19937](https://github.com/python/mypy/pull/19937))
1347 - Generate `__getattr__` wrapper (Piotr Sawicki, PR [19909](https://github.com/python/mypy/pull/19909))
1348 - Support deleting attributes in `__setattr__` wrapper (Piotr Sawicki, PR [19997](https://github.com/python/mypy/pull/19997))
1349
1350 ### Miscellaneous Mypyc Improvements
1351 - Fix `__new__` in native classes with inheritance (Piotr Sawicki, PR [20302](https://github.com/python/mypy/pull/20302))
1352 - Fix crash on `super` in generator (Ivan Levkivskyi, PR [20291](https://github.com/python/mypy/pull/20291))
1353 - Fix calling base class async method using `super()` (Jukka Lehtosalo, PR [20254](https://github.com/python/mypy/pull/20254))
1354 - Fix async or generator methods in traits (Jukka Lehtosalo, PR [20246](https://github.com/python/mypy/pull/20246))
1355 - Optimize equality check with string literals (BobTheBuidler, PR [19883](https://github.com/python/mypy/pull/19883))
1356 - Fix inheritance of async defs (Jukka Lehtosalo, PR [20044](https://github.com/python/mypy/pull/20044))
1357 - Reject invalid `mypyc_attr` args (BobTheBuidler, PR [19963](https://github.com/python/mypy/pull/19963))
1358 - Optimize `isinstance` with tuple of primitive types (BobTheBuidler, PR [19949](https://github.com/python/mypy/pull/19949))
1359 - Optimize away first index check in for loops if length > 1 (BobTheBuidler, PR [19933](https://github.com/python/mypy/pull/19933))
1360 - Fix broken exception/cancellation handling in async def (Jukka Lehtosalo, PR [19951](https://github.com/python/mypy/pull/19951))
1361 - Transform `object.__new__` inside `__new__` (Piotr Sawicki, PR [19866](https://github.com/python/mypy/pull/19866))
1362 - Fix crash with NewType and other non-class types in incremental builds (Jukka Lehtosalo, PR [19837](https://github.com/python/mypy/pull/19837))
1363 - Optimize container creation from expressions with length known at compile time (BobTheBuidler, PR [19503](https://github.com/python/mypy/pull/19503))
1364 - Allow per-class free list to be used with inheritance (Jukka Lehtosalo, PR [19790](https://github.com/python/mypy/pull/19790))
1365 - Fix object finalization (Marc Mueller, PR [19749](https://github.com/python/mypy/pull/19749))
1366 - Allow defining a single-item free "list" for a native class (Jukka Lehtosalo, PR [19785](https://github.com/python/mypy/pull/19785))
1367 - Speed up unary "not" (Jukka Lehtosalo, PR [19774](https://github.com/python/mypy/pull/19774))
1368
1369 ### Stubtest Improvements
1370 - Check `_value_` for ellipsis-valued stub enum members (Stanislav Terliakov, PR [19760](https://github.com/python/mypy/pull/19760))
1371 - Include function name in overload assertion messages (Joren Hammudoglu, PR [20063](https://github.com/python/mypy/pull/20063))
1372 - Fix special case in analyzing function signature (iap, PR [19822](https://github.com/python/mypy/pull/19822))
1373 - Improve `allowlist` docs with better example (sobolevn, PR [20007](https://github.com/python/mypy/pull/20007))
1374
1375 ### Documentation Updates
1376 - Update duck type compatibility: mention strict-bytes and mypy 2.0 (wyattscarpenter, PR [20121](https://github.com/python/mypy/pull/20121))
1377 - Document `--enable-incomplete-feature TypeForm` (wyattscarpenter, PR [20173](https://github.com/python/mypy/pull/20173))
1378 - Change the inline TypedDict example (wyattscarpenter, PR [20172](https://github.com/python/mypy/pull/20172))
1379 - Replace `List` with built‑in `list` (PEP 585) (Thiago J. Barbalho, PR [20000](https://github.com/python/mypy/pull/20000))
1380 - Improve junit documentation (wyattscarpenter, PR [19867](https://github.com/python/mypy/pull/19867))
1381
1382 ### Other Notable Fixes and Improvements
1383 - Fix annotated with function as type keyword list parameter (KarelKenens, PR [20094](https://github.com/python/mypy/pull/20094))
1384 - Fix errors for raise NotImplemented (Shantanu, PR [20168](https://github.com/python/mypy/pull/20168))
1385 - Don't let help formatter line-wrap URLs (Frank Dana, PR [19825](https://github.com/python/mypy/pull/19825))
1386 - Do not cache fast container types inside lambdas (Stanislav Terliakov, PR [20166](https://github.com/python/mypy/pull/20166))
1387 - Respect force-union-syntax flag in error hint (Marc Mueller, PR [20165](https://github.com/python/mypy/pull/20165))
1388 - Fix type checking of dict type aliases (Shantanu, PR [20170](https://github.com/python/mypy/pull/20170))
1389 - Use pretty callable formatting more often for callable expressions (Theodore Ando, PR [20128](https://github.com/python/mypy/pull/20128))
1390 - Use dummy concrete type instead of `Any` when checking protocol variance (bzoracler, PR [20110](https://github.com/python/mypy/pull/20110))
1391 - PEP 696: Fix swapping TypeVars with defaults (Randolf Scholz, PR [19449](https://github.com/python/mypy/pull/19449))
1392 - Fix narrowing of class pattern with union type (Randolf Scholz, PR [19517](https://github.com/python/mypy/pull/19517))
1393 - Do not emit unreachable warnings for lines that return `NotImplemented` (Christoph Tyralla, PR [20083](https://github.com/python/mypy/pull/20083))
1394 - Fix matching against `typing.Callable` and `Protocol` types (Randolf Scholz, PR [19471](https://github.com/python/mypy/pull/19471))
1395 - Make `--pretty` work better on multi-line issues (A5rocks, PR [20056](https://github.com/python/mypy/pull/20056))
1396 - More precise return types for `TypedDict.get` (Randolf Scholz, PR [19897](https://github.com/python/mypy/pull/19897))
1397 - Prevent false unreachable warnings for `@final` instances that occur when strict optional checking is disabled (Christoph Tyralla, PR [20045](https://github.com/python/mypy/pull/20045))
1398 - Check class references to catch non-existent classes in match cases (A5rocks, PR [20042](https://github.com/python/mypy/pull/20042))
1399 - Do not sort unused error codes in unused error codes warning (wyattscarpenter, PR [20036](https://github.com/python/mypy/pull/20036))
1400 - Fix `[name-defined]` false positive in `class A[X, Y=X]:` case (sobolevn, PR [20021](https://github.com/python/mypy/pull/20021))
1401 - Filter SyntaxWarnings during AST parsing (Marc Mueller, PR [20023](https://github.com/python/mypy/pull/20023))
1402 - Make untyped decorator its own error code (wyattscarpenter, PR [19911](https://github.com/python/mypy/pull/19911))
1403 - Support error codes from plugins in options (Sigve Sebastian Farstad, PR [19719](https://github.com/python/mypy/pull/19719))
1404 - Allow returning Literals in `__new__` (James Hilton-Balfe, PR [15687](https://github.com/python/mypy/pull/15687))
1405 - Inverse interface freshness logic (Ivan Levkivskyi, PR [19809](https://github.com/python/mypy/pull/19809))
1406 - Do not report exhaustive-match after deferral (Stanislav Terliakov, PR [19804](https://github.com/python/mypy/pull/19804))
1407 - Make `untyped_calls_exclude` invalidate cache (Ivan Levkivskyi, PR [19801](https://github.com/python/mypy/pull/19801))
1408 - Add await to empty context hack (Stanislav Terliakov, PR [19777](https://github.com/python/mypy/pull/19777))
1409 - Consider non-empty enums assignable to Self (Stanislav Terliakov, PR [19779](https://github.com/python/mypy/pull/19779))
1410
1411 ### Typeshed updates
1412
1413 Please see [git log](https://github.com/python/typeshed/commits/main?after=ebce8d766b41fbf4d83cf47c1297563a9508ff60+0&branch=main&path=stdlib) for full list of standard library typeshed stub changes.
1414
1415 ### Mypy 1.19.1
1416
1417 - Fix noncommutative joins with bounded TypeVars (Shantanu, PR [20345](https://github.com/python/mypy/pull/20345))
1418 - Respect output format for cached runs by serializing raw errors in cache metas (Ivan Levkivskyi, PR [20372](https://github.com/python/mypy/pull/20372))
1419 - Allow `types.NoneType` in match cases (A5rocks, PR [20383](https://github.com/python/mypy/pull/20383))
1420 - Fix mypyc generator regression with empty tuple (BobTheBuidler, PR [20371](https://github.com/python/mypy/pull/20371))
1421 - Fix crash involving Unpack-ed TypeVarTuple (Shantanu, PR [20323](https://github.com/python/mypy/pull/20323))
1422 - Fix crash on star import of redefinition (Ivan Levkivskyi, PR [20333](https://github.com/python/mypy/pull/20333))
1423 - Fix crash on typevar with forward ref used in other module (Ivan Levkivskyi, PR [20334](https://github.com/python/mypy/pull/20334))
1424 - Fail with an explicit error on PyPy (Ivan Levkivskyi, PR [20389](https://github.com/python/mypy/pull/20389))
1425
1426 ### Acknowledgements
1427
1428 Thanks to all mypy contributors who contributed to this release:
1429 - A5rocks
1430 - BobTheBuidler
1431 - bzoracler
1432 - Chainfire
1433 - Christoph Tyralla
1434 - David Foster
1435 - Frank Dana
1436 - Guo Ci
1437 - iap
1438 - Ivan Levkivskyi
1439 - James Hilton-Balfe
1440 - jhance
1441 - Joren Hammudoglu
1442 - Jukka Lehtosalo
1443 - KarelKenens
1444 - Kevin Kannammalil
1445 - Marc Mueller
1446 - Michael Carlstrom
1447 - Michael J. Sullivan
1448 - Piotr Sawicki
1449 - Randolf Scholz
1450 - Shantanu
1451 - Sigve Sebastian Farstad
1452 - sobolevn
1453 - Stanislav Terliakov
1454 - Stephen Morton
1455 - Theodore Ando
1456 - Thiago J. Barbalho
1457 - wyattscarpenter
1458
1459 I’d also like to thank my employer, Dropbox, for supporting mypy development.
1460
1461 ## Mypy 1.18
1462
1463 We’ve just uploaded mypy 1.18.1 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).
1464 Mypy is a static type checker for Python. This release includes new features, performance
1465 improvements and bug fixes. You can install it as follows:
1466
1467 python3 -m pip install -U mypy
1468
1469 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
1470
1471 ### Mypy Performance Improvements
1472
1473 Mypy 1.18.1 includes numerous performance improvements, resulting in about 40% speedup
1474 compared to 1.17 when type checking mypy itself. In extreme cases, the improvement
1475 can be 10x or higher. The list below is an overview of the various mypy optimizations.
1476 Many mypyc improvements (discussed in a separate section below) also improve performance.
1477
1478 Type caching optimizations have a small risk of causing regressions. When
1479 reporting issues with unexpected inferred types, please also check if
1480 `--disable-expression-cache` will work around the issue, as it turns off some of
1481 these optimizations.
1482
1483 - Improve self check performance by 1.8% (Jukka Lehtosalo, PR [19768](https://github.com/python/mypy/pull/19768), [19769](https://github.com/python/mypy/pull/19769), [19770](https://github.com/python/mypy/pull/19770))
1484 - Optimize fixed-format deserialization (Ivan Levkivskyi, PR [19765](https://github.com/python/mypy/pull/19765))
1485 - Use macros to optimize fixed-format deserialization (Ivan Levkivskyi, PR [19757](https://github.com/python/mypy/pull/19757))
1486 - Two additional micro‑optimizations (Ivan Levkivskyi, PR [19627](https://github.com/python/mypy/pull/19627))
1487 - Another set of micro‑optimizations (Ivan Levkivskyi, PR [19633](https://github.com/python/mypy/pull/19633))
1488 - Cache common types (Ivan Levkivskyi, PR [19621](https://github.com/python/mypy/pull/19621))
1489 - Skip more method bodies in third‑party libraries for speed (Ivan Levkivskyi, PR [19586](https://github.com/python/mypy/pull/19586))
1490 - Simplify the representation of callable types (Ivan Levkivskyi, PR [19580](https://github.com/python/mypy/pull/19580))
1491 - Add cache for types of some expressions (Ivan Levkivskyi, PR [19505](https://github.com/python/mypy/pull/19505))
1492 - Use cache for dictionary expressions (Ivan Levkivskyi, PR [19536](https://github.com/python/mypy/pull/19536))
1493 - Use cache for binary operations (Ivan Levkivskyi, PR [19523](https://github.com/python/mypy/pull/19523))
1494 - Cache types of type objects (Ivan Levkivskyi, PR [19514](https://github.com/python/mypy/pull/19514))
1495 - Avoid duplicate work when checking boolean operations (Ivan Levkivskyi, PR [19515](https://github.com/python/mypy/pull/19515))
1496 - Optimize generic inference passes (Ivan Levkivskyi, PR [19501](https://github.com/python/mypy/pull/19501))
1497 - Speed up the default plugin (Jukka Lehtosalo, PRs [19385](https://github.com/python/mypy/pull/19385) and [19462](https://github.com/python/mypy/pull/19462))
1498 - Remove nested imports from the default plugin (Ivan Levkivskyi, PR [19388](https://github.com/python/mypy/pull/19388))
1499 - Micro‑optimize type expansion (Jukka Lehtosalo, PR [19461](https://github.com/python/mypy/pull/19461))
1500 - Micro‑optimize type indirection (Jukka Lehtosalo, PR [19460](https://github.com/python/mypy/pull/19460))
1501 - Micro‑optimize the plugin framework (Jukka Lehtosalo, PR [19464](https://github.com/python/mypy/pull/19464))
1502 - Avoid temporary set creation in subtype checking (Jukka Lehtosalo, PR [19463](https://github.com/python/mypy/pull/19463))
1503 - Subtype checking micro‑optimization (Jukka Lehtosalo, PR [19384](https://github.com/python/mypy/pull/19384))
1504 - Return early where possible in subtype check (Stanislav Terliakov, PR [19400](https://github.com/python/mypy/pull/19400))
1505 - Deduplicate some types before joining (Stanislav Terliakov, PR [19409](https://github.com/python/mypy/pull/19409))
1506 - Speed up type checking by caching argument inference context (Jukka Lehtosalo, PR [19323](https://github.com/python/mypy/pull/19323))
1507 - Optimize binding method self argument type and deprecation checks (Ivan Levkivskyi, PR [19556](https://github.com/python/mypy/pull/19556))
1508 - Keep trivial instance types/aliases during expansion (Ivan Levkivskyi, PR [19543](https://github.com/python/mypy/pull/19543))
1509
1510 ### Fixed‑Format Cache (Experimental)
1511
1512 Mypy now supports a new cache format used for faster incremental builds. It makes
1513 incremental builds up to twice as fast. The feature is experimental and
1514 currently only supported when using a compiled version of mypy. Use `--fixed-format-cache`
1515 to enable the new format, or `fixed_format_cache = True` in a configuration file.
1516
1517 We plan to enable this by default in a future mypy release, and we'll eventually
1518 deprecate and remove support for the original JSON-based format.
1519
1520 Unlike the JSON-based cache format, the new binary format is currently
1521 not easy to parse and inspect by mypy users. We are planning to provide a tool to
1522 convert fixed-format cache files to JSON, but details of the output JSON may be
1523 different from the current JSON format. If you rely on being able to inspect
1524 mypy cache files, we recommend creating a GitHub issue and explaining your use
1525 case, so that we can more likely provide support for it. (Using
1526 `MypyFile.read(binary_data)` to inspect cache data may be sufficient to support
1527 some use cases.)
1528
1529 This feature was contributed by Ivan Levkivskyi (PR [19668](https://github.com/python/mypy/pull/19668), [19735](https://github.com/python/mypy/pull/19735), [19750](https://github.com/python/mypy/pull/19750), [19681](https://github.com/python/mypy/pull/19681), [19752](https://github.com/python/mypy/pull/19752), [19815](https://github.com/python/mypy/pull/19815)).
1530
1531 ### Flexible Variable Definitions: Update
1532
1533 Mypy 1.16.0 introduced `--allow-redefinition-new`, which allows redefining variables
1534 with different types, and inferring union types for variables from multiple assignments.
1535 The feature is now documented in the `--help` output, but the feature is still experimental.
1536
1537 We are planning to enable this by default in mypy 2.0, and we will also deprecate the
1538 older `--allow-redefinition` flag. Since the new behavior differs significantly from
1539 the older flag, we encourage users of `--allow-redefinition` to experiment with
1540 `--allow-redefinition-new` and create a GitHub issue if the new functionality doesn't
1541 support some important use cases.
1542
1543 This feature was contributed by Jukka Lehtosalo.
1544
1545 ### Inferred Type for Bare ClassVar
1546
1547 A ClassVar without an explicit type annotation now causes the type of the variable
1548 to be inferred from the initializer:
1549
1550
1551 ```python
1552 from typing import ClassVar
1553
1554 class Item:
1555 # Type of 'next_id' is now 'int' (it was 'Any')
1556 next_id: ClassVar = 1
1557
1558 ...
1559 ```
1560
1561 This feature was contributed by Ivan Levkivskyi (PR [19573](https://github.com/python/mypy/pull/19573)).
1562
1563 ### Disjoint Base Classes (@disjoint_base, PEP 800)
1564
1565 Mypy now understands disjoint bases (PEP 800): it recognizes the `@disjoint_base`
1566 decorator, and rejects class definitions that combine mutually incompatible base classes,
1567 and takes advantage of the fact that such classes cannot exist in reachability and
1568 narrowing logic.
1569
1570 This class definition will now generate an error:
1571
1572 ```python
1573 # Error: Class "Bad" has incompatible disjoint bases
1574 class Bad(str, Exception):
1575 ...
1576 ```
1577
1578 This feature was contributed by Jelle Zijlstra (PR [19678](https://github.com/python/mypy/pull/19678)).
1579
1580 ### Miscellaneous New Mypy Features
1581
1582 - Add `--strict-equality-for-none` to flag non-overlapping comparisons involving None (Christoph Tyralla, PR [19718](https://github.com/python/mypy/pull/19718))
1583 - Don’t show import‑related errors after a module‑level assert such as `assert sys.platform == "linux"` that is always false (Stanislav Terliakov, PR [19347](https://github.com/python/mypy/pull/19347))
1584
1585 ### Improvements to Match Statements
1586
1587 - Add temporary named expressions for match subjects (Stanislav Terliakov, PR [18446](https://github.com/python/mypy/pull/18446))
1588 - Fix unwrapping of assignment expressions in match subject (Marc Mueller, PR [19742](https://github.com/python/mypy/pull/19742))
1589 - Omit errors for class patterns against object (Marc Mueller, PR [19709](https://github.com/python/mypy/pull/19709))
1590 - Remove unnecessary error for certain match class patterns (Marc Mueller, PR [19708](https://github.com/python/mypy/pull/19708))
1591 - Use union type for captured vars in or pattern (Marc Mueller, PR [19710](https://github.com/python/mypy/pull/19710))
1592 - Prevent final reassignment inside match case (Omer Hadari, PR [19496](https://github.com/python/mypy/pull/19496))
1593
1594 ### Fixes to Crashes
1595
1596 - Fix crash with variadic tuple arguments to a generic type (Randolf Scholz, PR [19705](https://github.com/python/mypy/pull/19705))
1597 - Fix crash when enable_error_code in pyproject.toml has wrong type (wyattscarpenter, PR [19494](https://github.com/python/mypy/pull/19494))
1598 - Prevent crash for dataclass with PEP 695 TypeVarTuple on Python 3.13+ (Stanislav Terliakov, PR [19565](https://github.com/python/mypy/pull/19565))
1599 - Fix crash on settable property alias (Ivan Levkivskyi, PR [19615](https://github.com/python/mypy/pull/19615))
1600
1601 ### Experimental Free-threading Support for Mypyc
1602
1603 All mypyc tests now pass on free-threading Python 3.14 release candidate builds. The performance
1604 of various micro-benchmarks scale well across multiple threads.
1605
1606 Free-threading support is still experimental. Note that native attribute access
1607 (get and set), list item access and certain other operations are still
1608 unsafe when there are race conditions. This will likely change in the future.
1609 You can follow the
1610 [area-free-threading label](https://github.com/mypyc/mypyc/issues?q=is%3Aissue%20state%3Aopen%20label%3Aarea-free-threading)
1611 in the mypyc issues tracker to follow progress.
1612
1613 Related PRs:
1614 - Enable free‑threading when compiling multiple modules (Jukka Lehtosalo, PR [19541](https://github.com/python/mypy/pull/19541))
1615 - Fix `list.pop` on free‑threaded builds (Jukka Lehtosalo, PR [19522](https://github.com/python/mypy/pull/19522))
1616 - Make type objects immortal under free‑threading (Jukka Lehtosalo, PR [19538](https://github.com/python/mypy/pull/19538))
1617
1618 ### Mypyc: Support `__new__`
1619
1620 Mypyc now has rudimentary support for user-defined `__new__` methods.
1621
1622 This feature was contributed by Piotr Sawicki (PR [19739](https://github.com/python/mypy/pull/19739)).
1623
1624 ### Mypyc: Faster Generators and Async Functions
1625
1626 Generators and calls of async functions are now faster, sometimes by 2x or more.
1627
1628 Related PRs:
1629 - Speed up for loops over native generators (Jukka Lehtosalo, PR [19415](https://github.com/python/mypy/pull/19415))
1630 - Speed up native‑to‑native calls using await (Jukka Lehtosalo, PR [19398](https://github.com/python/mypy/pull/19398))
1631 - Call generator helper directly in await expressions (Jukka Lehtosalo, PR [19376](https://github.com/python/mypy/pull/19376))
1632 - Speed up generator allocation with per‑type freelists (Jukka Lehtosalo, PR [19316](https://github.com/python/mypy/pull/19316))
1633
1634 ### Miscellaneous Mypyc Improvements
1635
1636 - Special‑case certain Enum method calls for speed (Ivan Levkivskyi, PR [19634](https://github.com/python/mypy/pull/19634))
1637 - Fix issues related to subclassing and undefined attribute tracking (Chainfire, PR [19787](https://github.com/python/mypy/pull/19787))
1638 - Fix invalid C function signature (Jukka Lehtosalo, PR [19773](https://github.com/python/mypy/pull/19773))
1639 - Speed up implicit `__ne__` (Jukka Lehtosalo, PR [19759](https://github.com/python/mypy/pull/19759))
1640 - Speed up equality with optional str/bytes types (Jukka Lehtosalo, PR [19758](https://github.com/python/mypy/pull/19758))
1641 - Speed up access to empty tuples (BobTheBuidler, PR [19654](https://github.com/python/mypy/pull/19654))
1642 - Speed up calls with `*args` (BobTheBuidler, PRs [19623](https://github.com/python/mypy/pull/19623) and [19631](https://github.com/python/mypy/pull/19631))
1643 - Speed up calls with `**kwargs` (BobTheBuidler, PR [19630](https://github.com/python/mypy/pull/19630))
1644 - Optimize `type(x)`, `x.__class__`, and `<type>.__name__` (Jukka Lehtosalo, PR [19691](https://github.com/python/mypy/pull/19691), [19683](https://github.com/python/mypy/pull/19683))
1645 - Specialize `bytes.decode` for common encodings (Jukka Lehtosalo, PR [19688](https://github.com/python/mypy/pull/19688))
1646 - Speed up `in` operations using final fixed‑length tuples (Jukka Lehtosalo, PR [19682](https://github.com/python/mypy/pull/19682))
1647 - Optimize f‑string building from final values (BobTheBuidler, PR [19611](https://github.com/python/mypy/pull/19611))
1648 - Add dictionary set item for exact dict instances (BobTheBuidler, PR [19657](https://github.com/python/mypy/pull/19657))
1649 - Cache length when iterating over immutable types (BobTheBuidler, PR [19656](https://github.com/python/mypy/pull/19656))
1650 - Fix name conflict related to attributes of generator classes (Piotr Sawicki, PR [19535](https://github.com/python/mypy/pull/19535))
1651 - Fix segfault from heap type objects with a static docstring (Brian Schubert, PR [19636](https://github.com/python/mypy/pull/19636))
1652 - Unwrap NewType to its base type for additional optimizations (BobTheBuidler, PR [19497](https://github.com/python/mypy/pull/19497))
1653 - Generate an export table only for separate compilation (Jukka Lehtosalo, PR [19521](https://github.com/python/mypy/pull/19521))
1654 - Speed up `isinstance` with built‑in types (Piotr Sawicki, PR [19435](https://github.com/python/mypy/pull/19435))
1655 - Use native integers for some sequence indexing (Jukka Lehtosalo, PR [19426](https://github.com/python/mypy/pull/19426))
1656 - Speed up `isinstance(obj, list)` (Piotr Sawicki, PR [19416](https://github.com/python/mypy/pull/19416))
1657 - Report error on reserved method names (Piotr Sawicki, PR [19407](https://github.com/python/mypy/pull/19407))
1658 - Speed up string equality (Jukka Lehtosalo, PR [19402](https://github.com/python/mypy/pull/19402))
1659 - Raise `NameError` on undefined names (Piotr Sawicki, PR [19395](https://github.com/python/mypy/pull/19395))
1660 - Use per‑type freelists for nested functions (Jukka Lehtosalo, PR [19390](https://github.com/python/mypy/pull/19390))
1661 - Simplify comparison of tuple elements (Piotr Sawicki, PR [19396](https://github.com/python/mypy/pull/19396))
1662 - Generate introspection signatures for compiled functions (Brian Schubert, PR [19307](https://github.com/python/mypy/pull/19307))
1663 - Fix undefined attribute checking special case (Jukka Lehtosalo, PR [19378](https://github.com/python/mypy/pull/19378))
1664 - Fix comparison of tuples with different lengths (Piotr Sawicki, PR [19372](https://github.com/python/mypy/pull/19372))
1665 - Speed up `list.clear` (Jahongir Qurbonov, PR [19344](https://github.com/python/mypy/pull/19344))
1666 - Speed up `weakref.proxy` (BobTheBuidler, PR [19217](https://github.com/python/mypy/pull/19217))
1667 - Speed up `weakref.ref` (BobTheBuidler, PR [19099](https://github.com/python/mypy/pull/19099))
1668 - Speed up `str.count` (BobTheBuidler, PR [19264](https://github.com/python/mypy/pull/19264))
1669
1670 ### Stubtest Improvements
1671 - Add temporary `--ignore-disjoint-bases` flag to ease PEP 800 migration (Joren Hammudoglu, PR [19740](https://github.com/python/mypy/pull/19740))
1672 - Flag redundant uses of `@disjoint_base` (Jelle Zijlstra, PR [19715](https://github.com/python/mypy/pull/19715))
1673 - Improve signatures for `__init__` of C extension classes (Stephen Morton, PR [18259](https://github.com/python/mypy/pull/18259))
1674 - Handle overloads with mixed positional‑only parameters (Stephen Morton, PR [18287](https://github.com/python/mypy/pull/18287))
1675 - Use “parameter” (not “argument”) in error messages (PrinceNaroliya, PR [19707](https://github.com/python/mypy/pull/19707))
1676 - Don’t require `@disjoint_base` when `__slots__` imply finality (Jelle Zijlstra, PR [19701](https://github.com/python/mypy/pull/19701))
1677 - Allow runtime‑existing aliases of `@type_check_only` types (Brian Schubert, PR [19568](https://github.com/python/mypy/pull/19568))
1678 - More detailed checking of type objects in stubtest (Stephen Morton, PR [18251](https://github.com/python/mypy/pull/18251))
1679 - Support running stubtest in non-UTF8 terminals (Stanislav Terliakov, PR [19085](https://github.com/python/mypy/pull/19085))
1680
1681 ### Documentation Updates
1682
1683 - Add idlemypyextension to IDE integrations (CoolCat467, PR [18615](https://github.com/python/mypy/pull/18615))
1684 - Document that `object` is often preferable to `Any` in APIs (wyattscarpenter, PR [19103](https://github.com/python/mypy/pull/19103))
1685 - Include a detailed listing of flags enabled by `--strict` (wyattscarpenter, PR [19062](https://github.com/python/mypy/pull/19062))
1686 - Update “common issues” (reveal_type/reveal_locals; note on orjson) (wyattscarpenter, PR [19059](https://github.com/python/mypy/pull/19059), [19058](https://github.com/python/mypy/pull/19058))
1687
1688 ### Other Notable Fixes and Improvements
1689
1690 - Remove deprecated `--new-type-inference` flag (the new algorithm has long been default) (Ivan Levkivskyi, PR [19570](https://github.com/python/mypy/pull/19570))
1691 - Use empty context as a fallback for return expressions when outer context misleads inference (Ivan Levkivskyi, PR [19767](https://github.com/python/mypy/pull/19767))
1692 - Fix forward references in type parameters of over‑parameterized PEP 695 aliases (Brian Schubert, PR [19725](https://github.com/python/mypy/pull/19725))
1693 - Don’t expand PEP 695 aliases when checking node fullnames (Brian Schubert, PR [19699](https://github.com/python/mypy/pull/19699))
1694 - Don’t use outer context for 'or' expression inference when LHS is Any (Stanislav Terliakov, PR [19748](https://github.com/python/mypy/pull/19748))
1695 - Recognize buffer protocol special methods (Brian Schubert, PR [19581](https://github.com/python/mypy/pull/19581))
1696 - Support attribute access on enum members correctly (Stanislav Terliakov, PR [19422](https://github.com/python/mypy/pull/19422))
1697 - Check `__slots__` assignments on self types (Stanislav Terliakov, PR [19332](https://github.com/python/mypy/pull/19332))
1698 - Move self‑argument checks after decorator application (Stanislav Terliakov, PR [19490](https://github.com/python/mypy/pull/19490))
1699 - Infer empty list for `__slots__` and module `__all__` (Stanislav Terliakov, PR [19348](https://github.com/python/mypy/pull/19348))
1700 - Use normalized tuples for fallback calculation (Stanislav Terliakov, PR [19111](https://github.com/python/mypy/pull/19111))
1701 - Preserve literals when joining similar types (Stanislav Terliakov, PR [19279](https://github.com/python/mypy/pull/19279))
1702 - Allow adjacent conditionally‑defined overloads (Stanislav Terliakov, PR [19042](https://github.com/python/mypy/pull/19042))
1703 - Check property decorators more strictly (Stanislav Terliakov, PR [19313](https://github.com/python/mypy/pull/19313))
1704 - Support properties with generic setters (Ivan Levkivskyi, PR [19298](https://github.com/python/mypy/pull/19298))
1705 - Generalize class/static method and property alias support (Ivan Levkivskyi, PR [19297](https://github.com/python/mypy/pull/19297))
1706 - Re‑widen custom properties after narrowing (Ivan Levkivskyi, PR [19296](https://github.com/python/mypy/pull/19296))
1707 - Avoid erasing type objects when checking runtime cover (Shantanu, PR [19320](https://github.com/python/mypy/pull/19320))
1708 - Include tuple fallback in constraints built from tuple types (Stanislav Terliakov, PR [19100](https://github.com/python/mypy/pull/19100))
1709 - Somewhat better isinstance support on old‑style unions (Shantanu, PR [19714](https://github.com/python/mypy/pull/19714))
1710 - Improve promotions inside unions (Christoph Tyralla, PR [19245](https://github.com/python/mypy/pull/19245))
1711 - Treat uninhabited types as having all attributes (Ivan Levkivskyi, PR [19300](https://github.com/python/mypy/pull/19300))
1712 - Improve metaclass conflict checks (Robsdedude, PR [17682](https://github.com/python/mypy/pull/17682))
1713 - Fixes to metaclass resolution algorithm (Robsdedude, PR [17713](https://github.com/python/mypy/pull/17713))
1714 - PEP 702 @deprecated: handle “combined” overloads (Christoph Tyralla, PR [19626](https://github.com/python/mypy/pull/19626))
1715 - PEP 702 @deprecated: include overloads in snapshot descriptions (Christoph Tyralla, PR [19613](https://github.com/python/mypy/pull/19613))
1716 - Ignore overload implementation when checking `__OP__` / `__rOP__` compatibility (Stanislav Terliakov, PR [18502](https://github.com/python/mypy/pull/18502))
1717 - Support `_value_` as a fallback for ellipsis Enum members (Stanislav Terliakov, PR [19352](https://github.com/python/mypy/pull/19352))
1718 - Sort arguments in TypedDict overlap messages (Marc Mueller, PR [19666](https://github.com/python/mypy/pull/19666))
1719 - Fix handling of implicit return in lambda (Stanislav Terliakov, PR [19642](https://github.com/python/mypy/pull/19642))
1720 - Improve behavior of uninhabited types (Stanislav Terliakov, PR [19648](https://github.com/python/mypy/pull/19648))
1721 - Fix overload diagnostics when `*args` and `**kwargs` both match (Shantanu, PR [19614](https://github.com/python/mypy/pull/19614))
1722 - Further fix overload diagnostics for `*args`/`**kwargs` (Shantanu, PR [19619](https://github.com/python/mypy/pull/19619))
1723 - Show type variable name in "Cannot infer type argument" (Brian Schubert, PR [19290](https://github.com/python/mypy/pull/19290))
1724 - Fail gracefully on unsupported template strings (PEP 750) (Brian Schubert, PR [19700](https://github.com/python/mypy/pull/19700))
1725 - Revert colored argparse help for Python 3.14 (Marc Mueller, PR [19721](https://github.com/python/mypy/pull/19721))
1726 - Update stubinfo for latest typeshed (Shantanu, PR [19771](https://github.com/python/mypy/pull/19771))
1727 - Fix dict assignment when an incompatible same‑shape TypedDict exists (Stanislav Terliakov, PR [19592](https://github.com/python/mypy/pull/19592))
1728 - Fix constructor type for subclasses of Any (Ivan Levkivskyi, PR [19295](https://github.com/python/mypy/pull/19295))
1729 - Fix TypeGuard/TypeIs being forgotten in some cases (Brian Schubert, PR [19325](https://github.com/python/mypy/pull/19325))
1730 - Fix TypeIs negative narrowing for unions of generics (Brian Schubert, PR [18193](https://github.com/python/mypy/pull/18193))
1731 - dmypy suggest: Fix incorrect signature suggestion when a type matches a module name (Brian Schubert, PR [18937](https://github.com/python/mypy/pull/18937))
1732 - dmypy suggest: Fix interaction with `__new__` (Stanislav Terliakov, PR [18966](https://github.com/python/mypy/pull/18966))
1733 - dmypy suggest: Support Callable / callable Protocols in decorator unwrapping (Anthony Sottile, PR [19072](https://github.com/python/mypy/pull/19072))
1734 - Fix missing error when redeclaring a type variable in a nested generic class (Brian Schubert, PR [18883](https://github.com/python/mypy/pull/18883))
1735 - Fix for overloaded type object erasure (Shantanu, PR [19338](https://github.com/python/mypy/pull/19338))
1736 - Fix TypeGuard with call on temporary object (Saul Shanabrook, PR [19577](https://github.com/python/mypy/pull/19577))
1737
1738 ### Typeshed Updates
1739
1740 Please see [git log](https://github.com/python/typeshed/commits/main?after=2480d7e7c74493a024eaf254c5d2c6f452c80ee2+0&branch=main&path=stdlib) for full list of standard library typeshed stub changes.
1741
1742 ### Mypy 1.18.2
1743
1744 - Fix crash on recursive alias (Ivan Levkivskyi, PR [19845](https://github.com/python/mypy/pull/19845))
1745 - Add additional guidance for stubtest errors when runtime is `object.__init__` (Stephen Morton, PR [19733](https://github.com/python/mypy/pull/19733))
1746 - Fix handling of None values in f-string expressions in mypyc (BobTheBuidler, PR [19846](https://github.com/python/mypy/pull/19846))
1747
1748 ### Acknowledgements
1749
1750 Thanks to all mypy contributors who contributed to this release:
1751
1752 - Ali Hamdan
1753 - Anthony Sottile
1754 - BobTheBuidler
1755 - Brian Schubert
1756 - Chainfire
1757 - Charlie Denton
1758 - Christoph Tyralla
1759 - CoolCat467
1760 - Daniel Hnyk
1761 - Emily
1762 - Emma Smith
1763 - Ethan Sarp
1764 - Ivan Levkivskyi
1765 - Jahongir Qurbonov
1766 - Jelle Zijlstra
1767 - Joren Hammudoglu
1768 - Jukka Lehtosalo
1769 - Marc Mueller
1770 - Omer Hadari
1771 - Piotr Sawicki
1772 - PrinceNaroliya
1773 - Randolf Scholz
1774 - Robsdedude
1775 - Saul Shanabrook
1776 - Shantanu
1777 - Stanislav Terliakov
1778 - Stephen Morton
1779 - wyattscarpenter
1780
1781 I’d also like to thank my employer, Dropbox, for supporting mypy development.
1782
1783 ## Mypy 1.17
1784
1785 We’ve just uploaded mypy 1.17 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).
1786 Mypy is a static type checker for Python. This release includes new features and bug fixes.
1787 You can install it as follows:
1788
1789 python3 -m pip install -U mypy
1790
1791 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
1792
1793 ### Optionally Check That Match Is Exhaustive
1794
1795 Mypy can now optionally generate an error if a match statement does not
1796 match exhaustively, without having to use `assert_never(...)`. Enable
1797 this by using `--enable-error-code exhaustive-match`.
1798
1799 Example:
1800
1801 ```python
1802 # mypy: enable-error-code=exhaustive-match
1803
1804 import enum
1805
1806 class Color(enum.Enum):
1807 RED = 1
1808 BLUE = 2
1809
1810 def show_color(val: Color) -> None:
1811 # error: Unhandled case for values of type "Literal[Color.BLUE]"
1812 match val:
1813 case Color.RED:
1814 print("red")
1815 ```
1816
1817 This feature was contributed by Donal Burns (PR [19144](https://github.com/python/mypy/pull/19144)).
1818
1819 ### Further Improvements to Attribute Resolution
1820
1821 This release includes additional improvements to how attribute types
1822 and kinds are resolved. These fix many bugs and overall improve consistency.
1823
1824 * Handle corner case: protocol/class variable/descriptor (Ivan Levkivskyi, PR [19277](https://github.com/python/mypy/pull/19277))
1825 * Fix a few inconsistencies in protocol/type object interactions (Ivan Levkivskyi, PR [19267](https://github.com/python/mypy/pull/19267))
1826 * Refactor/unify access to static attributes (Ivan Levkivskyi, PR [19254](https://github.com/python/mypy/pull/19254))
1827 * Remove inconsistencies in operator handling (Ivan Levkivskyi, PR [19250](https://github.com/python/mypy/pull/19250))
1828 * Make protocol subtyping more consistent (Ivan Levkivskyi, PR [18943](https://github.com/python/mypy/pull/18943))
1829
1830 ### Fixes to Nondeterministic Type Checking
1831
1832 Previous mypy versions could infer different types for certain expressions
1833 across different runs (typically depending on which order certain types
1834 were processed, and this order was nondeterministic). This release includes
1835 fixes to several such issues.
1836
1837 * Fix nondeterministic type checking by making join with explicit Protocol and type promotion commute (Shantanu, PR [18402](https://github.com/python/mypy/pull/18402))
1838 * Fix nondeterministic type checking caused by nonassociative of None joins (Shantanu, PR [19158](https://github.com/python/mypy/pull/19158))
1839 * Fix nondeterministic type checking caused by nonassociativity of joins (Shantanu, PR [19147](https://github.com/python/mypy/pull/19147))
1840 * Fix nondeterministic type checking by making join between `type` and TypeVar commute (Shantanu, PR [19149](https://github.com/python/mypy/pull/19149))
1841
1842 ### Remove Support for Targeting Python 3.8
1843
1844 Mypy now requires `--python-version 3.9` or greater. Support for targeting Python 3.8 is
1845 fully removed now. Since 3.8 is an unsupported version, mypy will default to the oldest
1846 supported version (currently 3.9) if you still try to target 3.8.
1847
1848 This change is necessary because typeshed stopped supporting Python 3.8 after it
1849 reached its End of Life in October 2024.
1850
1851 Contributed by Marc Mueller
1852 (PR [19157](https://github.com/python/mypy/pull/19157), PR [19162](https://github.com/python/mypy/pull/19162)).
1853
1854 ### Initial Support for Python 3.14
1855
1856 Mypy is now tested on 3.14 and mypyc works with 3.14.0b3 and later.
1857 Binary wheels compiled with mypyc for mypy itself will be available for 3.14
1858 some time after 3.14.0rc1 has been released.
1859
1860 Note that not all features are supported just yet.
1861
1862 Contributed by Marc Mueller (PR [19164](https://github.com/python/mypy/pull/19164))
1863
1864 ### Deprecated Flag: `--force-uppercase-builtins`
1865
1866 Mypy only supports Python 3.9+. The `--force-uppercase-builtins` flag is now
1867 deprecated as unnecessary, and a no-op. It will be removed in a future version.
1868
1869 Contributed by Marc Mueller (PR [19176](https://github.com/python/mypy/pull/19176))
1870
1871 ### Mypyc: Improvements to Generators and Async Functions
1872
1873 This release includes both performance improvements and bug fixes related
1874 to generators and async functions (these share many implementation details).
1875
1876 * Fix exception swallowing in async try/finally blocks with await (Chainfire, PR [19353](https://github.com/python/mypy/pull/19353))
1877 * Fix AttributeError in async try/finally with mixed return paths (Chainfire, PR [19361](https://github.com/python/mypy/pull/19361))
1878 * Make generated generator helper method internal (Jukka Lehtosalo, PR [19268](https://github.com/python/mypy/pull/19268))
1879 * Free coroutine after await encounters StopIteration (Jukka Lehtosalo, PR [19231](https://github.com/python/mypy/pull/19231))
1880 * Use non-tagged integer for generator label (Jukka Lehtosalo, PR [19218](https://github.com/python/mypy/pull/19218))
1881 * Merge generator and environment classes in simple cases (Jukka Lehtosalo, PR [19207](https://github.com/python/mypy/pull/19207))
1882
1883 ### Mypyc: Partial, Unsafe Support for Free Threading
1884
1885 Mypyc has minimal, quite memory-unsafe support for the free threaded
1886 builds of 3.14. It is also only lightly tested. Bug reports and experience
1887 reports are welcome!
1888
1889 Here are some of the major limitations:
1890 * Free threading only works when compiling a single module at a time.
1891 * If there is concurrent access to an object while another thread is mutating the same
1892 object, it's possible to encounter segfaults and memory corruption.
1893 * There are no efficient native primitives for thread synthronization, though the
1894 regular `threading` module can be used.
1895 * Some workloads don't scale well to multiple threads for no clear reason.
1896
1897 Related PRs:
1898
1899 * Enable partial, unsafe support for free-threading (Jukka Lehtosalo, PR [19167](https://github.com/python/mypy/pull/19167))
1900 * Fix incref/decref on free-threaded builds (Jukka Lehtosalo, PR [19127](https://github.com/python/mypy/pull/19127))
1901
1902 ### Other Mypyc Fixes and Improvements
1903
1904 * Derive .c file name from full module name if using multi_file (Jukka Lehtosalo, PR [19278](https://github.com/python/mypy/pull/19278))
1905 * Support overriding the group name used in output files (Jukka Lehtosalo, PR [19272](https://github.com/python/mypy/pull/19272))
1906 * Add note about using non-native class to subclass built-in types (Jukka Lehtosalo, PR [19236](https://github.com/python/mypy/pull/19236))
1907 * Make some generated classes implicitly final (Jukka Lehtosalo, PR [19235](https://github.com/python/mypy/pull/19235))
1908 * Don't simplify module prefixes if using separate compilation (Jukka Lehtosalo, PR [19206](https://github.com/python/mypy/pull/19206))
1909
1910 ### Stubgen Improvements
1911
1912 * Add import for `types` in `__exit__` method signature (Alexey Makridenko, PR [19120](https://github.com/python/mypy/pull/19120))
1913 * Add support for including class and property docstrings (Chad Dombrova, PR [17964](https://github.com/python/mypy/pull/17964))
1914 * Don't generate `Incomplete | None = None` argument annotation (Sebastian Rittau, PR [19097](https://github.com/python/mypy/pull/19097))
1915 * Support several more constructs in stubgen's alias printer (Stanislav Terliakov, PR [18888](https://github.com/python/mypy/pull/18888))
1916
1917 ### Miscellaneous Fixes and Improvements
1918
1919 * Combine the revealed types of multiple iteration steps in a more robust manner (Christoph Tyralla, PR [19324](https://github.com/python/mypy/pull/19324))
1920 * Improve the handling of "iteration dependent" errors and notes in finally clauses (Christoph Tyralla, PR [19270](https://github.com/python/mypy/pull/19270))
1921 * Lessen dmypy suggest path limitations for Windows machines (CoolCat467, PR [19337](https://github.com/python/mypy/pull/19337))
1922 * Fix type ignore comments erroneously marked as unused by dmypy (Charlie Denton, PR [15043](https://github.com/python/mypy/pull/15043))
1923 * Fix misspelled `exhaustive-match` error code (johnthagen, PR [19276](https://github.com/python/mypy/pull/19276))
1924 * Fix missing error context for unpacking assignment involving star expression (Brian Schubert, PR [19258](https://github.com/python/mypy/pull/19258))
1925 * Fix and simplify error de-duplication (Ivan Levkivskyi, PR [19247](https://github.com/python/mypy/pull/19247))
1926 * Disallow `ClassVar` in type aliases (Brian Schubert, PR [19263](https://github.com/python/mypy/pull/19263))
1927 * Add script that prints list of compiled files when compiling mypy (Jukka Lehtosalo, PR [19260](https://github.com/python/mypy/pull/19260))
1928 * Fix help message url for "None and Optional handling" section (Guy Wilson, PR [19252](https://github.com/python/mypy/pull/19252))
1929 * Display fully qualified name of imported base classes in errors about incompatible overrides (Mikhail Golubev, PR [19115](https://github.com/python/mypy/pull/19115))
1930 * Avoid false `unreachable`, `redundant-expr`, and `redundant-casts` warnings in loops more robustly and efficiently, and avoid multiple `revealed type` notes for the same line (Christoph Tyralla, PR [19118](https://github.com/python/mypy/pull/19118))
1931 * Fix type extraction from `isinstance` checks (Stanislav Terliakov, PR [19223](https://github.com/python/mypy/pull/19223))
1932 * Erase stray type variables in `functools.partial` (Stanislav Terliakov, PR [18954](https://github.com/python/mypy/pull/18954))
1933 * Make inferring condition value recognize the whole truth table (Stanislav Terliakov, PR [18944](https://github.com/python/mypy/pull/18944))
1934 * Support type aliases, `NamedTuple` and `TypedDict` in constrained TypeVar defaults (Stanislav Terliakov, PR [18884](https://github.com/python/mypy/pull/18884))
1935 * Move dataclass `kw_only` fields to the end of the signature (Stanislav Terliakov, PR [19018](https://github.com/python/mypy/pull/19018))
1936 * Provide a better fallback value for the `python_version` option (Marc Mueller, PR [19162](https://github.com/python/mypy/pull/19162))
1937 * Avoid spurious non-overlapping equality error with metaclass with `__eq__` (Michael J. Sullivan, PR [19220](https://github.com/python/mypy/pull/19220))
1938 * Narrow type variable bounds (Ivan Levkivskyi, PR [19183](https://github.com/python/mypy/pull/19183))
1939 * Add classifier for Python 3.14 (Marc Mueller, PR [19199](https://github.com/python/mypy/pull/19199))
1940 * Capitalize syntax error messages (Charulata, PR [19114](https://github.com/python/mypy/pull/19114))
1941 * Infer constraints eagerly if actual is Any (Ivan Levkivskyi, PR [19190](https://github.com/python/mypy/pull/19190))
1942 * Include walrus assignments in conditional inference (Stanislav Terliakov, PR [19038](https://github.com/python/mypy/pull/19038))
1943 * Use PEP 604 syntax when converting types to strings (Marc Mueller, PR [19179](https://github.com/python/mypy/pull/19179))
1944 * Use more lower-case builtin types in error messages (Marc Mueller, PR [19177](https://github.com/python/mypy/pull/19177))
1945 * Fix example to use correct method of Stack (Łukasz Kwieciński, PR [19123](https://github.com/python/mypy/pull/19123))
1946 * Forbid `.pop` of `Readonly` `NotRequired` TypedDict items (Stanislav Terliakov, PR [19133](https://github.com/python/mypy/pull/19133))
1947 * Emit a friendlier warning on invalid exclude regex, instead of a stacktrace (wyattscarpenter, PR [19102](https://github.com/python/mypy/pull/19102))
1948 * Enable ANSI color codes for dmypy client in Windows (wyattscarpenter, PR [19088](https://github.com/python/mypy/pull/19088))
1949 * Extend special case for context-based type variable inference to unions in return position (Stanislav Terliakov, PR [18976](https://github.com/python/mypy/pull/18976))
1950
1951 ### Mypy 1.17.1
1952 * Retain `None` as constraints bottom if no bottoms were provided (Stanislav Terliakov, PR [19485](https://github.com/python/mypy/pull/19485))
1953 * Fix "ignored exception in `hasattr`" in dmypy (Stanislav Terliakov, PR [19428](https://github.com/python/mypy/pull/19428))
1954 * Prevent a crash when InitVar is redefined with a method in a subclass (Stanislav Terliakov, PR [19453](https://github.com/python/mypy/pull/19453))
1955
1956 ### Acknowledgements
1957
1958 Thanks to all mypy contributors who contributed to this release:
1959
1960 * Alexey Makridenko
1961 * Brian Schubert
1962 * Chad Dombrova
1963 * Chainfire
1964 * Charlie Denton
1965 * Charulata
1966 * Christoph Tyralla
1967 * CoolCat467
1968 * Donal Burns
1969 * Guy Wilson
1970 * Ivan Levkivskyi
1971 * johnthagen
1972 * Jukka Lehtosalo
1973 * Łukasz Kwieciński
1974 * Marc Mueller
1975 * Michael J. Sullivan
1976 * Mikhail Golubev
1977 * Sebastian Rittau
1978 * Shantanu
1979 * Stanislav Terliakov
1980 * wyattscarpenter
1981
1982 I’d also like to thank my employer, Dropbox, for supporting mypy development.
1983
1984 ## Mypy 1.16
1985
1986 We’ve just uploaded mypy 1.16 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).
1987 Mypy is a static type checker for Python. This release includes new features and bug fixes.
1988 You can install it as follows:
1989
1990 python3 -m pip install -U mypy
1991
1992 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
1993
1994 ### Different Property Getter and Setter Types
1995
1996 Mypy now supports using different types for a property getter and setter:
1997
1998 ```python
1999 class A:
2000 _value: int
2001
2002 @property
2003 def foo(self) -> int:
2004 return self._value
2005
2006 @foo.setter
2007 def foo(self, x: str | int) -> None:
2008 try:
2009 self._value = int(x)
2010 except ValueError:
2011 raise Exception(f"'{x}' is not a valid value for 'foo'")
2012 ```
2013 This was contributed by Ivan Levkivskyi (PR [18510](https://github.com/python/mypy/pull/18510)).
2014
2015 ### Flexible Variable Redefinitions (Experimental)
2016
2017 Mypy now allows unannotated variables to be freely redefined with
2018 different types when using the experimental `--allow-redefinition-new`
2019 flag. You will also need to enable `--local-partial-types`. Mypy will
2020 now infer a union type when different types are assigned to a
2021 variable:
2022
2023 ```py
2024 # mypy: allow-redefinition-new, local-partial-types
2025
2026 def f(n: int, b: bool) -> int | str:
2027 if b:
2028 x = n
2029 else:
2030 x = str(n)
2031 # Type of 'x' is int | str here.
2032 return x
2033 ```
2034
2035 Without the new flag, mypy only supports inferring optional types (`X
2036 | None`) from multiple assignments, but now mypy can infer arbitrary
2037 union types.
2038
2039 An unannotated variable can now also have different types in different
2040 code locations:
2041
2042 ```py
2043 # mypy: allow-redefinition-new, local-partial-types
2044 ...
2045
2046 if cond():
2047 for x in range(n):
2048 # Type of 'x' is 'int' here
2049 ...
2050 else:
2051 for x in ['a', 'b']:
2052 # Type of 'x' is 'str' here
2053 ...
2054 ```
2055
2056 We are planning to turn this flag on by default in mypy 2.0, along
2057 with `--local-partial-types`. The feature is still experimental and
2058 has known issues, and the semantics may still change in the
2059 future. You may need to update or add type annotations when switching
2060 to the new behavior, but if you encounter anything unexpected, please
2061 create a GitHub issue.
2062
2063 This was contributed by Jukka Lehtosalo
2064 (PR [18727](https://github.com/python/mypy/pull/18727), PR [19153](https://github.com/python/mypy/pull/19153)).
2065
2066 ### Stricter Type Checking with Imprecise Types
2067
2068 Mypy can now detect additional errors in code that uses `Any` types or has missing function annotations.
2069
2070 When calling `dict.get(x, None)` on an object of type `dict[str, Any]`, this
2071 now results in an optional type (in the past it was `Any`):
2072
2073 ```python
2074 def f(d: dict[str, Any]) -> int:
2075 # Error: Return value has type "Any | None" but expected "int"
2076 return d.get("x", None)
2077 ```
2078
2079 Type narrowing using assignments can result in more precise types in
2080 the presence of `Any` types:
2081
2082 ```python
2083 def foo(): ...
2084
2085 def bar(n: int) -> None:
2086 x = foo()
2087 # Type of 'x' is 'Any' here
2088 if n > 5:
2089 x = str(n)
2090 # Type of 'x' is 'str' here
2091 ```
2092
2093 When using `--check-untyped-defs`, unannotated overrides are now
2094 checked more strictly against superclass definitions.
2095
2096 Related PRs:
2097
2098 * Use union types instead of join in binder (Ivan Levkivskyi, PR [18538](https://github.com/python/mypy/pull/18538))
2099 * Check superclass compatibility of untyped methods if `--check-untyped-defs` is set (Stanislav Terliakov, PR [18970](https://github.com/python/mypy/pull/18970))
2100
2101 ### Improvements to Attribute Resolution
2102
2103 This release includes several fixes to inconsistent resolution of attribute, method and descriptor types.
2104
2105 * Consolidate descriptor handling (Ivan Levkivskyi, PR [18831](https://github.com/python/mypy/pull/18831))
2106 * Make multiple inheritance checking use common semantics (Ivan Levkivskyi, PR [18876](https://github.com/python/mypy/pull/18876))
2107 * Make method override checking use common semantics (Ivan Levkivskyi, PR [18870](https://github.com/python/mypy/pull/18870))
2108 * Fix descriptor overload selection (Ivan Levkivskyi, PR [18868](https://github.com/python/mypy/pull/18868))
2109 * Handle union types when binding `self` (Ivan Levkivskyi, PR [18867](https://github.com/python/mypy/pull/18867))
2110 * Make variable override checking use common semantics (Ivan Levkivskyi, PR [18847](https://github.com/python/mypy/pull/18847))
2111 * Make descriptor handling behave consistently (Ivan Levkivskyi, PR [18831](https://github.com/python/mypy/pull/18831))
2112
2113 ### Make Implementation for Abstract Overloads Optional
2114
2115 The implementation can now be omitted for abstract overloaded methods,
2116 even outside stubs:
2117
2118 ```py
2119 from abc import abstractmethod
2120 from typing import overload
2121
2122 class C:
2123 @abstractmethod
2124 @overload
2125 def foo(self, x: int) -> int: ...
2126
2127 @abstractmethod
2128 @overload
2129 def foo(self, x: str) -> str: ...
2130
2131 # No implementation required for "foo"
2132 ```
2133
2134 This was contributed by Ivan Levkivskyi (PR [18882](https://github.com/python/mypy/pull/18882)).
2135
2136 ### Option to Exclude Everything in .gitignore
2137
2138 You can now use `--exclude-gitignore` to exclude everything in a
2139 `.gitignore` file from the mypy build. This behaves similar to
2140 excluding the paths using `--exclude`. We might enable this by default
2141 in a future mypy release.
2142
2143 This was contributed by Ivan Levkivskyi (PR [18696](https://github.com/python/mypy/pull/18696)).
2144
2145 ### Selectively Disable Deprecated Warnings
2146
2147 It's now possible to selectively disable warnings generated from
2148 [`warnings.deprecated`](https://docs.python.org/3/library/warnings.html#warnings.deprecated)
2149 using the [`--deprecated-calls-exclude`](https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-deprecated-calls-exclude)
2150 option:
2151
2152 ```python
2153 # mypy --enable-error-code deprecated
2154 # --deprecated-calls-exclude=foo.A
2155 import foo
2156
2157 foo.A().func() # OK, the deprecated warning is ignored
2158 ```
2159
2160 ```python
2161 # file foo.py
2162
2163 from typing_extensions import deprecated
2164
2165 class A:
2166 @deprecated("Use A.func2 instead")
2167 def func(self): pass
2168
2169 ...
2170 ```
2171
2172 Contributed by Marc Mueller (PR [18641](https://github.com/python/mypy/pull/18641))
2173
2174 ### Annotating Native/Non-Native Classes in Mypyc
2175
2176 You can now declare a class as a non-native class when compiling with
2177 mypyc. Unlike native classes, which are extension classes and have an
2178 immutable structure, non-native classes are normal Python classes at
2179 runtime and are fully dynamic. Example:
2180
2181 ```python
2182 from mypy_extensions import mypyc_attr
2183
2184 @mypyc_attr(native_class=False)
2185 class NonNativeClass:
2186 ...
2187
2188 o = NonNativeClass()
2189
2190 # Ok, even if attribute "foo" not declared in class body
2191 setattr(o, "foo", 1)
2192 ```
2193
2194 Classes are native by default in compiled modules, but classes that
2195 use certain features (such as most metaclasses) are implicitly
2196 non-native.
2197
2198 You can also explicitly declare a class as native. In this case mypyc
2199 will generate an error if it can't compile the class as a native
2200 class, instead of falling back to a non-native class:
2201
2202 ```python
2203 from mypy_extensions import mypyc_attr
2204 from foo import MyMeta
2205
2206 # Error: Unsupported metaclass for a native class
2207 @mypyc_attr(native_class=True)
2208 class C(metaclass=MyMeta):
2209 ...
2210 ```
2211
2212 Since native classes are significantly more efficient that non-native
2213 classes, you may want to ensure that certain classes always compiled
2214 as native classes.
2215
2216 This feature was contributed by Valentin Stanciu (PR [18802](https://github.com/python/mypy/pull/18802)).
2217
2218 ### Mypyc Fixes and Improvements
2219
2220 * Improve documentation of native and non-native classes (Jukka Lehtosalo, PR [19154](https://github.com/python/mypy/pull/19154))
2221 * Fix compilation when using Python 3.13 debug build (Valentin Stanciu, PR [19045](https://github.com/python/mypy/pull/19045))
2222 * Show the reason why a class can't be a native class (Valentin Stanciu, PR [19016](https://github.com/python/mypy/pull/19016))
2223 * Support await/yield while temporary values are live (Michael J. Sullivan, PR [16305](https://github.com/python/mypy/pull/16305))
2224 * Fix spilling values with overlapping error values (Jukka Lehtosalo, PR [18961](https://github.com/python/mypy/pull/18961))
2225 * Fix reference count of spilled register in async def (Jukka Lehtosalo, PR [18957](https://github.com/python/mypy/pull/18957))
2226 * Add basic optimization for `sorted` (Marc Mueller, PR [18902](https://github.com/python/mypy/pull/18902))
2227 * Fix access of class object in a type annotation (Advait Dixit, PR [18874](https://github.com/python/mypy/pull/18874))
2228 * Optimize `list.__imul__` and `tuple.__mul__ `(Marc Mueller, PR [18887](https://github.com/python/mypy/pull/18887))
2229 * Optimize `list.__add__`, `list.__iadd__` and `tuple.__add__` (Marc Mueller, PR [18845](https://github.com/python/mypy/pull/18845))
2230 * Add and implement primitive `list.copy()` (exertustfm, PR [18771](https://github.com/python/mypy/pull/18771))
2231 * Optimize `builtins.repr` (Marc Mueller, PR [18844](https://github.com/python/mypy/pull/18844))
2232 * Support iterating over keys/values/items of dict-bound TypeVar and ParamSpec.kwargs (Stanislav Terliakov, PR [18789](https://github.com/python/mypy/pull/18789))
2233 * Add efficient primitives for `str.strip()` etc. (Advait Dixit, PR [18742](https://github.com/python/mypy/pull/18742))
2234 * Document that `strip()` etc. are optimized (Jukka Lehtosalo, PR [18793](https://github.com/python/mypy/pull/18793))
2235 * Fix mypyc crash with enum type aliases (Valentin Stanciu, PR [18725](https://github.com/python/mypy/pull/18725))
2236 * Optimize `str.find` and `str.rfind` (Marc Mueller, PR [18709](https://github.com/python/mypy/pull/18709))
2237 * Optimize `str.__contains__` (Marc Mueller, PR [18705](https://github.com/python/mypy/pull/18705))
2238 * Fix order of steal/unborrow in tuple unpacking (Ivan Levkivskyi, PR [18732](https://github.com/python/mypy/pull/18732))
2239 * Optimize `str.partition` and `str.rpartition` (Marc Mueller, PR [18702](https://github.com/python/mypy/pull/18702))
2240 * Optimize `str.startswith` and `str.endswith` with tuple argument (Marc Mueller, PR [18678](https://github.com/python/mypy/pull/18678))
2241 * Improve `str.startswith` and `str.endswith` with tuple argument (Marc Mueller, PR [18703](https://github.com/python/mypy/pull/18703))
2242 * `pythoncapi_compat`: don't define Py_NULL if it is already defined (Michael R. Crusoe, PR [18699](https://github.com/python/mypy/pull/18699))
2243 * Optimize `str.splitlines` (Marc Mueller, PR [18677](https://github.com/python/mypy/pull/18677))
2244 * Mark `dict.setdefault` as optimized (Marc Mueller, PR [18685](https://github.com/python/mypy/pull/18685))
2245 * Support `__del__` methods (Advait Dixit, PR [18519](https://github.com/python/mypy/pull/18519))
2246 * Optimize `str.rsplit` (Marc Mueller, PR [18673](https://github.com/python/mypy/pull/18673))
2247 * Optimize `str.removeprefix` and `str.removesuffix` (Marc Mueller, PR [18672](https://github.com/python/mypy/pull/18672))
2248 * Recognize literal types in `__match_args__` (Stanislav Terliakov, PR [18636](https://github.com/python/mypy/pull/18636))
2249 * Fix non extension classes with attribute annotations using forward references (Valentin Stanciu, PR [18577](https://github.com/python/mypy/pull/18577))
2250 * Use lower-case generic types such as `list[t]` in documentation (Jukka Lehtosalo, PR [18576](https://github.com/python/mypy/pull/18576))
2251 * Improve support for `frozenset` (Marc Mueller, PR [18571](https://github.com/python/mypy/pull/18571))
2252 * Fix wheel build for cp313-win (Marc Mueller, PR [18560](https://github.com/python/mypy/pull/18560))
2253 * Reduce impact of immortality (introduced in Python 3.12) on reference counting performance (Jukka Lehtosalo, PR [18459](https://github.com/python/mypy/pull/18459))
2254 * Update math error messages for 3.14 (Marc Mueller, PR [18534](https://github.com/python/mypy/pull/18534))
2255 * Update math error messages for 3.14 (2) (Marc Mueller, PR [18949](https://github.com/python/mypy/pull/18949))
2256 * Replace deprecated `_PyLong_new` with `PyLongWriter` API (Marc Mueller, PR [18532](https://github.com/python/mypy/pull/18532))
2257
2258 ### Fixes to Crashes
2259
2260 * Traverse module ancestors when traversing reachable graph nodes during dmypy update (Stanislav Terliakov, PR [18906](https://github.com/python/mypy/pull/18906))
2261 * Fix crash on multiple unpacks in a bare type application (Stanislav Terliakov, PR [18857](https://github.com/python/mypy/pull/18857))
2262 * Prevent crash when enum/TypedDict call is stored as a class attribute (Stanislav Terliakov, PR [18861](https://github.com/python/mypy/pull/18861))
2263 * Fix crash on multiple unpacks in a bare type application (Stanislav Terliakov, PR [18857](https://github.com/python/mypy/pull/18857))
2264 * Fix crash on type inference against non-normal callables (Ivan Levkivskyi, PR [18858](https://github.com/python/mypy/pull/18858))
2265 * Fix crash on decorated getter in settable property (Ivan Levkivskyi, PR [18787](https://github.com/python/mypy/pull/18787))
2266 * Fix crash on callable with `*args` and suffix against Any (Ivan Levkivskyi, PR [18781](https://github.com/python/mypy/pull/18781))
2267 * Fix crash on deferred supertype and setter override (Ivan Levkivskyi, PR [18649](https://github.com/python/mypy/pull/18649))
2268 * Fix crashes on incorrectly detected recursive aliases (Ivan Levkivskyi, PR [18625](https://github.com/python/mypy/pull/18625))
2269 * Report that `NamedTuple` and `dataclass` are incompatile instead of crashing (Christoph Tyralla, PR [18633](https://github.com/python/mypy/pull/18633))
2270 * Fix mypy daemon crash (Valentin Stanciu, PR [19087](https://github.com/python/mypy/pull/19087))
2271
2272 ### Performance Improvements
2273
2274 These are specific to mypy. Mypyc-related performance improvements are discussed elsewhere.
2275
2276 * Speed up binding `self` in trivial cases (Ivan Levkivskyi, PR [19024](https://github.com/python/mypy/pull/19024))
2277 * Small constraint solver optimization (Aaron Gokaslan, PR [18688](https://github.com/python/mypy/pull/18688))
2278
2279 ### Documentation Updates
2280
2281 * Improve documentation of `--strict` (lenayoung8, PR [18903](https://github.com/python/mypy/pull/18903))
2282 * Remove a note about `from __future__ import annotations` (Ageev Maxim, PR [18915](https://github.com/python/mypy/pull/18915))
2283 * Improve documentation on type narrowing (Tim Hoffmann, PR [18767](https://github.com/python/mypy/pull/18767))
2284 * Fix metaclass usage example (Georg, PR [18686](https://github.com/python/mypy/pull/18686))
2285 * Update documentation on `extra_checks` flag (Ivan Levkivskyi, PR [18537](https://github.com/python/mypy/pull/18537))
2286
2287 ### Stubgen Improvements
2288
2289 * Fix `TypeAlias` handling (Alexey Makridenko, PR [18960](https://github.com/python/mypy/pull/18960))
2290 * Handle `arg=None` in C extension modules (Anthony Sottile, PR [18768](https://github.com/python/mypy/pull/18768))
2291 * Fix valid type detection to allow pipe unions (Chad Dombrova, PR [18726](https://github.com/python/mypy/pull/18726))
2292 * Include simple decorators in stub files (Marc Mueller, PR [18489](https://github.com/python/mypy/pull/18489))
2293 * Support positional and keyword-only arguments in stubdoc (Paul Ganssle, PR [18762](https://github.com/python/mypy/pull/18762))
2294 * Fall back to `Incomplete` if we are unable to determine the module name (Stanislav Terliakov, PR [19084](https://github.com/python/mypy/pull/19084))
2295
2296 ### Stubtest Improvements
2297
2298 * Make stubtest ignore `__slotnames__` (Nick Pope, PR [19077](https://github.com/python/mypy/pull/19077))
2299 * Fix stubtest tests on 3.14 (Jelle Zijlstra, PR [19074](https://github.com/python/mypy/pull/19074))
2300 * Support for `strict_bytes` in stubtest (Joren Hammudoglu, PR [19002](https://github.com/python/mypy/pull/19002))
2301 * Understand override (Shantanu, PR [18815](https://github.com/python/mypy/pull/18815))
2302 * Better checking of runtime arguments with dunder names (Shantanu, PR [18756](https://github.com/python/mypy/pull/18756))
2303 * Ignore setattr and delattr inherited from object (Stephen Morton, PR [18325](https://github.com/python/mypy/pull/18325))
2304
2305 ### Miscellaneous Fixes and Improvements
2306
2307 * Add `--strict-bytes` to `--strict` (wyattscarpenter, PR [19049](https://github.com/python/mypy/pull/19049))
2308 * Admit that Final variables are never redefined (Stanislav Terliakov, PR [19083](https://github.com/python/mypy/pull/19083))
2309 * Add special support for `@django.cached_property` needed in `django-stubs` (sobolevn, PR [18959](https://github.com/python/mypy/pull/18959))
2310 * Do not narrow types to `Never` with binder (Ivan Levkivskyi, PR [18972](https://github.com/python/mypy/pull/18972))
2311 * Local forward references should precede global forward references (Ivan Levkivskyi, PR [19000](https://github.com/python/mypy/pull/19000))
2312 * Do not cache module lookup results in incremental mode that may become invalid (Stanislav Terliakov, PR [19044](https://github.com/python/mypy/pull/19044))
2313 * Only consider meta variables in ambiguous "any of" constraints (Stanislav Terliakov, PR [18986](https://github.com/python/mypy/pull/18986))
2314 * Allow accessing `__init__` on final classes and when `__init__` is final (Stanislav Terliakov, PR [19035](https://github.com/python/mypy/pull/19035))
2315 * Treat varargs as positional-only (A5rocks, PR [19022](https://github.com/python/mypy/pull/19022))
2316 * Enable colored output for argparse help in Python 3.14 (Marc Mueller, PR [19021](https://github.com/python/mypy/pull/19021))
2317 * Fix argparse for Python 3.14 (Marc Mueller, PR [19020](https://github.com/python/mypy/pull/19020))
2318 * `dmypy suggest` can now suggest through contextmanager-based decorators (Anthony Sottile, PR [18948](https://github.com/python/mypy/pull/18948))
2319 * Fix `__r<magic_methods>__` being used under the same `__<magic_method>__` hook (Arnav Jain, PR [18995](https://github.com/python/mypy/pull/18995))
2320 * Prioritize `.pyi` from `-stubs` packages over bundled `.pyi` (Joren Hammudoglu, PR [19001](https://github.com/python/mypy/pull/19001))
2321 * Fix missing subtype check case for `type[T]` (Stanislav Terliakov, PR [18975](https://github.com/python/mypy/pull/18975))
2322 * Fixes to the detection of redundant casts (Anthony Sottile, PR [18588](https://github.com/python/mypy/pull/18588))
2323 * Make some parse errors non-blocking (Shantanu, PR [18941](https://github.com/python/mypy/pull/18941))
2324 * Fix PEP 695 type alias with a mix of type arguments (PEP 696) (Marc Mueller, PR [18919](https://github.com/python/mypy/pull/18919))
2325 * Allow deeper recursion in mypy daemon, better error reporting (Carter Dodd, PR [17707](https://github.com/python/mypy/pull/17707))
2326 * Fix swapped errors for frozen/non-frozen dataclass inheritance (Nazrawi Demeke, PR [18918](https://github.com/python/mypy/pull/18918))
2327 * Fix incremental issue with namespace packages (Shantanu, PR [18907](https://github.com/python/mypy/pull/18907))
2328 * Exclude irrelevant members when narrowing union overlapping with enum (Stanislav Terliakov, PR [18897](https://github.com/python/mypy/pull/18897))
2329 * Flatten union before contracting literals when checking subtyping (Stanislav Terliakov, PR [18898](https://github.com/python/mypy/pull/18898))
2330 * Do not add `kw_only` dataclass fields to `__match_args__` (sobolevn, PR [18892](https://github.com/python/mypy/pull/18892))
2331 * Fix error message when returning long tuple with type mismatch (Thomas Mattone, PR [18881](https://github.com/python/mypy/pull/18881))
2332 * Treat `TypedDict` (old-style) aliases as regular `TypedDict`s (Stanislav Terliakov, PR [18852](https://github.com/python/mypy/pull/18852))
2333 * Warn about unused `type: ignore` comments when error code is disabled (Brian Schubert, PR [18849](https://github.com/python/mypy/pull/18849))
2334 * Reject duplicate `ParamSpec.{args,kwargs}` at call site (Stanislav Terliakov, PR [18854](https://github.com/python/mypy/pull/18854))
2335 * Make detection of enum members more consistent (sobolevn, PR [18675](https://github.com/python/mypy/pull/18675))
2336 * Admit that `**kwargs` mapping subtypes may have no direct type parameters (Stanislav Terliakov, PR [18850](https://github.com/python/mypy/pull/18850))
2337 * Don't suggest `types-setuptools` for `pkg_resources` (Shantanu, PR [18840](https://github.com/python/mypy/pull/18840))
2338 * Suggest `scipy-stubs` for `scipy` as non-typeshed stub package (Joren Hammudoglu, PR [18832](https://github.com/python/mypy/pull/18832))
2339 * Narrow tagged unions in match statements (Gene Parmesan Thomas, PR [18791](https://github.com/python/mypy/pull/18791))
2340 * Consistently store settable property type (Ivan Levkivskyi, PR [18774](https://github.com/python/mypy/pull/18774))
2341 * Do not blindly undefer on leaving function (Ivan Levkivskyi, PR [18674](https://github.com/python/mypy/pull/18674))
2342 * Process superclass methods before subclass methods in semanal (Ivan Levkivskyi, PR [18723](https://github.com/python/mypy/pull/18723))
2343 * Only defer top-level functions (Ivan Levkivskyi, PR [18718](https://github.com/python/mypy/pull/18718))
2344 * Add one more type-checking pass (Ivan Levkivskyi, PR [18717](https://github.com/python/mypy/pull/18717))
2345 * Properly account for `member` and `nonmember` in enums (sobolevn, PR [18559](https://github.com/python/mypy/pull/18559))
2346 * Fix instance vs tuple subtyping edge case (Ivan Levkivskyi, PR [18664](https://github.com/python/mypy/pull/18664))
2347 * Improve handling of Any/object in variadic generics (Ivan Levkivskyi, PR [18643](https://github.com/python/mypy/pull/18643))
2348 * Fix handling of named tuples in class match pattern (Ivan Levkivskyi, PR [18663](https://github.com/python/mypy/pull/18663))
2349 * Fix regression for user config files (Shantanu, PR [18656](https://github.com/python/mypy/pull/18656))
2350 * Fix dmypy socket issue on GNU/Hurd (Mattias Ellert, PR [18630](https://github.com/python/mypy/pull/18630))
2351 * Don't assume that for loop body index variable is always set (Jukka Lehtosalo, PR [18631](https://github.com/python/mypy/pull/18631))
2352 * Fix overlap check for variadic generics (Ivan Levkivskyi, PR [18638](https://github.com/python/mypy/pull/18638))
2353 * Improve support for `functools.partial` of overloaded callable protocol (Shantanu, PR [18639](https://github.com/python/mypy/pull/18639))
2354 * Allow lambdas in `except*` clauses (Stanislav Terliakov, PR [18620](https://github.com/python/mypy/pull/18620))
2355 * Fix trailing commas in many multiline string options in `pyproject.toml` (sobolevn, PR [18624](https://github.com/python/mypy/pull/18624))
2356 * Allow trailing commas for `files` setting in `mypy.ini` and `setup.ini` (sobolevn, PR [18621](https://github.com/python/mypy/pull/18621))
2357 * Fix "not callable" issue for `@dataclass(frozen=True)` with `Final` attr (sobolevn, PR [18572](https://github.com/python/mypy/pull/18572))
2358 * Add missing TypedDict special case when checking member access (Stanislav Terliakov, PR [18604](https://github.com/python/mypy/pull/18604))
2359 * Use lower case `list` and `dict` in invariance notes (Jukka Lehtosalo, PR [18594](https://github.com/python/mypy/pull/18594))
2360 * Fix inference when class and instance match protocol (Ivan Levkivskyi, PR [18587](https://github.com/python/mypy/pull/18587))
2361 * Remove support for `builtins.Any` (Marc Mueller, PR [18578](https://github.com/python/mypy/pull/18578))
2362 * Update the overlapping check for tuples to account for NamedTuples (A5rocks, PR [18564](https://github.com/python/mypy/pull/18564))
2363 * Fix `@deprecated` (PEP 702) with normal overloaded methods (Christoph Tyralla, PR [18477](https://github.com/python/mypy/pull/18477))
2364 * Start propagating end columns/lines for `type-arg` errors (A5rocks, PR [18533](https://github.com/python/mypy/pull/18533))
2365 * Improve handling of `type(x) is Foo` checks (Stanislav Terliakov, PR [18486](https://github.com/python/mypy/pull/18486))
2366 * Suggest `typing.Literal` for exit-return error messages (Marc Mueller, PR [18541](https://github.com/python/mypy/pull/18541))
2367 * Allow redefinitions in except/else/finally (Stanislav Terliakov, PR [18515](https://github.com/python/mypy/pull/18515))
2368 * Disallow setting Python version using inline config (Shantanu, PR [18497](https://github.com/python/mypy/pull/18497))
2369 * Improve type inference in tuple multiplication plugin (Shantanu, PR [18521](https://github.com/python/mypy/pull/18521))
2370 * Add missing line number to `yield from` with wrong type (Stanislav Terliakov, PR [18518](https://github.com/python/mypy/pull/18518))
2371 * Hint at argument names when formatting callables with compatible return types in error messages (Stanislav Terliakov, PR [18495](https://github.com/python/mypy/pull/18495))
2372 * Add better naming and improve compatibility for ad hoc intersections of instances (Christoph Tyralla, PR [18506](https://github.com/python/mypy/pull/18506))
2373
2374 ### Acknowledgements
2375
2376 Thanks to all mypy contributors who contributed to this release:
2377
2378 - A5rocks
2379 - Aaron Gokaslan
2380 - Advait Dixit
2381 - Ageev Maxim
2382 - Alexey Makridenko
2383 - Ali Hamdan
2384 - Anthony Sottile
2385 - Arnav Jain
2386 - Brian Schubert
2387 - bzoracler
2388 - Carter Dodd
2389 - Chad Dombrova
2390 - Christoph Tyralla
2391 - Dimitri Papadopoulos Orfanos
2392 - Emma Smith
2393 - exertustfm
2394 - Gene Parmesan Thomas
2395 - Georg
2396 - Ivan Levkivskyi
2397 - Jared Hance
2398 - Jelle Zijlstra
2399 - Joren Hammudoglu
2400 - lenayoung8
2401 - Marc Mueller
2402 - Mattias Ellert
2403 - Michael J. Sullivan
2404 - Michael R. Crusoe
2405 - Nazrawi Demeke
2406 - Nick Pope
2407 - Paul Ganssle
2408 - Shantanu
2409 - sobolevn
2410 - Stanislav Terliakov
2411 - Stephen Morton
2412 - Thomas Mattone
2413 - Tim Hoffmann
2414 - Tim Ruffing
2415 - Valentin Stanciu
2416 - Wesley Collin Wright
2417 - wyattscarpenter
2418
2419 I’d also like to thank my employer, Dropbox, for supporting mypy development.
2420
2421 ## Mypy 1.15
2422
2423 We’ve just uploaded mypy 1.15 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).
2424 Mypy is a static type checker for Python. This release includes new features, performance
2425 improvements and bug fixes. You can install it as follows:
2426
2427 python3 -m pip install -U mypy
2428
2429 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
2430
2431 ### Performance Improvements
2432
2433 Mypy is up to 40% faster in some use cases. This improvement comes largely from tuning the performance
2434 of the garbage collector. Additionally, the release includes several micro-optimizations that may
2435 be impactful for large projects.
2436
2437 Contributed by Jukka Lehtosalo
2438 - PR [18306](https://github.com/python/mypy/pull/18306)
2439 - PR [18302](https://github.com/python/mypy/pull/18302)
2440 - PR [18298](https://github.com/python/mypy/pull/18298)
2441 - PR [18299](https://github.com/python/mypy/pull/18299)
2442
2443 ### Mypyc Accelerated Mypy Wheels for ARM Linux
2444
2445 For best performance, mypy can be compiled to C extension modules using mypyc. This makes
2446 mypy 3-5x faster than when interpreted with pure Python. We now build and upload mypyc
2447 accelerated mypy wheels for `manylinux_aarch64` to PyPI, making it easy for Linux users on
2448 ARM platforms to realise this speedup -- just `pip install` the latest mypy.
2449
2450 Contributed by Christian Bundy and Marc Mueller
2451 (PR [mypy_mypyc-wheels#76](https://github.com/mypyc/mypy_mypyc-wheels/pull/76),
2452 PR [mypy_mypyc-wheels#89](https://github.com/mypyc/mypy_mypyc-wheels/pull/89)).
2453
2454 ### `--strict-bytes`
2455
2456 By default, mypy treats `bytearray` and `memoryview` values as assignable to the `bytes`
2457 type, for historical reasons. Use the `--strict-bytes` flag to disable this
2458 behavior. [PEP 688](https://peps.python.org/pep-0688) specified the removal of this
2459 special case. The flag will be enabled by default in **mypy 2.0**.
2460
2461 Contributed by Ali Hamdan (PR [18263](https://github.com/python/mypy/pull/18263)) and
2462 Shantanu Jain (PR [13952](https://github.com/python/mypy/pull/13952)).
2463
2464 ### Improvements to Reachability Analysis and Partial Type Handling in Loops
2465
2466 This change results in mypy better modelling control flow within loops and hence detecting
2467 several previously ignored issues. In some cases, this change may require additional
2468 explicit variable annotations.
2469
2470 Contributed by Christoph Tyralla (PR [18180](https://github.com/python/mypy/pull/18180),
2471 PR [18433](https://github.com/python/mypy/pull/18433)).
2472
2473 (Speaking of partial types, remember that we plan to enable `--local-partial-types`
2474 by default in **mypy 2.0**.)
2475
2476 ### Better Discovery of Configuration Files
2477
2478 Mypy will now walk up the filesystem (up until a repository or file system root) to discover
2479 configuration files. See the
2480 [mypy configuration file documentation](https://mypy.readthedocs.io/en/stable/config_file.html)
2481 for more details.
2482
2483 Contributed by Mikhail Shiryaev and Shantanu Jain
2484 (PR [16965](https://github.com/python/mypy/pull/16965), PR [18482](https://github.com/python/mypy/pull/18482))
2485
2486 ### Better Line Numbers for Decorators and Slice Expressions
2487
2488 Mypy now uses more correct line numbers for decorators and slice expressions. In some cases,
2489 you may have to change the location of a `# type: ignore` comment.
2490
2491 Contributed by Shantanu Jain (PR [18392](https://github.com/python/mypy/pull/18392),
2492 PR [18397](https://github.com/python/mypy/pull/18397)).
2493
2494 ### Drop Support for Python 3.8
2495
2496 Mypy no longer supports running with Python 3.8, which has reached end-of-life.
2497 When running mypy with Python 3.9+, it is still possible to type check code
2498 that needs to support Python 3.8 with the `--python-version 3.8` argument.
2499 Support for this will be dropped in the first half of 2025!
2500
2501 Contributed by Marc Mueller (PR [17492](https://github.com/python/mypy/pull/17492)).
2502
2503 ### Mypyc Improvements
2504
2505 * Fix `__init__` for classes with `@attr.s(slots=True)` (Advait Dixit, PR [18447](https://github.com/python/mypy/pull/18447))
2506 * Report error for nested class instead of crashing (Valentin Stanciu, PR [18460](https://github.com/python/mypy/pull/18460))
2507 * Fix `InitVar` for dataclasses (Advait Dixit, PR [18319](https://github.com/python/mypy/pull/18319))
2508 * Remove unnecessary mypyc files from wheels (Marc Mueller, PR [18416](https://github.com/python/mypy/pull/18416))
2509 * Fix issues with relative imports (Advait Dixit, PR [18286](https://github.com/python/mypy/pull/18286))
2510 * Add faster primitive for some list get item operations (Jukka Lehtosalo, PR [18136](https://github.com/python/mypy/pull/18136))
2511 * Fix iteration over `NamedTuple` objects (Advait Dixit, PR [18254](https://github.com/python/mypy/pull/18254))
2512 * Mark mypyc package with `py.typed` (bzoracler, PR [18253](https://github.com/python/mypy/pull/18253))
2513 * Fix list index while checking for `Enum` class (Advait Dixit, PR [18426](https://github.com/python/mypy/pull/18426))
2514
2515 ### Stubgen Improvements
2516
2517 * Improve dataclass init signatures (Marc Mueller, PR [18430](https://github.com/python/mypy/pull/18430))
2518 * Preserve `dataclass_transform` decorator (Marc Mueller, PR [18418](https://github.com/python/mypy/pull/18418))
2519 * Fix `UnpackType` for 3.11+ (Marc Mueller, PR [18421](https://github.com/python/mypy/pull/18421))
2520 * Improve `self` annotations (Marc Mueller, PR [18420](https://github.com/python/mypy/pull/18420))
2521 * Print `InspectError` traceback in stubgen `walk_packages` when verbose is specified (Gareth, PR [18224](https://github.com/python/mypy/pull/18224))
2522
2523 ### Stubtest Improvements
2524
2525 * Fix crash with numpy array default values (Ali Hamdan, PR [18353](https://github.com/python/mypy/pull/18353))
2526 * Distinguish metaclass attributes from class attributes (Stephen Morton, PR [18314](https://github.com/python/mypy/pull/18314))
2527
2528 ### Fixes to Crashes
2529
2530 * Prevent crash with `Unpack` of a fixed tuple in PEP695 type alias (Stanislav Terliakov, PR [18451](https://github.com/python/mypy/pull/18451))
2531 * Fix crash with `--cache-fine-grained --cache-dir=/dev/null` (Shantanu, PR [18457](https://github.com/python/mypy/pull/18457))
2532 * Prevent crashing when `match` arms use name of existing callable (Stanislav Terliakov, PR [18449](https://github.com/python/mypy/pull/18449))
2533 * Gracefully handle encoding errors when writing to stdout (Brian Schubert, PR [18292](https://github.com/python/mypy/pull/18292))
2534 * Prevent crash on generic NamedTuple with unresolved typevar bound (Stanislav Terliakov, PR [18585](https://github.com/python/mypy/pull/18585))
2535
2536 ### Documentation Updates
2537
2538 * Add inline tabs to documentation (Marc Mueller, PR [18262](https://github.com/python/mypy/pull/18262))
2539 * Document any `TYPE_CHECKING` name works (Shantanu, PR [18443](https://github.com/python/mypy/pull/18443))
2540 * Update documentation to not mention 3.8 where possible (sobolevn, PR [18455](https://github.com/python/mypy/pull/18455))
2541 * Mention `ignore_errors` in exclude documentation (Shantanu, PR [18412](https://github.com/python/mypy/pull/18412))
2542 * Add `Self` misuse to common issues (Shantanu, PR [18261](https://github.com/python/mypy/pull/18261))
2543
2544 ### Other Notable Fixes and Improvements
2545
2546 * Fix literal context for ternary expressions (Ivan Levkivskyi, PR [18545](https://github.com/python/mypy/pull/18545))
2547 * Ignore `dataclass.__replace__` LSP violations (Marc Mueller, PR [18464](https://github.com/python/mypy/pull/18464))
2548 * Bind `self` to the class being defined when checking multiple inheritance (Stanislav Terliakov, PR [18465](https://github.com/python/mypy/pull/18465))
2549 * Fix attribute type resolution with multiple inheritance (Stanislav Terliakov, PR [18415](https://github.com/python/mypy/pull/18415))
2550 * Improve security of our GitHub Actions (sobolevn, PR [18413](https://github.com/python/mypy/pull/18413))
2551 * Unwrap `type[Union[...]]` when solving type variable constraints (Stanislav Terliakov, PR [18266](https://github.com/python/mypy/pull/18266))
2552 * Allow `Any` to match sequence patterns in match/case (Stanislav Terliakov, PR [18448](https://github.com/python/mypy/pull/18448))
2553 * Fix parent generics mapping when overriding generic attribute with property (Stanislav Terliakov, PR [18441](https://github.com/python/mypy/pull/18441))
2554 * Add dedicated error code for explicit `Any` (Shantanu, PR [18398](https://github.com/python/mypy/pull/18398))
2555 * Reject invalid `ParamSpec` locations (Stanislav Terliakov, PR [18278](https://github.com/python/mypy/pull/18278))
2556 * Stop suggesting stubs that have been removed from typeshed (Shantanu, PR [18373](https://github.com/python/mypy/pull/18373))
2557 * Allow inverting `--local-partial-types` (Shantanu, PR [18377](https://github.com/python/mypy/pull/18377))
2558 * Allow to use `Final` and `ClassVar` after Python 3.13 (정승원, PR [18358](https://github.com/python/mypy/pull/18358))
2559 * Update suggestions to include latest stubs in typeshed (Shantanu, PR [18366](https://github.com/python/mypy/pull/18366))
2560 * Fix `--install-types` masking failure details (wyattscarpenter, PR [17485](https://github.com/python/mypy/pull/17485))
2561 * Reject promotions when checking against protocols (Christoph Tyralla, PR [18360](https://github.com/python/mypy/pull/18360))
2562 * Don't erase type object arguments in diagnostics (Shantanu, PR [18352](https://github.com/python/mypy/pull/18352))
2563 * Clarify status in `dmypy status` output (Kcornw, PR [18331](https://github.com/python/mypy/pull/18331))
2564 * Disallow no-argument generic aliases when using PEP 613 explicit aliases (Brian Schubert, PR [18173](https://github.com/python/mypy/pull/18173))
2565 * Suppress errors for unreachable branches in conditional expressions (Brian Schubert, PR [18295](https://github.com/python/mypy/pull/18295))
2566 * Do not allow `ClassVar` and `Final` in `TypedDict` and `NamedTuple` (sobolevn, PR [18281](https://github.com/python/mypy/pull/18281))
2567 * Report error if not enough or too many types provided to `TypeAliasType` (bzoracler, PR [18308](https://github.com/python/mypy/pull/18308))
2568 * Use more precise context for `TypedDict` plugin errors (Brian Schubert, PR [18293](https://github.com/python/mypy/pull/18293))
2569 * Use more precise context for invalid type argument errors (Brian Schubert, PR [18290](https://github.com/python/mypy/pull/18290))
2570 * Do not allow `type[]` to contain `Literal` types (sobolevn, PR [18276](https://github.com/python/mypy/pull/18276))
2571 * Allow bytearray/bytes comparisons with `--strict-bytes` (Jukka Lehtosalo, PR [18255](https://github.com/python/mypy/pull/18255))
2572
2573 ### Acknowledgements
2574
2575 Thanks to all mypy contributors who contributed to this release:
2576
2577 - Advait Dixit
2578 - Ali Hamdan
2579 - Brian Schubert
2580 - bzoracler
2581 - Cameron Matsui
2582 - Christoph Tyralla
2583 - Gareth
2584 - Ivan Levkivskyi
2585 - Jukka Lehtosalo
2586 - Kcornw
2587 - Marc Mueller
2588 - Mikhail f. Shiryaev
2589 - Shantanu
2590 - sobolevn
2591 - Stanislav Terliakov
2592 - Stephen Morton
2593 - Valentin Stanciu
2594 - Viktor Szépe
2595 - wyattscarpenter
2596 - 정승원
2597
2598 I’d also like to thank my employer, Dropbox, for supporting mypy development.
2599
2600 ## Mypy 1.14
2601
2602 We’ve just uploaded mypy 1.14 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).
2603 Mypy is a static type checker for Python. This release includes new features and bug fixes.
2604 You can install it as follows:
2605
2606 python3 -m pip install -U mypy
2607
2608 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
2609
2610 ### Change to Enum Membership Semantics
2611
2612 As per the updated [typing specification for enums](https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members),
2613 enum members must be left unannotated.
2614
2615 ```python
2616 class Pet(Enum):
2617 CAT = 1 # Member attribute
2618 DOG = 2 # Member attribute
2619
2620 # New error: Enum members must be left unannotated
2621 WOLF: int = 3
2622
2623 species: str # Considered a non-member attribute
2624 ```
2625
2626 In particular, the specification change can result in issues in type stubs (`.pyi` files), since
2627 historically it was common to leave the value absent:
2628
2629 ```python
2630 # In a type stub (.pyi file)
2631
2632 class Pet(Enum):
2633 # Change in semantics: previously considered members,
2634 # now non-member attributes
2635 CAT: int
2636 DOG: int
2637
2638 # Mypy will now issue a warning if it detects this
2639 # situation in type stubs:
2640 # > Detected enum "Pet" in a type stub with zero
2641 # > members. There is a chance this is due to a recent
2642 # > change in the semantics of enum membership. If so,
2643 # > use `member = value` to mark an enum member,
2644 # > instead of `member: type`
2645
2646 class Pet(Enum):
2647 # As per the specification, you should now do one of
2648 # the following:
2649 DOG = 1 # Member attribute with value 1 and known type
2650 WOLF = cast(int, ...) # Member attribute with unknown
2651 # value but known type
2652 LION = ... # Member attribute with unknown value and
2653 # # unknown type
2654 ```
2655
2656 Contributed by Terence Honles (PR [17207](https://github.com/python/mypy/pull/17207)) and
2657 Shantanu Jain (PR [18068](https://github.com/python/mypy/pull/18068)).
2658
2659 ### Support for @deprecated Decorator (PEP 702)
2660
2661 Mypy can now issue errors or notes when code imports a deprecated feature
2662 explicitly with a `from mod import depr` statement, or uses a deprecated feature
2663 imported otherwise or defined locally. Features are considered deprecated when
2664 decorated with `warnings.deprecated`, as specified in [PEP 702](https://peps.python.org/pep-0702).
2665
2666 You can enable the error code via `--enable-error-code=deprecated` on the mypy
2667 command line or `enable_error_code = deprecated` in the mypy config file.
2668 Use the command line flag `--report-deprecated-as-note` or config file option
2669 `report_deprecated_as_note=True` to turn all such errors into notes.
2670
2671 Deprecation errors will be enabled by default in a future mypy version.
2672
2673 This feature was contributed by Christoph Tyralla.
2674
2675 List of changes:
2676
2677 * Add basic support for PEP 702 (`@deprecated`) (Christoph Tyralla, PR [17476](https://github.com/python/mypy/pull/17476))
2678 * Support descriptors with `@deprecated` (Christoph Tyralla, PR [18090](https://github.com/python/mypy/pull/18090))
2679 * Make "deprecated" note an error, disabled by default (Valentin Stanciu, PR [18192](https://github.com/python/mypy/pull/18192))
2680 * Consider all possible type positions with `@deprecated` (Christoph Tyralla, PR [17926](https://github.com/python/mypy/pull/17926))
2681 * Improve the handling of explicit type annotations in assignment statements with `@deprecated` (Christoph Tyralla, PR [17899](https://github.com/python/mypy/pull/17899))
2682
2683 ### Optionally Analyzing Untyped Modules
2684
2685 Mypy normally doesn't analyze imports from third-party modules (installed using pip, for example)
2686 if there are no stubs or a py.typed marker file. To force mypy to analyze these imports, you
2687 can now use the `--follow-untyped-imports` flag or set the `follow_untyped_imports`
2688 config file option to True. This can be set either in the global section of your mypy config
2689 file, or individually on a per-module basis.
2690
2691 This feature was contributed by Jannick Kremer.
2692
2693 List of changes:
2694
2695 * Implement flag to allow type checking of untyped modules (Jannick Kremer, PR [17712](https://github.com/python/mypy/pull/17712))
2696 * Warn about `--follow-untyped-imports` (Shantanu, PR [18249](https://github.com/python/mypy/pull/18249))
2697
2698 ### Support New Style Type Variable Defaults (PEP 696)
2699
2700 Mypy now supports type variable defaults using the new syntax described in PEP 696, which
2701 was introduced in Python 3.13. Example:
2702
2703 ```python
2704 @dataclass
2705 class Box[T = int]: # Set default for "T"
2706 value: T | None = None
2707
2708 reveal_type(Box()) # type is Box[int], since it's the default
2709 reveal_type(Box(value="Hello World!")) # type is Box[str]
2710 ```
2711
2712 This feature was contributed by Marc Mueller (PR [17985](https://github.com/python/mypy/pull/17985)).
2713
2714 ### Improved For Loop Index Variable Type Narrowing
2715
2716 Mypy now preserves the literal type of for loop index variables, to support `TypedDict`
2717 lookups. Example:
2718
2719 ```python
2720 from typing import TypedDict
2721
2722 class X(TypedDict):
2723 hourly: int
2724 daily: int
2725
2726 def func(x: X) -> int:
2727 s = 0
2728 for var in ("hourly", "daily"):
2729 # "Union[Literal['hourly']?, Literal['daily']?]"
2730 reveal_type(var)
2731
2732 # x[var] no longer triggers a literal-required error
2733 s += x[var]
2734 return s
2735 ```
2736
2737 This was contributed by Marc Mueller (PR [18014](https://github.com/python/mypy/pull/18014)).
2738
2739 ### Mypyc Improvements
2740
2741 * Document optimized bytes operations and additional str operations (Jukka Lehtosalo, PR [18242](https://github.com/python/mypy/pull/18242))
2742 * Add primitives and specialization for `ord()` (Jukka Lehtosalo, PR [18240](https://github.com/python/mypy/pull/18240))
2743 * Optimize `str.encode` with specializations for common used encodings (Valentin Stanciu, PR [18232](https://github.com/python/mypy/pull/18232))
2744 * Fix fall back to generic operation for staticmethod and classmethod (Advait Dixit, PR [18228](https://github.com/python/mypy/pull/18228))
2745 * Support unicode surrogates in string literals (Jukka Lehtosalo, PR [18209](https://github.com/python/mypy/pull/18209))
2746 * Fix index variable in for loop with `builtins.enumerate` (Advait Dixit, PR [18202](https://github.com/python/mypy/pull/18202))
2747 * Fix check for enum classes (Advait Dixit, PR [18178](https://github.com/python/mypy/pull/18178))
2748 * Fix loading type from imported modules (Advait Dixit, PR [18158](https://github.com/python/mypy/pull/18158))
2749 * Fix initializers of final attributes in class body (Jared Hance, PR [18031](https://github.com/python/mypy/pull/18031))
2750 * Fix name generation for modules with similar full names (aatle, PR [18001](https://github.com/python/mypy/pull/18001))
2751 * Fix relative imports in `__init__.py` (Shantanu, PR [17979](https://github.com/python/mypy/pull/17979))
2752 * Optimize dunder methods (jairov4, PR [17934](https://github.com/python/mypy/pull/17934))
2753 * Replace deprecated `_PyDict_GetItemStringWithError` (Marc Mueller, PR [17930](https://github.com/python/mypy/pull/17930))
2754 * Fix wheel build for cp313-win (Marc Mueller, PR [17941](https://github.com/python/mypy/pull/17941))
2755 * Use public PyGen_GetCode instead of vendored implementation (Marc Mueller, PR [17931](https://github.com/python/mypy/pull/17931))
2756 * Optimize calls to final classes (jairov4, PR [17886](https://github.com/python/mypy/pull/17886))
2757 * Support ellipsis (`...`) expressions in class bodies (Newbyte, PR [17923](https://github.com/python/mypy/pull/17923))
2758 * Sync `pythoncapi_compat.h` (Marc Mueller, PR [17929](https://github.com/python/mypy/pull/17929))
2759 * Add `runtests.py mypyc-fast` for running fast mypyc tests (Jukka Lehtosalo, PR [17906](https://github.com/python/mypy/pull/17906))
2760
2761 ### Stubgen Improvements
2762
2763 * Do not include mypy generated symbols (Ali Hamdan, PR [18137](https://github.com/python/mypy/pull/18137))
2764 * Fix `FunctionContext.fullname` for nested classes (Chad Dombrova, PR [17963](https://github.com/python/mypy/pull/17963))
2765 * Add flagfile support (Ruslan Sayfutdinov, PR [18061](https://github.com/python/mypy/pull/18061))
2766 * Add support for PEP 695 and PEP 696 syntax (Ali Hamdan, PR [18054](https://github.com/python/mypy/pull/18054))
2767
2768 ### Stubtest Improvements
2769
2770 * Allow the use of `--show-traceback` and `--pdb` with stubtest (Stephen Morton, PR [18037](https://github.com/python/mypy/pull/18037))
2771 * Verify `__all__` exists in stub (Sebastian Rittau, PR [18005](https://github.com/python/mypy/pull/18005))
2772 * Stop telling people to use double underscores (Jelle Zijlstra, PR [17897](https://github.com/python/mypy/pull/17897))
2773
2774 ### Documentation Updates
2775
2776 * Update config file documentation (sobolevn, PR [18103](https://github.com/python/mypy/pull/18103))
2777 * Improve contributor documentation for Windows (ag-tafe, PR [18097](https://github.com/python/mypy/pull/18097))
2778 * Correct note about `--disallow-any-generics` flag in documentation (Abel Sen, PR [18055](https://github.com/python/mypy/pull/18055))
2779 * Further caution against `--follow-imports=skip` (Shantanu, PR [18048](https://github.com/python/mypy/pull/18048))
2780 * Fix the edit page button link in documentation (Kanishk Pachauri, PR [17933](https://github.com/python/mypy/pull/17933))
2781
2782 ### Other Notables Fixes and Improvements
2783
2784 * Allow enum members to have type objects as values (Jukka Lehtosalo, PR [19160](https://github.com/python/mypy/pull/19160))
2785 * Show `Protocol` `__call__` for arguments with incompatible types (MechanicalConstruct, PR [18214](https://github.com/python/mypy/pull/18214))
2786 * Make join and meet symmetric with `strict_optional` (MechanicalConstruct, PR [18227](https://github.com/python/mypy/pull/18227))
2787 * Preserve block unreachablility when checking function definitions with constrained TypeVars (Brian Schubert, PR [18217](https://github.com/python/mypy/pull/18217))
2788 * Do not include non-init fields in the synthesized `__replace__` method for dataclasses (Victorien, PR [18221](https://github.com/python/mypy/pull/18221))
2789 * Disallow `TypeVar` constraints parameterized by type variables (Brian Schubert, PR [18186](https://github.com/python/mypy/pull/18186))
2790 * Always complain about invalid varargs and varkwargs (Shantanu, PR [18207](https://github.com/python/mypy/pull/18207))
2791 * Set default strict_optional state to True (Shantanu, PR [18198](https://github.com/python/mypy/pull/18198))
2792 * Preserve type variable default None in type alias (Sukhorosov Aleksey, PR [18197](https://github.com/python/mypy/pull/18197))
2793 * Add checks for invalid usage of continue/break/return in `except*` block (coldwolverine, PR [18132](https://github.com/python/mypy/pull/18132))
2794 * Do not consider bare TypeVar not overlapping with None for reachability analysis (Stanislav Terliakov, PR [18138](https://github.com/python/mypy/pull/18138))
2795 * Special case `types.DynamicClassAttribute` as property-like (Stephen Morton, PR [18150](https://github.com/python/mypy/pull/18150))
2796 * Disallow bare `ParamSpec` in type aliases (Brian Schubert, PR [18174](https://github.com/python/mypy/pull/18174))
2797 * Move long_description metadata to pyproject.toml (Marc Mueller, PR [18172](https://github.com/python/mypy/pull/18172))
2798 * Support `==`-based narrowing of Optional (Christoph Tyralla, PR [18163](https://github.com/python/mypy/pull/18163))
2799 * Allow TypedDict assignment of Required item to NotRequired ReadOnly item (Brian Schubert, PR [18164](https://github.com/python/mypy/pull/18164))
2800 * Allow nesting of Annotated with TypedDict special forms inside TypedDicts (Brian Schubert, PR [18165](https://github.com/python/mypy/pull/18165))
2801 * Infer generic type arguments for slice expressions (Brian Schubert, PR [18160](https://github.com/python/mypy/pull/18160))
2802 * Fix checking of match sequence pattern against bounded type variables (Brian Schubert, PR [18091](https://github.com/python/mypy/pull/18091))
2803 * Fix incorrect truthyness for Enum types and literals (David Salvisberg, PR [17337](https://github.com/python/mypy/pull/17337))
2804 * Move static project metadata to pyproject.toml (Marc Mueller, PR [18146](https://github.com/python/mypy/pull/18146))
2805 * Fallback to stdlib json if integer exceeds 64-bit range (q0w, PR [18148](https://github.com/python/mypy/pull/18148))
2806 * Fix 'or' pattern structural matching exhaustiveness (yihong, PR [18119](https://github.com/python/mypy/pull/18119))
2807 * Fix type inference of positional parameter in class pattern involving builtin subtype (Brian Schubert, PR [18141](https://github.com/python/mypy/pull/18141))
2808 * Fix `[override]` error with no line number when argument node has no line number (Brian Schubert, PR [18122](https://github.com/python/mypy/pull/18122))
2809 * Fix some dmypy crashes (Ivan Levkivskyi, PR [18098](https://github.com/python/mypy/pull/18098))
2810 * Fix subtyping between instance type and overloaded (Shantanu, PR [18102](https://github.com/python/mypy/pull/18102))
2811 * Clean up new_semantic_analyzer config (Shantanu, PR [18071](https://github.com/python/mypy/pull/18071))
2812 * Issue warning for enum with no members in stub (Shantanu, PR [18068](https://github.com/python/mypy/pull/18068))
2813 * Fix enum attributes are not members (Terence Honles, PR [17207](https://github.com/python/mypy/pull/17207))
2814 * Fix crash when checking slice expression with step 0 in tuple index (Brian Schubert, PR [18063](https://github.com/python/mypy/pull/18063))
2815 * Allow union-with-callable attributes to be overridden by methods (Brian Schubert, PR [18018](https://github.com/python/mypy/pull/18018))
2816 * Emit `[mutable-override]` for covariant override of attribute with method (Brian Schubert, PR [18058](https://github.com/python/mypy/pull/18058))
2817 * Support ParamSpec mapping with `functools.partial` (Stanislav Terliakov, PR [17355](https://github.com/python/mypy/pull/17355))
2818 * Fix approved stub ignore, remove normpath (Shantanu, PR [18045](https://github.com/python/mypy/pull/18045))
2819 * Make `disallow-any-unimported` flag invertible (Séamus Ó Ceanainn, PR [18030](https://github.com/python/mypy/pull/18030))
2820 * Filter to possible package paths before trying to resolve a module (falsedrow, PR [18038](https://github.com/python/mypy/pull/18038))
2821 * Fix overlap check for ParamSpec types (Jukka Lehtosalo, PR [18040](https://github.com/python/mypy/pull/18040))
2822 * Do not prioritize ParamSpec signatures during overload resolution (Stanislav Terliakov, PR [18033](https://github.com/python/mypy/pull/18033))
2823 * Fix ternary union for literals (Ivan Levkivskyi, PR [18023](https://github.com/python/mypy/pull/18023))
2824 * Fix compatibility checks for conditional function definitions using decorators (Brian Schubert, PR [18020](https://github.com/python/mypy/pull/18020))
2825 * TypeGuard should be bool not Any when matching TypeVar (Evgeniy Slobodkin, PR [17145](https://github.com/python/mypy/pull/17145))
2826 * Fix convert-cache tool (Shantanu, PR [17974](https://github.com/python/mypy/pull/17974))
2827 * Fix generator comprehension with mypyc (Shantanu, PR [17969](https://github.com/python/mypy/pull/17969))
2828 * Fix crash issue when using shadowfile with pretty (Max Chang, PR [17894](https://github.com/python/mypy/pull/17894))
2829 * Fix multiple nested classes with new generics syntax (Max Chang, PR [17820](https://github.com/python/mypy/pull/17820))
2830 * Better error for `mypy -p package` without py.typed (Joe Gordon, PR [17908](https://github.com/python/mypy/pull/17908))
2831 * Emit error for `raise NotImplemented` (Brian Schubert, PR [17890](https://github.com/python/mypy/pull/17890))
2832 * Add `is_lvalue` attribute to AttributeContext (Brian Schubert, PR [17881](https://github.com/python/mypy/pull/17881))
2833
2834 ### Acknowledgements
2835
2836 Thanks to all mypy contributors who contributed to this release:
2837
2838 - aatle
2839 - Abel Sen
2840 - Advait Dixit
2841 - ag-tafe
2842 - Alex Waygood
2843 - Ali Hamdan
2844 - Brian Schubert
2845 - Carlton Gibson
2846 - Chad Dombrova
2847 - Chelsea Durazo
2848 - chiri
2849 - Christoph Tyralla
2850 - coldwolverine
2851 - David Salvisberg
2852 - Ekin Dursun
2853 - Evgeniy Slobodkin
2854 - falsedrow
2855 - Gaurav Giri
2856 - Ihor
2857 - Ivan Levkivskyi
2858 - jairov4
2859 - Jannick Kremer
2860 - Jared Hance
2861 - Jelle Zijlstra
2862 - jianghuyiyuan
2863 - Joe Gordon
2864 - John Doknjas
2865 - Jukka Lehtosalo
2866 - Kanishk Pachauri
2867 - Marc Mueller
2868 - Max Chang
2869 - MechanicalConstruct
2870 - Newbyte
2871 - q0w
2872 - Ruslan Sayfutdinov
2873 - Sebastian Rittau
2874 - Shantanu
2875 - sobolevn
2876 - Stanislav Terliakov
2877 - Stephen Morton
2878 - Sukhorosov Aleksey
2879 - Séamus Ó Ceanainn
2880 - Terence Honles
2881 - Valentin Stanciu
2882 - vasiliy
2883 - Victorien
2884 - yihong
2885
2886 I’d also like to thank my employer, Dropbox, for supporting mypy development.
2887
2888
2889 ## Mypy 1.13
2890
2891 We’ve just uploaded mypy 1.13 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).
2892 Mypy is a static type checker for Python. You can install it as follows:
2893
2894 python3 -m pip install -U mypy
2895
2896 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
2897
2898 Note that unlike typical releases, Mypy 1.13 does not have any changes to type checking semantics
2899 from 1.12.1.
2900
2901 ### Improved Performance
2902
2903 Mypy 1.13 contains several performance improvements. Users can expect mypy to be 5-20% faster.
2904 In environments with long search paths (such as environments using many editable installs), mypy
2905 can be significantly faster, e.g. 2.2x faster in the use case targeted by these improvements.
2906
2907 Mypy 1.13 allows use of the `orjson` library for handling the cache instead of the stdlib `json`,
2908 for improved performance. You can ensure the presence of `orjson` using the `faster-cache` extra:
2909
2910 python3 -m pip install -U mypy[faster-cache]
2911
2912 Mypy may depend on `orjson` by default in the future.
2913
2914 These improvements were contributed by Shantanu.
2915
2916 List of changes:
2917 * Significantly speed up file handling error paths (Shantanu, PR [17920](https://github.com/python/mypy/pull/17920))
2918 * Use fast path in modulefinder more often (Shantanu, PR [17950](https://github.com/python/mypy/pull/17950))
2919 * Let mypyc optimise os.path.join (Shantanu, PR [17949](https://github.com/python/mypy/pull/17949))
2920 * Make is_sub_path faster (Shantanu, PR [17962](https://github.com/python/mypy/pull/17962))
2921 * Speed up stubs suggestions (Shantanu, PR [17965](https://github.com/python/mypy/pull/17965))
2922 * Use sha1 for hashing (Shantanu, PR [17953](https://github.com/python/mypy/pull/17953))
2923 * Use orjson instead of json, when available (Shantanu, PR [17955](https://github.com/python/mypy/pull/17955))
2924 * Add faster-cache extra, test in CI (Shantanu, PR [17978](https://github.com/python/mypy/pull/17978))
2925
2926 ### Acknowledgements
2927 Thanks to all mypy contributors who contributed to this release:
2928
2929 - Shantanu Jain
2930 - Jukka Lehtosalo
2931
2932 ## Mypy 1.12
2933
2934 We’ve just uploaded mypy 1.12 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)). Mypy is a static type
2935 checker for Python. This release includes new features, performance improvements and bug fixes.
2936 You can install it as follows:
2937
2938 python3 -m pip install -U mypy
2939
2940 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
2941
2942 ### Support Python 3.12 Syntax for Generics (PEP 695)
2943
2944 Support for the new type parameter syntax introduced in Python 3.12 is now enabled by default,
2945 documented, and no longer experimental. It was available through a feature flag in
2946 mypy 1.11 as an experimental feature.
2947
2948 This example demonstrates the new syntax:
2949
2950 ```python
2951 # Generic function
2952 def f[T](x: T) -> T: ...
2953
2954 reveal_type(f(1)) # Revealed type is 'int'
2955
2956 # Generic class
2957 class C[T]:
2958 def __init__(self, x: T) -> None:
2959 self.x = x
2960
2961 c = C('a')
2962 reveal_type(c.x) # Revealed type is 'str'
2963
2964 # Type alias
2965 type A[T] = C[list[T]]
2966 ```
2967
2968 For more information, refer to the [documentation](https://mypy.readthedocs.io/en/latest/generics.html).
2969
2970 These improvements are included:
2971
2972 * Document Python 3.12 type parameter syntax (Jukka Lehtosalo, PR [17816](https://github.com/python/mypy/pull/17816))
2973 * Further documentation updates (Jukka Lehtosalo, PR [17826](https://github.com/python/mypy/pull/17826))
2974 * Allow Self return types with contravariance (Jukka Lehtosalo, PR [17786](https://github.com/python/mypy/pull/17786))
2975 * Enable new type parameter syntax by default (Jukka Lehtosalo, PR [17798](https://github.com/python/mypy/pull/17798))
2976 * Generate error if new-style type alias used as base class (Jukka Lehtosalo, PR [17789](https://github.com/python/mypy/pull/17789))
2977 * Inherit variance if base class has explicit variance (Jukka Lehtosalo, PR [17787](https://github.com/python/mypy/pull/17787))
2978 * Fix crash on invalid type var reference (Jukka Lehtosalo, PR [17788](https://github.com/python/mypy/pull/17788))
2979 * Fix covariance of frozen dataclasses (Jukka Lehtosalo, PR [17783](https://github.com/python/mypy/pull/17783))
2980 * Allow covariance with attribute that has "`_`" name prefix (Jukka Lehtosalo, PR [17782](https://github.com/python/mypy/pull/17782))
2981 * Support `Annotated[...]` in new-style type aliases (Jukka Lehtosalo, PR [17777](https://github.com/python/mypy/pull/17777))
2982 * Fix nested generic classes (Jukka Lehtosalo, PR [17776](https://github.com/python/mypy/pull/17776))
2983 * Add detection and error reporting for the use of incorrect expressions within the scope of a type parameter and a type alias (Kirill Podoprigora, PR [17560](https://github.com/python/mypy/pull/17560))
2984
2985 ### Basic Support for Python 3.13
2986
2987 This release adds partial support for Python 3.13 features and compiled binaries for
2988 Python 3.13. Mypyc now also supports Python 3.13.
2989
2990 In particular, these features are supported:
2991 * Various new stdlib features and changes (through typeshed stub improvements)
2992 * `typing.ReadOnly` (see below for more)
2993 * `typing.TypeIs` (added in mypy 1.10, [PEP 742](https://peps.python.org/pep-0742/))
2994 * Type parameter defaults when using the legacy syntax ([PEP 696](https://peps.python.org/pep-0696/))
2995
2996 These features are not supported yet:
2997 * `warnings.deprecated` ([PEP 702](https://peps.python.org/pep-0702/))
2998 * Type parameter defaults when using Python 3.12 type parameter syntax
2999
3000 ### Mypyc Support for Python 3.13
3001
3002 Mypyc now supports Python 3.13. This was contributed by Marc Mueller, with additional
3003 fixes by Jukka Lehtosalo. Free threaded Python 3.13 builds are not supported yet.
3004
3005 List of changes:
3006
3007 * Add additional includes for Python 3.13 (Marc Mueller, PR [17506](https://github.com/python/mypy/pull/17506))
3008 * Add another include for Python 3.13 (Marc Mueller, PR [17509](https://github.com/python/mypy/pull/17509))
3009 * Fix ManagedDict functions for Python 3.13 (Marc Mueller, PR [17507](https://github.com/python/mypy/pull/17507))
3010 * Update mypyc test output for Python 3.13 (Marc Mueller, PR [17508](https://github.com/python/mypy/pull/17508))
3011 * Fix `PyUnicode` functions for Python 3.13 (Marc Mueller, PR [17504](https://github.com/python/mypy/pull/17504))
3012 * Fix `_PyObject_LookupAttrId` for Python 3.13 (Marc Mueller, PR [17505](https://github.com/python/mypy/pull/17505))
3013 * Fix `_PyList_Extend` for Python 3.13 (Marc Mueller, PR [17503](https://github.com/python/mypy/pull/17503))
3014 * Fix `gen_is_coroutine` for Python 3.13 (Marc Mueller, PR [17501](https://github.com/python/mypy/pull/17501))
3015 * Fix `_PyObject_FastCall` for Python 3.13 (Marc Mueller, PR [17502](https://github.com/python/mypy/pull/17502))
3016 * Avoid uses of `_PyObject_CallMethodOneArg` on 3.13 (Jukka Lehtosalo, PR [17526](https://github.com/python/mypy/pull/17526))
3017 * Don't rely on `_PyType_CalculateMetaclass` on 3.13 (Jukka Lehtosalo, PR [17525](https://github.com/python/mypy/pull/17525))
3018 * Don't use `_PyUnicode_FastCopyCharacters` on 3.13 (Jukka Lehtosalo, PR [17524](https://github.com/python/mypy/pull/17524))
3019 * Don't use `_PyUnicode_EQ` on 3.13, as it's no longer exported (Jukka Lehtosalo, PR [17523](https://github.com/python/mypy/pull/17523))
3020
3021 ### Inferring Unions for Conditional Expressions
3022
3023 Mypy now always tries to infer a union type for a conditional expression if left and right
3024 operand types are different. This results in more precise inferred types and lets mypy detect
3025 more issues. Example:
3026
3027 ```python
3028 s = "foo" if cond() else 1
3029 # Type of "s" is now "str | int" (it used to be "object")
3030 ```
3031
3032 Notably, if one of the operands has type `Any`, the type of a conditional expression is
3033 now `<type> | Any`. Previously the inferred type was just `Any`. The new type essentially
3034 indicates that the value can be of type `<type>`, and potentially of some (unknown) type.
3035 Most operations performed on the result must also be valid for `<type>`.
3036 Example where this is relevant:
3037
3038 ```python
3039 from typing import Any
3040
3041 def func(a: Any, b: bool) -> None:
3042 x = a if b else None
3043 # Type of x is "Any | None"
3044 print(x.y) # Error: None has no attribute "y"
3045 ```
3046
3047 This feature was contributed by Ivan Levkivskyi (PR [17427](https://github.com/python/mypy/pull/17427)).
3048
3049 ### ReadOnly Support for TypedDict (PEP 705)
3050
3051 You can now use `typing.ReadOnly` to specity TypedDict items as
3052 read-only ([PEP 705](https://peps.python.org/pep-0705/)):
3053
3054 ```python
3055 from typing import TypedDict
3056
3057 # Or "from typing ..." on Python 3.13
3058 from typing_extensions import ReadOnly
3059
3060 class TD(TypedDict):
3061 a: int
3062 b: ReadOnly[int]
3063
3064 d: TD = {"a": 1, "b": 2}
3065 d["a"] = 3 # OK
3066 d["b"] = 5 # Error: "b" is ReadOnly
3067 ```
3068
3069 This feature was contributed by Nikita Sobolev (PR [17644](https://github.com/python/mypy/pull/17644)).
3070
3071 ### Python 3.8 End of Life Approaching
3072
3073 We are planning to drop support for Python 3.8 in the next mypy feature release or the
3074 one after that. Python 3.8 reaches end of life in October 2024.
3075
3076 ### Planned Changes to Defaults
3077
3078 We are planning to enable `--local-partial-types` by default in mypy 2.0. This will
3079 often require at least minor code changes. This option is implicitly enabled by mypy
3080 daemon, so this makes the behavior of daemon and non-daemon modes consistent.
3081
3082 We recommend that mypy users start using local partial types soon (or to explicitly disable
3083 them) to prepare for the change.
3084
3085 This can also be configured in a mypy configuration file:
3086
3087 ```
3088 local_partial_types = True
3089 ```
3090
3091 For more information, refer to the
3092 [documentation](https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-local-partial-types).
3093
3094 ### Documentation Updates
3095
3096 Mypy documentation now uses modern syntax variants and imports in many examples. Some
3097 examples no longer work on Python 3.8, which is the earliest Python version that mypy supports.
3098
3099 Notably, `Iterable` and other protocols/ABCs are imported from `collections.abc` instead of
3100 `typing`:
3101 ```python
3102 from collections.abc import Iterable, Callable
3103 ```
3104
3105 Examples also avoid the upper-case aliases to built-in types: `list[str]` is used instead
3106 of `List[str]`. The `X | Y` union type syntax introduced in Python 3.10 is also now prevalent.
3107
3108 List of documentation updates:
3109
3110 * Document `--output=json` CLI option (Edgar Ramírez Mondragón, PR [17611](https://github.com/python/mypy/pull/17611))
3111 * Update various references to deprecated type aliases in docs (Jukka Lehtosalo, PR [17829](https://github.com/python/mypy/pull/17829))
3112 * Make "X | Y" union syntax more prominent in documentation (Jukka Lehtosalo, PR [17835](https://github.com/python/mypy/pull/17835))
3113 * Discuss upper bounds before self types in documentation (Jukka Lehtosalo, PR [17827](https://github.com/python/mypy/pull/17827))
3114 * Make changelog visible in mypy documentation (quinn-sasha, PR [17742](https://github.com/python/mypy/pull/17742))
3115 * List all incomplete features in `--enable-incomplete-feature` docs (sobolevn, PR [17633](https://github.com/python/mypy/pull/17633))
3116 * Remove the explicit setting of a pygments theme (Pradyun Gedam, PR [17571](https://github.com/python/mypy/pull/17571))
3117 * Document ReadOnly with TypedDict (Jukka Lehtosalo, PR [17905](https://github.com/python/mypy/pull/17905))
3118 * Document TypeIs (Chelsea Durazo, PR [17821](https://github.com/python/mypy/pull/17821))
3119
3120 ### Experimental Inline TypedDict Syntax
3121
3122 Mypy now supports a non-standard, experimental syntax for defining anonymous TypedDicts.
3123 Example:
3124
3125 ```python
3126 def func(n: str, y: int) -> {"name": str, "year": int}:
3127 return {"name": n, "year": y}
3128 ```
3129
3130 The feature is disabled by default. Use `--enable-incomplete-feature=InlineTypedDict` to
3131 enable it. *We might remove this feature in a future release.*
3132
3133 This feature was contributed by Ivan Levkivskyi (PR [17457](https://github.com/python/mypy/pull/17457)).
3134
3135 ### Stubgen Improvements
3136
3137 * Fix crash on literal class-level keywords (sobolevn, PR [17663](https://github.com/python/mypy/pull/17663))
3138 * Stubgen add `--version` (sobolevn, PR [17662](https://github.com/python/mypy/pull/17662))
3139 * Fix `stubgen --no-analysis/--parse-only` docs (sobolevn, PR [17632](https://github.com/python/mypy/pull/17632))
3140 * Include keyword only args when generating signatures in stubgenc (Eric Mark Martin, PR [17448](https://github.com/python/mypy/pull/17448))
3141 * Add support for detecting `Literal` types when extracting types from docstrings (Michael Carlstrom, PR [17441](https://github.com/python/mypy/pull/17441))
3142 * Use `Generator` type var defaults (Sebastian Rittau, PR [17670](https://github.com/python/mypy/pull/17670))
3143
3144 ### Stubtest Improvements
3145 * Add support for `cached_property` (Ali Hamdan, PR [17626](https://github.com/python/mypy/pull/17626))
3146 * Add `enable_incomplete_feature` validation to `stubtest` (sobolevn, PR [17635](https://github.com/python/mypy/pull/17635))
3147 * Fix error code handling in `stubtest` with `--mypy-config-file` (sobolevn, PR [17629](https://github.com/python/mypy/pull/17629))
3148
3149 ### Other Notables Fixes and Improvements
3150
3151 * Report error if using unsupported type parameter defaults (Jukka Lehtosalo, PR [17876](https://github.com/python/mypy/pull/17876))
3152 * Fix re-processing cross-reference in mypy daemon when node kind changes (Ivan Levkivskyi, PR [17883](https://github.com/python/mypy/pull/17883))
3153 * Don't use equality to narrow when value is IntEnum/StrEnum (Jukka Lehtosalo, PR [17866](https://github.com/python/mypy/pull/17866))
3154 * Don't consider None vs IntEnum comparison ambiguous (Jukka Lehtosalo, PR [17877](https://github.com/python/mypy/pull/17877))
3155 * Fix narrowing of IntEnum and StrEnum types (Jukka Lehtosalo, PR [17874](https://github.com/python/mypy/pull/17874))
3156 * Filter overload items based on self type during type inference (Jukka Lehtosalo, PR [17873](https://github.com/python/mypy/pull/17873))
3157 * Enable negative narrowing of union TypeVar upper bounds (Brian Schubert, PR [17850](https://github.com/python/mypy/pull/17850))
3158 * Fix issue with member expression formatting (Brian Schubert, PR [17848](https://github.com/python/mypy/pull/17848))
3159 * Avoid type size explosion when expanding types (Jukka Lehtosalo, PR [17842](https://github.com/python/mypy/pull/17842))
3160 * Fix negative narrowing of tuples in match statement (Brian Schubert, PR [17817](https://github.com/python/mypy/pull/17817))
3161 * Narrow falsey str/bytes/int to literal type (Brian Schubert, PR [17818](https://github.com/python/mypy/pull/17818))
3162 * Test against latest Python 3.13, make testing 3.14 easy (Shantanu, PR [17812](https://github.com/python/mypy/pull/17812))
3163 * Reject ParamSpec-typed callables calls with insufficient arguments (Stanislav Terliakov, PR [17323](https://github.com/python/mypy/pull/17323))
3164 * Fix crash when passing too many type arguments to generic base class accepting single ParamSpec (Brian Schubert, PR [17770](https://github.com/python/mypy/pull/17770))
3165 * Fix TypeVar upper bounds sometimes not being displayed in pretty callables (Brian Schubert, PR [17802](https://github.com/python/mypy/pull/17802))
3166 * Added error code for overlapping function signatures (Katrina Connors, PR [17597](https://github.com/python/mypy/pull/17597))
3167 * Check for `truthy-bool` in `not ...` unary expressions (sobolevn, PR [17773](https://github.com/python/mypy/pull/17773))
3168 * Add missing lines-covered and lines-valid attributes (Soubhik Kumar Mitra, PR [17738](https://github.com/python/mypy/pull/17738))
3169 * Fix another crash scenario with recursive tuple types (Ivan Levkivskyi, PR [17708](https://github.com/python/mypy/pull/17708))
3170 * Resolve TypeVar upper bounds in `functools.partial` (Shantanu, PR [17660](https://github.com/python/mypy/pull/17660))
3171 * Always reset binder when checking deferred nodes (Ivan Levkivskyi, PR [17643](https://github.com/python/mypy/pull/17643))
3172 * Fix crash on a callable attribute with single unpack (Ivan Levkivskyi, PR [17641](https://github.com/python/mypy/pull/17641))
3173 * Fix mismatched signature between checker plugin API and implementation (bzoracler, PR [17343](https://github.com/python/mypy/pull/17343))
3174 * Indexing a type also produces a GenericAlias (Shantanu, PR [17546](https://github.com/python/mypy/pull/17546))
3175 * Fix crash on self-type in callable protocol (Ivan Levkivskyi, PR [17499](https://github.com/python/mypy/pull/17499))
3176 * Fix crash on NamedTuple with method and error in function (Ivan Levkivskyi, PR [17498](https://github.com/python/mypy/pull/17498))
3177 * Add `__replace__` for dataclasses in 3.13 (Max Muoto, PR [17469](https://github.com/python/mypy/pull/17469))
3178 * Fix help message for `--no-namespace-packages` (Raphael Krupinski, PR [17472](https://github.com/python/mypy/pull/17472))
3179 * Fix typechecking for async generators (Danny Yang, PR [17452](https://github.com/python/mypy/pull/17452))
3180 * Fix strict optional handling in attrs plugin (Ivan Levkivskyi, PR [17451](https://github.com/python/mypy/pull/17451))
3181 * Allow mixing ParamSpec and TypeVarTuple in Generic (Ivan Levkivskyi, PR [17450](https://github.com/python/mypy/pull/17450))
3182 * Improvements to `functools.partial` of types (Shantanu, PR [17898](https://github.com/python/mypy/pull/17898))
3183 * Make ReadOnly TypedDict items covariant (Jukka Lehtosalo, PR [17904](https://github.com/python/mypy/pull/17904))
3184 * Fix union callees with `functools.partial` (Jukka Lehtosalo, PR [17903](https://github.com/python/mypy/pull/17903))
3185 * Improve handling of generic functions with `functools.partial` (Ivan Levkivskyi, PR [17925](https://github.com/python/mypy/pull/17925))
3186
3187 ### Typeshed Updates
3188
3189 Please see [git log](https://github.com/python/typeshed/commits/main?after=91a58b07cdd807b1d965e04ba85af2adab8bf924+0&branch=main&path=stdlib) for full list of standard library typeshed stub changes.
3190
3191 ### Mypy 1.12.1
3192 * Fix crash when showing partially analyzed type in error message (Ivan Levkivskyi, PR [17961](https://github.com/python/mypy/pull/17961))
3193 * Fix iteration over union (when self type is involved) (Shantanu, PR [17976](https://github.com/python/mypy/pull/17976))
3194 * Fix type object with type var default in union context (Jukka Lehtosalo, PR [17991](https://github.com/python/mypy/pull/17991))
3195 * Revert change to `os.path` stubs affecting use of `os.PathLike[Any]` (Shantanu, PR [17995](https://github.com/python/mypy/pull/17995))
3196
3197 ### Acknowledgements
3198 Thanks to all mypy contributors who contributed to this release:
3199
3200 - Ali Hamdan
3201 - Anders Kaseorg
3202 - Bénédikt Tran
3203 - Brian Schubert
3204 - bzoracler
3205 - Chelsea Durazo
3206 - Danny Yang
3207 - Edgar Ramírez Mondragón
3208 - Eric Mark Martin
3209 - InSync
3210 - Ivan Levkivskyi
3211 - Jordandev678
3212 - Katrina Connors
3213 - Kirill Podoprigora
3214 - Marc Mueller
3215 - Max Muoto
3216 - Max Murin
3217 - Michael Carlstrom
3218 - Michael I Chen
3219 - Pradyun Gedam
3220 - quinn-sasha
3221 - Raphael Krupinski
3222 - Sebastian Rittau
3223 - Shantanu
3224 - sobolevn
3225 - Soubhik Kumar Mitra
3226 - Stanislav Terliakov
3227 - wyattscarpenter
3228
3229 I’d also like to thank my employer, Dropbox, for supporting mypy development.
3230
3231
3232 ## Mypy 1.11
3233
3234 We’ve just uploaded mypy 1.11 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:
3235
3236 python3 -m pip install -U mypy
3237
3238 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
3239
3240 ### Support Python 3.12 Syntax for Generics (PEP 695)
3241
3242 Mypy now supports the new type parameter syntax introduced in Python 3.12 ([PEP 695](https://peps.python.org/pep-0695/)).
3243 This feature is still experimental and must be enabled with the `--enable-incomplete-feature=NewGenericSyntax` flag, or with `enable_incomplete_feature = NewGenericSyntax` in the mypy configuration file.
3244 We plan to enable this by default in the next mypy feature release.
3245
3246 This example demonstrates the new syntax:
3247
3248 ```python
3249 # Generic function
3250 def f[T](x: T) -> T: ...
3251
3252 reveal_type(f(1)) # Revealed type is 'int'
3253
3254 # Generic class
3255 class C[T]:
3256 def __init__(self, x: T) -> None:
3257 self.x = x
3258
3259 c = C('a')
3260 reveal_type(c.x) # Revealed type is 'str'
3261
3262 # Type alias
3263 type A[T] = C[list[T]]
3264 ```
3265
3266 This feature was contributed by Jukka Lehtosalo.
3267
3268
3269 ### Support for `functools.partial`
3270
3271 Mypy now type checks uses of `functools.partial`. Previously mypy would accept arbitrary arguments.
3272
3273 This example will now produce an error:
3274
3275 ```python
3276 from functools import partial
3277
3278 def f(a: int, b: str) -> None: ...
3279
3280 g = partial(f, 1)
3281
3282 # Argument has incompatible type "int"; expected "str"
3283 g(11)
3284 ```
3285
3286 This feature was contributed by Shantanu (PR [16939](https://github.com/python/mypy/pull/16939)).
3287
3288
3289 ### Stricter Checks for Untyped Overrides
3290
3291 Past mypy versions didn't check if untyped methods were compatible with overridden methods. This would result in false negatives. Now mypy performs these checks when using `--check-untyped-defs`.
3292
3293 For example, this now generates an error if using `--check-untyped-defs`:
3294
3295 ```python
3296 class Base:
3297 def f(self, x: int = 0) -> None: ...
3298
3299 class Derived(Base):
3300 # Signature incompatible with "Base"
3301 def f(self): ...
3302 ```
3303
3304 This feature was contributed by Steven Troxler (PR [17276](https://github.com/python/mypy/pull/17276)).
3305
3306
3307 ### Type Inference Improvements
3308
3309 The new polymorphic inference algorithm introduced in mypy 1.5 is now used in more situations. This improves type inference involving generic higher-order functions, in particular.
3310
3311 This feature was contributed by Ivan Levkivskyi (PR [17348](https://github.com/python/mypy/pull/17348)).
3312
3313 Mypy now uses unions of tuple item types in certain contexts to enable more precise inferred types. Example:
3314
3315 ```python
3316 for x in (1, 'x'):
3317 # Previously inferred as 'object'
3318 reveal_type(x) # Revealed type is 'int | str'
3319 ```
3320
3321 This was also contributed by Ivan Levkivskyi (PR [17408](https://github.com/python/mypy/pull/17408)).
3322
3323
3324 ### Improvements to Detection of Overlapping Overloads
3325
3326 The details of how mypy checks if two `@overload` signatures are unsafely overlapping were overhauled. This both fixes some false positives, and allows mypy to detect additional unsafe signatures.
3327
3328 This feature was contributed by Ivan Levkivskyi (PR [17392](https://github.com/python/mypy/pull/17392)).
3329
3330
3331 ### Better Support for Type Hints in Expressions
3332
3333 Mypy now allows more expressions that evaluate to valid type annotations in all expression contexts. The inferred types of these expressions are also sometimes more precise. Previously they were often `object`.
3334
3335 This example uses a union type that includes a callable type as an expression, and it no longer generates an error:
3336
3337 ```python
3338 from typing import Callable
3339
3340 print(Callable[[], int] | None) # No error
3341 ```
3342
3343 This feature was contributed by Jukka Lehtosalo (PR [17404](https://github.com/python/mypy/pull/17404)).
3344
3345
3346 ### Mypyc Improvements
3347
3348 Mypyc now supports the new syntax for generics introduced in Python 3.12 (see above). Another notable improvement is significantly faster basic operations on `int` values.
3349
3350 * Support Python 3.12 syntax for generic functions and classes (Jukka Lehtosalo, PR [17357](https://github.com/python/mypy/pull/17357))
3351 * Support Python 3.12 type alias syntax (Jukka Lehtosalo, PR [17384](https://github.com/python/mypy/pull/17384))
3352 * Fix ParamSpec (Shantanu, PR [17309](https://github.com/python/mypy/pull/17309))
3353 * Inline fast paths of integer unboxing operations (Jukka Lehtosalo, PR [17266](https://github.com/python/mypy/pull/17266))
3354 * Inline tagged integer arithmetic and bitwise operations (Jukka Lehtosalo, PR [17265](https://github.com/python/mypy/pull/17265))
3355 * Allow specifying primitives as pure (Jukka Lehtosalo, PR [17263](https://github.com/python/mypy/pull/17263))
3356
3357
3358 ### Changes to Stubtest
3359 * Ignore `_ios_support` (Alex Waygood, PR [17270](https://github.com/python/mypy/pull/17270))
3360 * Improve support for Python 3.13 (Shantanu, PR [17261](https://github.com/python/mypy/pull/17261))
3361
3362
3363 ### Changes to Stubgen
3364 * Gracefully handle invalid `Optional` and recognize aliases to PEP 604 unions (Ali Hamdan, PR [17386](https://github.com/python/mypy/pull/17386))
3365 * Fix for Python 3.13 (Jelle Zijlstra, PR [17290](https://github.com/python/mypy/pull/17290))
3366 * Preserve enum value initialisers (Shantanu, PR [17125](https://github.com/python/mypy/pull/17125))
3367
3368
3369 ### Miscellaneous New Features
3370 * Add error format support and JSON output option via `--output json` (Tushar Sadhwani, PR [11396](https://github.com/python/mypy/pull/11396))
3371 * Support `enum.member` in Python 3.11+ (Nikita Sobolev, PR [17382](https://github.com/python/mypy/pull/17382))
3372 * Support `enum.nonmember` in Python 3.11+ (Nikita Sobolev, PR [17376](https://github.com/python/mypy/pull/17376))
3373 * Support `namedtuple.__replace__` in Python 3.13 (Shantanu, PR [17259](https://github.com/python/mypy/pull/17259))
3374 * Support `rename=True` in collections.namedtuple (Jelle Zijlstra, PR [17247](https://github.com/python/mypy/pull/17247))
3375 * Add support for `__spec__` (Shantanu, PR [14739](https://github.com/python/mypy/pull/14739))
3376
3377
3378 ### Changes to Error Reporting
3379 * Mention `--enable-incomplete-feature=NewGenericSyntax` in messages (Shantanu, PR [17462](https://github.com/python/mypy/pull/17462))
3380 * Do not report plugin-generated methods with `explicit-override` (sobolevn, PR [17433](https://github.com/python/mypy/pull/17433))
3381 * Use and display namespaces for function type variables (Ivan Levkivskyi, PR [17311](https://github.com/python/mypy/pull/17311))
3382 * Fix false positive for Final local scope variable in Protocol (GiorgosPapoutsakis, PR [17308](https://github.com/python/mypy/pull/17308))
3383 * Use Never in more messages, use ambiguous in join (Shantanu, PR [17304](https://github.com/python/mypy/pull/17304))
3384 * Log full path to config file in verbose output (dexterkennedy, PR [17180](https://github.com/python/mypy/pull/17180))
3385 * Added `[prop-decorator]` code for unsupported property decorators (#14461) (Christopher Barber, PR [16571](https://github.com/python/mypy/pull/16571))
3386 * Suppress second error message with `:=` and `[truthy-bool]` (Nikita Sobolev, PR [15941](https://github.com/python/mypy/pull/15941))
3387 * Generate error for assignment of functional Enum to variable of different name (Shantanu, PR [16805](https://github.com/python/mypy/pull/16805))
3388 * Fix error reporting on cached run after uninstallation of third party library (Shantanu, PR [17420](https://github.com/python/mypy/pull/17420))
3389
3390
3391 ### Fixes for Crashes
3392 * Fix daemon crash on invalid type in TypedDict (Ivan Levkivskyi, PR [17495](https://github.com/python/mypy/pull/17495))
3393 * Fix crash and bugs related to `partial()` (Ivan Levkivskyi, PR [17423](https://github.com/python/mypy/pull/17423))
3394 * Fix crash when overriding with unpacked TypedDict (Ivan Levkivskyi, PR [17359](https://github.com/python/mypy/pull/17359))
3395 * Fix crash on TypedDict unpacking for ParamSpec (Ivan Levkivskyi, PR [17358](https://github.com/python/mypy/pull/17358))
3396 * Fix crash involving recursive union of tuples (Ivan Levkivskyi, PR [17353](https://github.com/python/mypy/pull/17353))
3397 * Fix crash on invalid callable property override (Ivan Levkivskyi, PR [17352](https://github.com/python/mypy/pull/17352))
3398 * Fix crash on unpacking self in NamedTuple (Ivan Levkivskyi, PR [17351](https://github.com/python/mypy/pull/17351))
3399 * Fix crash on recursive alias with an optional type (Ivan Levkivskyi, PR [17350](https://github.com/python/mypy/pull/17350))
3400 * Fix crash on type comment inside generic definitions (Bénédikt Tran, PR [16849](https://github.com/python/mypy/pull/16849))
3401
3402
3403 ### Changes to Documentation
3404 * Use inline config in documentation for optional error codes (Shantanu, PR [17374](https://github.com/python/mypy/pull/17374))
3405 * Use lower-case generics in documentation (Seo Sanghyeon, PR [17176](https://github.com/python/mypy/pull/17176))
3406 * Add documentation for show-error-code-links (GiorgosPapoutsakis, PR [17144](https://github.com/python/mypy/pull/17144))
3407 * Update CONTRIBUTING.md to include commands for Windows (GiorgosPapoutsakis, PR [17142](https://github.com/python/mypy/pull/17142))
3408
3409
3410 ### Other Notable Improvements and Fixes
3411 * Fix ParamSpec inference against TypeVarTuple (Ivan Levkivskyi, PR [17431](https://github.com/python/mypy/pull/17431))
3412 * Fix explicit type for `partial` (Ivan Levkivskyi, PR [17424](https://github.com/python/mypy/pull/17424))
3413 * Always allow lambda calls (Ivan Levkivskyi, PR [17430](https://github.com/python/mypy/pull/17430))
3414 * Fix isinstance checks with PEP 604 unions containing None (Shantanu, PR [17415](https://github.com/python/mypy/pull/17415))
3415 * Fix self-referential upper bound in new-style type variables (Ivan Levkivskyi, PR [17407](https://github.com/python/mypy/pull/17407))
3416 * Consider overlap between instances and callables (Ivan Levkivskyi, PR [17389](https://github.com/python/mypy/pull/17389))
3417 * Allow new-style self-types in classmethods (Ivan Levkivskyi, PR [17381](https://github.com/python/mypy/pull/17381))
3418 * Fix isinstance with type aliases to PEP 604 unions (Shantanu, PR [17371](https://github.com/python/mypy/pull/17371))
3419 * Properly handle unpacks in overlap checks (Ivan Levkivskyi, PR [17356](https://github.com/python/mypy/pull/17356))
3420 * Fix type application for classes with generic constructors (Ivan Levkivskyi, PR [17354](https://github.com/python/mypy/pull/17354))
3421 * Update `typing_extensions` to >=4.6.0 to fix Python 3.12 error (Ben Brown, PR [17312](https://github.com/python/mypy/pull/17312))
3422 * Avoid "does not return" error in lambda (Shantanu, PR [17294](https://github.com/python/mypy/pull/17294))
3423 * Fix bug with descriptors in non-strict-optional mode (Max Murin, PR [17293](https://github.com/python/mypy/pull/17293))
3424 * Don’t leak unreachability from lambda body to surrounding scope (Anders Kaseorg, PR [17287](https://github.com/python/mypy/pull/17287))
3425 * Fix issues with non-ASCII characters on Windows (Alexander Leopold Shon, PR [17275](https://github.com/python/mypy/pull/17275))
3426 * Fix for type narrowing of negative integer literals (gilesgc, PR [17256](https://github.com/python/mypy/pull/17256))
3427 * Fix confusion between .py and .pyi files in mypy daemon (Valentin Stanciu, PR [17245](https://github.com/python/mypy/pull/17245))
3428 * Fix type of `tuple[X, Y]` expression (urnest, PR [17235](https://github.com/python/mypy/pull/17235))
3429 * Don't forget that a `TypedDict` was wrapped in `Unpack` after a `name-defined` error occurred (Christoph Tyralla, PR [17226](https://github.com/python/mypy/pull/17226))
3430 * Mark annotated argument as having an explicit, not inferred type (bzoracler, PR [17217](https://github.com/python/mypy/pull/17217))
3431 * Don't consider Enum private attributes as enum members (Ali Hamdan, PR [17182](https://github.com/python/mypy/pull/17182))
3432 * Fix Literal strings containing pipe characters (Jelle Zijlstra, PR [17148](https://github.com/python/mypy/pull/17148))
3433
3434
3435 ### Typeshed Updates
3436
3437 Please see [git log](https://github.com/python/typeshed/commits/main?after=6dda799d8ad1d89e0f8aad7ac41d2d34bd838ace+0&branch=main&path=stdlib) for full list of standard library typeshed stub changes.
3438
3439 ### Mypy 1.11.1
3440 * Fix `RawExpressionType.accept` crash with `--cache-fine-grained` (Anders Kaseorg, PR [17588](https://github.com/python/mypy/pull/17588))
3441 * Fix PEP 604 isinstance caching (Shantanu, PR [17563](https://github.com/python/mypy/pull/17563))
3442 * Fix `typing.TypeAliasType` being undefined on python < 3.12 (Nikita Sobolev, PR [17558](https://github.com/python/mypy/pull/17558))
3443 * Fix `types.GenericAlias` lookup crash (Shantanu, PR [17543](https://github.com/python/mypy/pull/17543))
3444
3445 ### Mypy 1.11.2
3446 * Alternative fix for a union-like literal string (Ivan Levkivskyi, PR [17639](https://github.com/python/mypy/pull/17639))
3447 * Unwrap `TypedDict` item types before storing (Ivan Levkivskyi, PR [17640](https://github.com/python/mypy/pull/17640))
3448
3449 ### Acknowledgements
3450 Thanks to all mypy contributors who contributed to this release:
3451
3452 - Alex Waygood
3453 - Alexander Leopold Shon
3454 - Ali Hamdan
3455 - Anders Kaseorg
3456 - Ben Brown
3457 - Bénédikt Tran
3458 - bzoracler
3459 - Christoph Tyralla
3460 - Christopher Barber
3461 - dexterkennedy
3462 - gilesgc
3463 - GiorgosPapoutsakis
3464 - Ivan Levkivskyi
3465 - Jelle Zijlstra
3466 - Jukka Lehtosalo
3467 - Marc Mueller
3468 - Matthieu Devlin
3469 - Michael R. Crusoe
3470 - Nikita Sobolev
3471 - Seo Sanghyeon
3472 - Shantanu
3473 - sobolevn
3474 - Steven Troxler
3475 - Tadeu Manoel
3476 - Tamir Duberstein
3477 - Tushar Sadhwani
3478 - urnest
3479 - Valentin Stanciu
3480
3481 I’d also like to thank my employer, Dropbox, for supporting mypy development.
3482
3483
3484 ## Mypy 1.10
3485
3486 We’ve just uploaded mypy 1.10 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:
3487
3488 python3 -m pip install -U mypy
3489
3490 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
3491
3492 ### Support TypeIs (PEP 742)
3493
3494 Mypy now supports `TypeIs` ([PEP 742](https://peps.python.org/pep-0742/)), which allows
3495 functions to narrow the type of a value, similar to `isinstance()`. Unlike `TypeGuard`,
3496 `TypeIs` can narrow in both the `if` and `else` branches of an if statement:
3497
3498 ```python
3499 from typing_extensions import TypeIs
3500
3501 def is_str(s: object) -> TypeIs[str]:
3502 return isinstance(s, str)
3503
3504 def f(o: str | int) -> None:
3505 if is_str(o):
3506 # Type of o is 'str'
3507 ...
3508 else:
3509 # Type of o is 'int'
3510 ...
3511 ```
3512
3513 `TypeIs` will be added to the `typing` module in Python 3.13, but it
3514 can be used on earlier Python versions by importing it from
3515 `typing_extensions`.
3516
3517 This feature was contributed by Jelle Zijlstra (PR [16898](https://github.com/python/mypy/pull/16898)).
3518
3519 ### Support TypeVar Defaults (PEP 696)
3520
3521 [PEP 696](https://peps.python.org/pep-0696/) adds support for type parameter defaults.
3522 Example:
3523
3524 ```python
3525 from typing import Generic
3526 from typing_extensions import TypeVar
3527
3528 T = TypeVar("T", default=int)
3529
3530 class C(Generic[T]):
3531 ...
3532
3533 x: C = ...
3534 y: C[str] = ...
3535 reveal_type(x) # C[int], because of the default
3536 reveal_type(y) # C[str]
3537 ```
3538
3539 TypeVar defaults will be added to the `typing` module in Python 3.13, but they
3540 can be used with earlier Python releases by importing `TypeVar` from
3541 `typing_extensions`.
3542
3543 This feature was contributed by Marc Mueller (PR [16878](https://github.com/python/mypy/pull/16878)
3544 and PR [16925](https://github.com/python/mypy/pull/16925)).
3545
3546 ### Support TypeAliasType (PEP 695)
3547 As part of the initial steps towards implementing [PEP 695](https://peps.python.org/pep-0695/), mypy now supports `TypeAliasType`.
3548 `TypeAliasType` provides a backport of the new `type` statement in Python 3.12.
3549
3550 ```python
3551 type ListOrSet[T] = list[T] | set[T]
3552 ```
3553
3554 is equivalent to:
3555
3556 ```python
3557 T = TypeVar("T")
3558 ListOrSet = TypeAliasType("ListOrSet", list[T] | set[T], type_params=(T,))
3559 ```
3560
3561 Example of use in mypy:
3562
3563 ```python
3564 from typing_extensions import TypeAliasType, TypeVar
3565
3566 NewUnionType = TypeAliasType("NewUnionType", int | str)
3567 x: NewUnionType = 42
3568 y: NewUnionType = 'a'
3569 z: NewUnionType = object() # error: Incompatible types in assignment (expression has type "object", variable has type "int | str") [assignment]
3570
3571 T = TypeVar("T")
3572 ListOrSet = TypeAliasType("ListOrSet", list[T] | set[T], type_params=(T,))
3573 a: ListOrSet[int] = [1, 2]
3574 b: ListOrSet[str] = {'a', 'b'}
3575 c: ListOrSet[str] = 'test' # error: Incompatible types in assignment (expression has type "str", variable has type "list[str] | set[str]") [assignment]
3576 ```
3577
3578 `TypeAliasType` was added to the `typing` module in Python 3.12, but it can be used with earlier Python releases by importing from `typing_extensions`.
3579
3580 This feature was contributed by Ali Hamdan (PR [16926](https://github.com/python/mypy/pull/16926), PR [17038](https://github.com/python/mypy/pull/17038) and PR [17053](https://github.com/python/mypy/pull/17053))
3581
3582 ### Detect Additional Unsafe Uses of super()
3583
3584 Mypy will reject unsafe uses of `super()` more consistently, when the target has a
3585 trivial (empty) body. Example:
3586
3587 ```python
3588 class Proto(Protocol):
3589 def method(self) -> int: ...
3590
3591 class Sub(Proto):
3592 def method(self) -> int:
3593 return super().meth() # Error (unsafe)
3594 ```
3595
3596 This feature was contributed by Shantanu (PR [16756](https://github.com/python/mypy/pull/16756)).
3597
3598 ### Stubgen Improvements
3599 - Preserve empty tuple annotation (Ali Hamdan, PR [16907](https://github.com/python/mypy/pull/16907))
3600 - Add support for PEP 570 positional-only parameters (Ali Hamdan, PR [16904](https://github.com/python/mypy/pull/16904))
3601 - Replace obsolete typing aliases with builtin containers (Ali Hamdan, PR [16780](https://github.com/python/mypy/pull/16780))
3602 - Fix generated dataclass `__init__` signature (Ali Hamdan, PR [16906](https://github.com/python/mypy/pull/16906))
3603
3604 ### Mypyc Improvements
3605
3606 - Provide an easier way to define IR-to-IR transforms (Jukka Lehtosalo, PR [16998](https://github.com/python/mypy/pull/16998))
3607 - Implement lowering pass and add primitives for int (in)equality (Jukka Lehtosalo, PR [17027](https://github.com/python/mypy/pull/17027))
3608 - Implement lowering for remaining tagged integer comparisons (Jukka Lehtosalo, PR [17040](https://github.com/python/mypy/pull/17040))
3609 - Optimize away some bool/bit registers (Jukka Lehtosalo, PR [17022](https://github.com/python/mypy/pull/17022))
3610 - Remangle redefined names produced by async with (Richard Si, PR [16408](https://github.com/python/mypy/pull/16408))
3611 - Optimize TYPE_CHECKING to False at Runtime (Srinivas Lade, PR [16263](https://github.com/python/mypy/pull/16263))
3612 - Fix compilation of unreachable comprehensions (Richard Si, PR [15721](https://github.com/python/mypy/pull/15721))
3613 - Don't crash on non-inlinable final local reads (Richard Si, PR [15719](https://github.com/python/mypy/pull/15719))
3614
3615 ### Documentation Improvements
3616 - Import `TypedDict` from `typing` instead of `typing_extensions` (Riccardo Di Maio, PR [16958](https://github.com/python/mypy/pull/16958))
3617 - Add missing `mutable-override` to section title (James Braza, PR [16886](https://github.com/python/mypy/pull/16886))
3618
3619 ### Error Reporting Improvements
3620
3621 - Use lower-case generics more consistently in error messages (Jukka Lehtosalo, PR [17035](https://github.com/python/mypy/pull/17035))
3622
3623 ### Other Notable Changes and Fixes
3624 - Fix incorrect inferred type when accessing descriptor on union type (Matthieu Devlin, PR [16604](https://github.com/python/mypy/pull/16604))
3625 - Fix crash when expanding invalid `Unpack` in a `Callable` alias (Ali Hamdan, PR [17028](https://github.com/python/mypy/pull/17028))
3626 - Fix false positive when string formatting with string enum (roberfi, PR [16555](https://github.com/python/mypy/pull/16555))
3627 - Narrow individual items when matching a tuple to a sequence pattern (Loïc Simon, PR [16905](https://github.com/python/mypy/pull/16905))
3628 - Fix false positive from type variable within TypeGuard or TypeIs (Evgeniy Slobodkin, PR [17071](https://github.com/python/mypy/pull/17071))
3629 - Improve `yield from` inference for unions of generators (Shantanu, PR [16717](https://github.com/python/mypy/pull/16717))
3630 - Fix emulating hash method logic in `attrs` classes (Hashem, PR [17016](https://github.com/python/mypy/pull/17016))
3631 - Add reverted typeshed commit that uses `ParamSpec` for `functools.wraps` (Tamir Duberstein, PR [16942](https://github.com/python/mypy/pull/16942))
3632 - Fix type narrowing for `types.EllipsisType` (Shantanu, PR [17003](https://github.com/python/mypy/pull/17003))
3633 - Fix single item enum match type exhaustion (Oskari Lehto, PR [16966](https://github.com/python/mypy/pull/16966))
3634 - Improve type inference with empty collections (Marc Mueller, PR [16994](https://github.com/python/mypy/pull/16994))
3635 - Fix override checking for decorated property (Shantanu, PR [16856](https://github.com/python/mypy/pull/16856))
3636 - Fix narrowing on match with function subject (Edward Paget, PR [16503](https://github.com/python/mypy/pull/16503))
3637 - Allow `+N` within `Literal[...]` (Spencer Brown, PR [16910](https://github.com/python/mypy/pull/16910))
3638 - Experimental: Support TypedDict within `type[...]` (Marc Mueller, PR [16963](https://github.com/python/mypy/pull/16963))
3639 - Experimtental: Fix issue with TypedDict with optional keys in `type[...]` (Marc Mueller, PR [17068](https://github.com/python/mypy/pull/17068))
3640
3641 ### Typeshed Updates
3642
3643 Please see [git log](https://github.com/python/typeshed/commits/main?after=6dda799d8ad1d89e0f8aad7ac41d2d34bd838ace+0&branch=main&path=stdlib) for full list of standard library typeshed stub changes.
3644
3645 ### Mypy 1.10.1
3646
3647 - Fix error reporting on cached run after uninstallation of third party library (Shantanu, PR [17420](https://github.com/python/mypy/pull/17420))
3648
3649 ### Acknowledgements
3650 Thanks to all mypy contributors who contributed to this release:
3651
3652 - Alex Waygood
3653 - Ali Hamdan
3654 - Edward Paget
3655 - Evgeniy Slobodkin
3656 - Hashem
3657 - hesam
3658 - Hugo van Kemenade
3659 - Ihor
3660 - James Braza
3661 - Jelle Zijlstra
3662 - jhance
3663 - Jukka Lehtosalo
3664 - Loïc Simon
3665 - Marc Mueller
3666 - Matthieu Devlin
3667 - Michael R. Crusoe
3668 - Nikita Sobolev
3669 - Oskari Lehto
3670 - Riccardo Di Maio
3671 - Richard Si
3672 - roberfi
3673 - Roman Solomatin
3674 - Sam Xifaras
3675 - Shantanu
3676 - Spencer Brown
3677 - Srinivas Lade
3678 - Tamir Duberstein
3679 - youkaichao
3680
3681 I’d also like to thank my employer, Dropbox, for supporting mypy development.
3682
3683
3684 ## Mypy 1.9
3685
3686 We’ve just uploaded mypy 1.9 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:
3687
3688 python3 -m pip install -U mypy
3689
3690 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
3691
3692 ### Breaking Changes
3693
3694 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))
3695
3696 We are planning to enable
3697 [local partial types](https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-local-partial-types) (enabled via the
3698 `--local-partial-types` flag) later this year by default. This change
3699 was announced years ago, but now it's finally happening. This is a
3700 major backward-incompatible change, so we'll probably include it as
3701 part of the upcoming mypy 2.0 release. This makes daemon and
3702 non-daemon mypy runs have the same behavior by default.
3703
3704 Local partial types can also be enabled in the mypy config file:
3705 ```
3706 local_partial_types = True
3707 ```
3708
3709 We are looking at providing a tool to make it easier to migrate
3710 projects to use `--local-partial-types`, but it's not yet clear whether
3711 this is practical. The migration usually involves adding some
3712 explicit type annotations to module-level and class-level variables.
3713
3714 ### Basic Support for Type Parameter Defaults (PEP 696)
3715
3716 This release contains new experimental support for type parameter
3717 defaults ([PEP 696](https://peps.python.org/pep-0696)). Please try it
3718 out! This feature was contributed by Marc Mueller.
3719
3720 Since this feature will be officially introduced in the next Python
3721 feature release (3.13), you will need to import `TypeVar`, `ParamSpec`
3722 or `TypeVarTuple` from `typing_extensions` to use defaults for now.
3723
3724 This example adapted from the PEP defines a default for `BotT`:
3725 ```python
3726 from typing import Generic
3727 from typing_extensions import TypeVar
3728
3729 class Bot: ...
3730
3731 BotT = TypeVar("BotT", bound=Bot, default=Bot)
3732
3733 class Context(Generic[BotT]):
3734 bot: BotT
3735
3736 class MyBot(Bot): ...
3737
3738 # type is Bot (the default)
3739 reveal_type(Context().bot)
3740 # type is MyBot
3741 reveal_type(Context[MyBot]().bot)
3742 ```
3743
3744 ### Type-checking Improvements
3745 * Fix missing type store for overloads (Marc Mueller, PR [16803](https://github.com/python/mypy/pull/16803))
3746 * Fix `'WriteToConn' object has no attribute 'flush'` (Charlie Denton, PR [16801](https://github.com/python/mypy/pull/16801))
3747 * Improve TypeAlias error messages (Marc Mueller, PR [16831](https://github.com/python/mypy/pull/16831))
3748 * Support narrowing unions that include `type[None]` (Christoph Tyralla, PR [16315](https://github.com/python/mypy/pull/16315))
3749 * Support TypedDict functional syntax as class base type (anniel-stripe, PR [16703](https://github.com/python/mypy/pull/16703))
3750 * Accept multiline quoted annotations (Shantanu, PR [16765](https://github.com/python/mypy/pull/16765))
3751 * Allow unary + in `Literal` (Jelle Zijlstra, PR [16729](https://github.com/python/mypy/pull/16729))
3752 * Substitute type variables in return type of static methods (Kouroche Bouchiat, PR [16670](https://github.com/python/mypy/pull/16670))
3753 * Consider TypeVarTuple to be invariant (Marc Mueller, PR [16759](https://github.com/python/mypy/pull/16759))
3754 * Add `alias` support to `field()` in `attrs` plugin (Nikita Sobolev, PR [16610](https://github.com/python/mypy/pull/16610))
3755 * Improve attrs hashability detection (Tin Tvrtković, PR [16556](https://github.com/python/mypy/pull/16556))
3756
3757 ### Performance Improvements
3758
3759 * Speed up finding function type variables (Jukka Lehtosalo, PR [16562](https://github.com/python/mypy/pull/16562))
3760
3761 ### Documentation Updates
3762
3763 * Document supported values for `--enable-incomplete-feature` in "mypy --help" (Froger David, PR [16661](https://github.com/python/mypy/pull/16661))
3764 * Update new type system discussion links (thomaswhaley, PR [16841](https://github.com/python/mypy/pull/16841))
3765 * Add missing class instantiation to cheat sheet (Aleksi Tarvainen, PR [16817](https://github.com/python/mypy/pull/16817))
3766 * Document how evil `--no-strict-optional` is (Shantanu, PR [16731](https://github.com/python/mypy/pull/16731))
3767 * Improve mypy daemon documentation note about local partial types (Makonnen Makonnen, PR [16782](https://github.com/python/mypy/pull/16782))
3768 * Fix numbering error (Stefanie Molin, PR [16838](https://github.com/python/mypy/pull/16838))
3769 * Various documentation improvements (Shantanu, PR [16836](https://github.com/python/mypy/pull/16836))
3770
3771 ### Stubtest Improvements
3772 * 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))
3773 * Ignore a new protocol dunder (Alex Waygood, PR [16895](https://github.com/python/mypy/pull/16895))
3774 * Private parameters can be omitted (Sebastian Rittau, PR [16507](https://github.com/python/mypy/pull/16507))
3775 * Add support for setting enum members to "..." (Jelle Zijlstra, PR [16807](https://github.com/python/mypy/pull/16807))
3776 * Adjust symbol table logic (Shantanu, PR [16823](https://github.com/python/mypy/pull/16823))
3777 * Fix posisitional-only handling in overload resolution (Shantanu, PR [16750](https://github.com/python/mypy/pull/16750))
3778
3779 ### Stubgen Improvements
3780 * Fix crash on star unpack of TypeVarTuple (Ali Hamdan, PR [16869](https://github.com/python/mypy/pull/16869))
3781 * Use PEP 604 unions everywhere (Ali Hamdan, PR [16519](https://github.com/python/mypy/pull/16519))
3782 * Do not ignore property deleter (Ali Hamdan, PR [16781](https://github.com/python/mypy/pull/16781))
3783 * Support type stub generation for `staticmethod` (WeilerMarcel, PR [14934](https://github.com/python/mypy/pull/14934))
3784
3785 ### Acknowledgements
3786
3787 ​Thanks to all mypy contributors who contributed to this release:
3788
3789 - Aleksi Tarvainen
3790 - Alex Waygood
3791 - Ali Hamdan
3792 - anniel-stripe
3793 - Charlie Denton
3794 - Christoph Tyralla
3795 - Dheeraj
3796 - Fabian Keller
3797 - Fabian Lewis
3798 - Froger David
3799 - Ihor
3800 - Jared Hance
3801 - Jelle Zijlstra
3802 - Jukka Lehtosalo
3803 - Kouroche Bouchiat
3804 - Lukas Geiger
3805 - Maarten Huijsmans
3806 - Makonnen Makonnen
3807 - Marc Mueller
3808 - Nikita Sobolev
3809 - Sebastian Rittau
3810 - Shantanu
3811 - Stefanie Molin
3812 - Stephen Morton
3813 - thomaswhaley
3814 - Tin Tvrtković
3815 - WeilerMarcel
3816 - Wesley Collin Wright
3817 - zipperer
3818
3819 I’d also like to thank my employer, Dropbox, for supporting mypy development.
3820
3821 ## Mypy 1.8
3822
3823 We’ve just uploaded mypy 1.8 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:
3824
3825 python3 -m pip install -U mypy
3826
3827 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
3828
3829 ### Type-checking Improvements
3830 * Do not intersect types in isinstance checks if at least one is final (Christoph Tyralla, PR [16330](https://github.com/python/mypy/pull/16330))
3831 * Detect that `@final` class without `__bool__` cannot have falsey instances (Ilya Priven, PR [16566](https://github.com/python/mypy/pull/16566))
3832 * Do not allow `TypedDict` classes with extra keywords (Nikita Sobolev, PR [16438](https://github.com/python/mypy/pull/16438))
3833 * Do not allow class-level keywords for `NamedTuple` (Nikita Sobolev, PR [16526](https://github.com/python/mypy/pull/16526))
3834 * Make imprecise constraints handling more robust (Ivan Levkivskyi, PR [16502](https://github.com/python/mypy/pull/16502))
3835 * Fix strict-optional in extending generic TypedDict (Ivan Levkivskyi, PR [16398](https://github.com/python/mypy/pull/16398))
3836 * Allow type ignores of PEP 695 constructs (Shantanu, PR [16608](https://github.com/python/mypy/pull/16608))
3837 * Enable `type_check_only` support for `TypedDict` and `NamedTuple` (Nikita Sobolev, PR [16469](https://github.com/python/mypy/pull/16469))
3838
3839 ### Performance Improvements
3840 * Add fast path to analyzing special form assignments (Jukka Lehtosalo, PR [16561](https://github.com/python/mypy/pull/16561))
3841
3842 ### Improvements to Error Reporting
3843 * Don't show documentation links for plugin error codes (Ivan Levkivskyi, PR [16383](https://github.com/python/mypy/pull/16383))
3844 * Improve error messages for `super` checks and add more tests (Nikita Sobolev, PR [16393](https://github.com/python/mypy/pull/16393))
3845 * Add error code for mutable covariant override (Ivan Levkivskyi, PR [16399](https://github.com/python/mypy/pull/16399))
3846
3847 ### Stubgen Improvements
3848 * Preserve simple defaults in function signatures (Ali Hamdan, PR [15355](https://github.com/python/mypy/pull/15355))
3849 * Include `__all__` in output (Jelle Zijlstra, PR [16356](https://github.com/python/mypy/pull/16356))
3850 * Fix stubgen regressions with pybind11 and mypy 1.7 (Chad Dombrova, PR [16504](https://github.com/python/mypy/pull/16504))
3851
3852 ### Stubtest Improvements
3853 * Improve handling of unrepresentable defaults (Jelle Zijlstra, PR [16433](https://github.com/python/mypy/pull/16433))
3854 * Print more helpful errors if a function is missing from stub (Alex Waygood, PR [16517](https://github.com/python/mypy/pull/16517))
3855 * Support `@type_check_only` decorator (Nikita Sobolev, PR [16422](https://github.com/python/mypy/pull/16422))
3856 * Warn about missing `__del__` (Shantanu, PR [16456](https://github.com/python/mypy/pull/16456))
3857 * Fix crashes with some uses of `final` and `deprecated` (Shantanu, PR [16457](https://github.com/python/mypy/pull/16457))
3858
3859 ### Fixes to Crashes
3860 * Fix crash with type alias to `Callable[[Unpack[Tuple[Any, ...]]], Any]` (Alex Waygood, PR [16541](https://github.com/python/mypy/pull/16541))
3861 * Fix crash on TypeGuard in `__call__` (Ivan Levkivskyi, PR [16516](https://github.com/python/mypy/pull/16516))
3862 * Fix crash on invalid enum in method (Ivan Levkivskyi, PR [16511](https://github.com/python/mypy/pull/16511))
3863 * Fix crash on unimported Any in TypedDict (Ivan Levkivskyi, PR [16510](https://github.com/python/mypy/pull/16510))
3864
3865 ### Documentation Updates
3866 * Update soft-error-limit default value to -1 (Sveinung Gundersen, PR [16542](https://github.com/python/mypy/pull/16542))
3867 * Support Sphinx 7.x (Michael R. Crusoe, PR [16460](https://github.com/python/mypy/pull/16460))
3868
3869 ### Other Notable Changes and Fixes
3870 * Allow mypy to output a junit file with per-file results (Matthew Wright, PR [16388](https://github.com/python/mypy/pull/16388))
3871
3872 ### Typeshed Updates
3873
3874 Please see [git log](https://github.com/python/typeshed/commits/main?after=4a854366e03dee700109f8e758a08b2457ea2f51+0&branch=main&path=stdlib) for full list of standard library typeshed stub changes.
3875
3876 ### Acknowledgements
3877
3878 ​Thanks to all mypy contributors who contributed to this release:
3879
3880 - Alex Waygood
3881 - Ali Hamdan
3882 - Chad Dombrova
3883 - Christoph Tyralla
3884 - Ilya Priven
3885 - Ivan Levkivskyi
3886 - Jelle Zijlstra
3887 - Jukka Lehtosalo
3888 - Marcel Telka
3889 - Matthew Wright
3890 - Michael R. Crusoe
3891 - Nikita Sobolev
3892 - Ole Peder Brandtzæg
3893 - robjhornby
3894 - Shantanu
3895 - Sveinung Gundersen
3896 - Valentin Stanciu
3897
3898 I’d also like to thank my employer, Dropbox, for supporting mypy development.
3899
3900 Posted by Wesley Collin Wright
3901
3902 ## Mypy 1.7
3903
3904 We’ve just uploaded mypy 1.7 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:
3905
3906 python3 -m pip install -U mypy
3907
3908 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
3909
3910 ### Using TypedDict for `**kwargs` Typing
3911
3912 Mypy now has support for using `Unpack[...]` with a TypedDict type to annotate `**kwargs` arguments enabled by default. Example:
3913
3914 ```python
3915 # Or 'from typing_extensions import ...'
3916 from typing import TypedDict, Unpack
3917
3918 class Person(TypedDict):
3919 name: str
3920 age: int
3921
3922 def foo(**kwargs: Unpack[Person]) -> None:
3923 ...
3924
3925 foo(name="x", age=1) # Ok
3926 foo(name=1) # Error
3927 ```
3928
3929 The definition of `foo` above is equivalent to the one below, with keyword-only arguments `name` and `age`:
3930
3931 ```python
3932 def foo(*, name: str, age: int) -> None:
3933 ...
3934 ```
3935
3936 Refer to [PEP 692](https://peps.python.org/pep-0692/) for more information. Note that unlike in the current version of the PEP, mypy always treats signatures with `Unpack[SomeTypedDict]` as equivalent to their expanded forms with explicit keyword arguments, and there aren't special type checking rules for TypedDict arguments.
3937
3938 This was contributed by Ivan Levkivskyi back in 2022 (PR [13471](https://github.com/python/mypy/pull/13471)).
3939
3940 ### TypeVarTuple Support Enabled (Experimental)
3941
3942 Mypy now has support for variadic generics (TypeVarTuple) enabled by default, as an experimental feature. Refer to [PEP 646](https://peps.python.org/pep-0646/) for the details.
3943
3944 TypeVarTuple was implemented by Jared Hance and Ivan Levkivskyi over several mypy releases, with help from Jukka Lehtosalo.
3945
3946 Changes included in this release:
3947
3948 * Fix handling of tuple type context with unpacks (Ivan Levkivskyi, PR [16444](https://github.com/python/mypy/pull/16444))
3949 * Handle TypeVarTuples when checking overload constraints (robjhornby, PR [16428](https://github.com/python/mypy/pull/16428))
3950 * Enable Unpack/TypeVarTuple support (Ivan Levkivskyi, PR [16354](https://github.com/python/mypy/pull/16354))
3951 * Fix crash on unpack call special-casing (Ivan Levkivskyi, PR [16381](https://github.com/python/mypy/pull/16381))
3952 * Some final touches for variadic types support (Ivan Levkivskyi, PR [16334](https://github.com/python/mypy/pull/16334))
3953 * Support PEP-646 and PEP-692 in the same callable (Ivan Levkivskyi, PR [16294](https://github.com/python/mypy/pull/16294))
3954 * Support new `*` syntax for variadic types (Ivan Levkivskyi, PR [16242](https://github.com/python/mypy/pull/16242))
3955 * Correctly handle variadic instances with empty arguments (Ivan Levkivskyi, PR [16238](https://github.com/python/mypy/pull/16238))
3956 * Correctly handle runtime type applications of variadic types (Ivan Levkivskyi, PR [16240](https://github.com/python/mypy/pull/16240))
3957 * Support variadic tuple packing/unpacking (Ivan Levkivskyi, PR [16205](https://github.com/python/mypy/pull/16205))
3958 * Better support for variadic calls and indexing (Ivan Levkivskyi, PR [16131](https://github.com/python/mypy/pull/16131))
3959 * Subtyping and inference of user-defined variadic types (Ivan Levkivskyi, PR [16076](https://github.com/python/mypy/pull/16076))
3960 * Complete type analysis of variadic types (Ivan Levkivskyi, PR [15991](https://github.com/python/mypy/pull/15991))
3961
3962 ### New Way of Installing Mypyc Dependencies
3963
3964 If you want to install package dependencies needed by mypyc (not just mypy), you should now install `mypy[mypyc]` instead of just `mypy`:
3965
3966 ```
3967 python3 -m pip install -U 'mypy[mypyc]'
3968 ```
3969
3970 Mypy has many more users than mypyc, so always installing mypyc dependencies would often bring unnecessary dependencies.
3971
3972 This change was contributed by Shantanu (PR [16229](https://github.com/python/mypy/pull/16229)).
3973
3974 ### New Rules for Re-exports
3975
3976 Mypy no longer considers an import such as `import a.b as b` as an explicit re-export. The old behavior was arguably inconsistent and surprising. This may impact some stub packages, such as older versions of `types-six`. You can change the import to `from a import b as b`, if treating the import as a re-export was intentional.
3977
3978 This change was contributed by Anders Kaseorg (PR [14086](https://github.com/python/mypy/pull/14086)).
3979
3980 ### Improved Type Inference
3981
3982 The new type inference algorithm that was recently introduced to mypy (but was not enabled by default) is now enabled by default. It improves type inference of calls to generic callables where an argument is also a generic callable, in particular. You can use `--old-type-inference` to disable the new behavior.
3983
3984 The new algorithm can (rarely) produce different error messages, different error codes, or errors reported on different lines. This is more likely in cases where generic types were used incorrectly.
3985
3986 The new type inference algorithm was contributed by Ivan Levkivskyi. PR [16345](https://github.com/python/mypy/pull/16345) enabled it by default.
3987
3988 ### Narrowing Tuple Types Using len()
3989
3990 Mypy now can narrow tuple types using `len()` checks. Example:
3991
3992 ```python
3993 def f(t: tuple[int, int] | tuple[int, int, int]) -> None:
3994 if len(t) == 2:
3995 a, b = t # Ok
3996 ...
3997 ```
3998
3999 This feature was contributed by Ivan Levkivskyi (PR [16237](https://github.com/python/mypy/pull/16237)).
4000
4001 ### More Precise Tuple Lengths (Experimental)
4002
4003 Mypy supports experimental, more precise checking of tuple type lengths through `--enable-incomplete-feature=PreciseTupleTypes`. Refer to the [documentation](https://mypy.readthedocs.io/en/latest/command_line.html#enabling-incomplete-experimental-features) for more information.
4004
4005 More generally, we are planning to use `--enable-incomplete-feature` to introduce experimental features that would benefit from community feedback.
4006
4007 This feature was contributed by Ivan Levkivskyi (PR [16237](https://github.com/python/mypy/pull/16237)).
4008
4009 ### Mypy Changelog
4010
4011 We now maintain a [changelog](https://github.com/python/mypy/blob/master/CHANGELOG.md) in the mypy Git repository. It mirrors the contents of [mypy release blog posts](https://mypy-lang.blogspot.com/). We will continue to also publish release blog posts. In the future, release blog posts will be created based on the changelog near a release date.
4012
4013 This was contributed by Shantanu (PR [16280](https://github.com/python/mypy/pull/16280)).
4014
4015 ### Mypy Daemon Improvements
4016
4017 * Fix daemon crash caused by deleted submodule (Jukka Lehtosalo, PR [16370](https://github.com/python/mypy/pull/16370))
4018 * Fix file reloading in dmypy with --export-types (Ivan Levkivskyi, PR [16359](https://github.com/python/mypy/pull/16359))
4019 * Fix dmypy inspect on Windows (Ivan Levkivskyi, PR [16355](https://github.com/python/mypy/pull/16355))
4020 * Fix dmypy inspect for namespace packages (Ivan Levkivskyi, PR [16357](https://github.com/python/mypy/pull/16357))
4021 * Fix return type change to optional in generic function (Jukka Lehtosalo, PR [16342](https://github.com/python/mypy/pull/16342))
4022 * Fix daemon false positives related to module-level `__getattr__` (Jukka Lehtosalo, PR [16292](https://github.com/python/mypy/pull/16292))
4023 * Fix daemon crash related to ABCs (Jukka Lehtosalo, PR [16275](https://github.com/python/mypy/pull/16275))
4024 * Stream dmypy output instead of dumping everything at the end (Valentin Stanciu, PR [16252](https://github.com/python/mypy/pull/16252))
4025 * Make sure all dmypy errors are shown (Valentin Stanciu, PR [16250](https://github.com/python/mypy/pull/16250))
4026
4027 ### Mypyc Improvements
4028
4029 * Generate error on duplicate function definitions (Jukka Lehtosalo, PR [16309](https://github.com/python/mypy/pull/16309))
4030 * Don't crash on unreachable statements (Jukka Lehtosalo, PR [16311](https://github.com/python/mypy/pull/16311))
4031 * Avoid cyclic reference in nested functions (Jukka Lehtosalo, PR [16268](https://github.com/python/mypy/pull/16268))
4032 * Fix direct `__dict__` access on inner functions in new Python (Shantanu, PR [16084](https://github.com/python/mypy/pull/16084))
4033 * Make tuple packing and unpacking more efficient (Jukka Lehtosalo, PR [16022](https://github.com/python/mypy/pull/16022))
4034
4035 ### Improvements to Error Reporting
4036
4037 * Update starred expression error message to match CPython (Cibin Mathew, PR [16304](https://github.com/python/mypy/pull/16304))
4038 * Fix error code of "Maybe you forgot to use await" note (Jelle Zijlstra, PR [16203](https://github.com/python/mypy/pull/16203))
4039 * Use error code `[unsafe-overload]` for unsafe overloads, instead of `[misc]` (Randolf Scholz, PR [16061](https://github.com/python/mypy/pull/16061))
4040 * Reword the error message related to void functions (Albert Tugushev, PR [15876](https://github.com/python/mypy/pull/15876))
4041 * Represent bottom type as Never in messages (Shantanu, PR [15996](https://github.com/python/mypy/pull/15996))
4042 * Add hint for AsyncIterator incompatible return type (Ilya Priven, PR [15883](https://github.com/python/mypy/pull/15883))
4043 * Don't suggest stubs packages where the runtime package now ships with types (Alex Waygood, PR [16226](https://github.com/python/mypy/pull/16226))
4044
4045 ### Performance Improvements
4046
4047 * Speed up type argument checking (Jukka Lehtosalo, PR [16353](https://github.com/python/mypy/pull/16353))
4048 * Add fast path for checking self types (Jukka Lehtosalo, PR [16352](https://github.com/python/mypy/pull/16352))
4049 * Cache information about whether file is typeshed file (Jukka Lehtosalo, PR [16351](https://github.com/python/mypy/pull/16351))
4050 * Skip expensive `repr()` in logging call when not needed (Jukka Lehtosalo, PR [16350](https://github.com/python/mypy/pull/16350))
4051
4052 ### Attrs and Dataclass Improvements
4053
4054 * `dataclass.replace`: Allow transformed classes (Ilya Priven, PR [15915](https://github.com/python/mypy/pull/15915))
4055 * `dataclass.replace`: Fall through to typeshed signature (Ilya Priven, PR [15962](https://github.com/python/mypy/pull/15962))
4056 * Document `dataclass_transform` behavior (Ilya Priven, PR [16017](https://github.com/python/mypy/pull/16017))
4057 * `attrs`: Remove fields type check (Ilya Priven, PR [15983](https://github.com/python/mypy/pull/15983))
4058 * `attrs`, `dataclasses`: Don't enforce slots when base class doesn't (Ilya Priven, PR [15976](https://github.com/python/mypy/pull/15976))
4059 * Fix crash on dataclass field / property collision (Nikita Sobolev, PR [16147](https://github.com/python/mypy/pull/16147))
4060
4061 ### Stubgen Improvements
4062
4063 * Write stubs with utf-8 encoding (Jørgen Lind, PR [16329](https://github.com/python/mypy/pull/16329))
4064 * Fix missing property setter in semantic analysis mode (Ali Hamdan, PR [16303](https://github.com/python/mypy/pull/16303))
4065 * Unify C extension and pure python stub generators with object oriented design (Chad Dombrova, PR [15770](https://github.com/python/mypy/pull/15770))
4066 * Multiple fixes to the generated imports (Ali Hamdan, PR [15624](https://github.com/python/mypy/pull/15624))
4067 * Generate valid dataclass stubs (Ali Hamdan, PR [15625](https://github.com/python/mypy/pull/15625))
4068
4069 ### Fixes to Crashes
4070
4071 * Fix incremental mode crash on TypedDict in method (Ivan Levkivskyi, PR [16364](https://github.com/python/mypy/pull/16364))
4072 * Fix crash on star unpack in TypedDict (Ivan Levkivskyi, PR [16116](https://github.com/python/mypy/pull/16116))
4073 * Fix crash on malformed TypedDict in incremental mode (Ivan Levkivskyi, PR [16115](https://github.com/python/mypy/pull/16115))
4074 * Fix crash with report generation on namespace packages (Shantanu, PR [16019](https://github.com/python/mypy/pull/16019))
4075 * Fix crash when parsing error code config with typo (Shantanu, PR [16005](https://github.com/python/mypy/pull/16005))
4076 * Fix `__post_init__()` internal error (Ilya Priven, PR [16080](https://github.com/python/mypy/pull/16080))
4077
4078 ### Documentation Updates
4079
4080 * Make it easier to copy commands from README (Hamir Mahal, PR [16133](https://github.com/python/mypy/pull/16133))
4081 * Document and rename `[overload-overlap]` error code (Shantanu, PR [16074](https://github.com/python/mypy/pull/16074))
4082 * Document `--force-uppercase-builtins` and `--force-union-syntax` (Nikita Sobolev, PR [16049](https://github.com/python/mypy/pull/16049))
4083 * Document `force_union_syntax` and `force_uppercase_builtins` (Nikita Sobolev, PR [16048](https://github.com/python/mypy/pull/16048))
4084 * Document we're not tracking relationships between symbols (Ilya Priven, PR [16018](https://github.com/python/mypy/pull/16018))
4085
4086 ### Other Notable Changes and Fixes
4087
4088 * Propagate narrowed types to lambda expressions (Ivan Levkivskyi, PR [16407](https://github.com/python/mypy/pull/16407))
4089 * Avoid importing from `setuptools._distutils` (Shantanu, PR [16348](https://github.com/python/mypy/pull/16348))
4090 * Delete recursive aliases flags (Ivan Levkivskyi, PR [16346](https://github.com/python/mypy/pull/16346))
4091 * Properly use proper subtyping for callables (Ivan Levkivskyi, PR [16343](https://github.com/python/mypy/pull/16343))
4092 * Use upper bound as inference fallback more consistently (Ivan Levkivskyi, PR [16344](https://github.com/python/mypy/pull/16344))
4093 * Add `[unimported-reveal]` error code (Nikita Sobolev, PR [16271](https://github.com/python/mypy/pull/16271))
4094 * Add `|=` and `|` operators support for `TypedDict` (Nikita Sobolev, PR [16249](https://github.com/python/mypy/pull/16249))
4095 * Clarify variance convention for Parameters (Ivan Levkivskyi, PR [16302](https://github.com/python/mypy/pull/16302))
4096 * Correctly recognize `typing_extensions.NewType` (Ganden Schaffner, PR [16298](https://github.com/python/mypy/pull/16298))
4097 * Fix partially defined in the case of missing type maps (Shantanu, PR [15995](https://github.com/python/mypy/pull/15995))
4098 * Use SPDX license identifier (Nikita Sobolev, PR [16230](https://github.com/python/mypy/pull/16230))
4099 * Make `__qualname__` and `__module__` available in class bodies (Anthony Sottile, PR [16215](https://github.com/python/mypy/pull/16215))
4100 * stubtest: Hint when args in stub need to be keyword-only (Alex Waygood, PR [16210](https://github.com/python/mypy/pull/16210))
4101 * Tuple slice should not propagate fallback (Thomas Grainger, PR [16154](https://github.com/python/mypy/pull/16154))
4102 * Fix cases of type object handling for overloads (Shantanu, PR [16168](https://github.com/python/mypy/pull/16168))
4103 * Fix walrus interaction with empty collections (Ivan Levkivskyi, PR [16197](https://github.com/python/mypy/pull/16197))
4104 * Use type variable bound when it appears as actual during inference (Ivan Levkivskyi, PR [16178](https://github.com/python/mypy/pull/16178))
4105 * Use upper bounds as fallback solutions for inference (Ivan Levkivskyi, PR [16184](https://github.com/python/mypy/pull/16184))
4106 * Special-case type inference of empty collections (Ivan Levkivskyi, PR [16122](https://github.com/python/mypy/pull/16122))
4107 * Allow TypedDict unpacking in Callable types (Ivan Levkivskyi, PR [16083](https://github.com/python/mypy/pull/16083))
4108 * Fix inference for overloaded `__call__` with generic self (Shantanu, PR [16053](https://github.com/python/mypy/pull/16053))
4109 * Call dynamic class hook on generic classes (Petter Friberg, PR [16052](https://github.com/python/mypy/pull/16052))
4110 * Preserve implicitly exported types via attribute access (Shantanu, PR [16129](https://github.com/python/mypy/pull/16129))
4111 * Fix a stubtest bug (Alex Waygood)
4112 * Fix `tuple[Any, ...]` subtyping (Shantanu, PR [16108](https://github.com/python/mypy/pull/16108))
4113 * Lenient handling of trivial Callable suffixes (Ivan Levkivskyi, PR [15913](https://github.com/python/mypy/pull/15913))
4114 * Add `add_overloaded_method_to_class` helper for plugins (Nikita Sobolev, PR [16038](https://github.com/python/mypy/pull/16038))
4115 * Bundle `misc/proper_plugin.py` as a part of `mypy` (Nikita Sobolev, PR [16036](https://github.com/python/mypy/pull/16036))
4116 * Fix `case Any()` in match statement (DS/Charlie, PR [14479](https://github.com/python/mypy/pull/14479))
4117 * Make iterable logic more consistent (Shantanu, PR [16006](https://github.com/python/mypy/pull/16006))
4118 * Fix inference for properties with `__call__` (Shantanu, PR [15926](https://github.com/python/mypy/pull/15926))
4119
4120 ### Typeshed Updates
4121
4122 Please see [git log](https://github.com/python/typeshed/commits/main?after=4a854366e03dee700109f8e758a08b2457ea2f51+0&branch=main&path=stdlib) for full list of standard library typeshed stub changes.
4123
4124 ### Acknowledgements
4125
4126 Thanks to all mypy contributors who contributed to this release:
4127
4128 * Albert Tugushev
4129 * Alex Waygood
4130 * Ali Hamdan
4131 * Anders Kaseorg
4132 * Anthony Sottile
4133 * Chad Dombrova
4134 * Cibin Mathew
4135 * dinaldoap
4136 * DS/Charlie
4137 * Eli Schwartz
4138 * Ganden Schaffner
4139 * Hamir Mahal
4140 * Ihor
4141 * Ikko Eltociear Ashimine
4142 * Ilya Priven
4143 * Ivan Levkivskyi
4144 * Jelle Zijlstra
4145 * Jukka Lehtosalo
4146 * Jørgen Lind
4147 * KotlinIsland
4148 * Matt Bogosian
4149 * Nikita Sobolev
4150 * Petter Friberg
4151 * Randolf Scholz
4152 * Shantanu
4153 * Thomas Grainger
4154 * Valentin Stanciu
4155
4156 I’d also like to thank my employer, Dropbox, for supporting mypy development.
4157
4158 Posted by Jukka Lehtosalo
4159
4160 ## Mypy 1.6
4161
4162 [Tuesday, 10 October 2023](https://mypy-lang.blogspot.com/2023/10/mypy-16-released.html)
4163
4164 We’ve just uploaded mypy 1.6 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:
4165
4166 python3 -m pip install -U mypy
4167
4168 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
4169
4170 ### Introduce Error Subcodes for Import Errors
4171
4172 Mypy now uses the error code import-untyped if an import targets an installed library that doesn’t support static type checking, and no stub files are available. Other invalid imports produce the import-not-found error code. They both are subcodes of the import error code, which was previously used for both kinds of import-related errors.
4173
4174 Use \--disable-error-code=import-untyped to only ignore import errors about installed libraries without stubs. This way mypy will still report errors about typos in import statements, for example.
4175
4176 If you use \--warn-unused-ignore or \--strict, mypy will complain if you use \# type: ignore\[import\] to ignore an import error. You are expected to use one of the more specific error codes instead. Otherwise, ignoring the import error code continues to silence both errors.
4177
4178 This feature was contributed by Shantanu (PR [15840](https://github.com/python/mypy/pull/15840), PR [14740](https://github.com/python/mypy/pull/14740)).
4179
4180 ### Remove Support for Targeting Python 3.6 and Earlier
4181
4182 Running mypy with \--python-version 3.6, for example, is no longer supported. Python 3.6 hasn’t been properly supported by mypy for some time now, and this makes it explicit. This was contributed by Nikita Sobolev (PR [15668](https://github.com/python/mypy/pull/15668)).
4183
4184 ### Selective Filtering of \--disallow-untyped-calls Targets
4185
4186 Using \--disallow-untyped-calls could be annoying when using libraries with missing type information, as mypy would generate many errors about code that uses the library. Now you can use \--untyped-calls-exclude=acme, for example, to disable these errors about calls targeting functions defined in the acme package. Refer to the [documentation](https://mypy.readthedocs.io/en/latest/command_line.html#cmdoption-mypy-untyped-calls-exclude) for more information.
4187
4188 This feature was contributed by Ivan Levkivskyi (PR [15845](https://github.com/python/mypy/pull/15845)).
4189
4190 ### Improved Type Inference between Callable Types
4191
4192 Mypy now does a better job inferring type variables inside arguments of callable types. For example, this code fragment now type checks correctly:
4193
4194 ```python
4195 def f(c: Callable[[T, S], None]) -> Callable[[str, T, S], None]: ...
4196 def g(*x: int) -> None: ...
4197
4198 reveal_type(f(g)) # Callable[[str, int, int], None]
4199 ```
4200
4201 This was contributed by Ivan Levkivskyi (PR [15910](https://github.com/python/mypy/pull/15910)).
4202
4203 ### Don’t Consider None and TypeVar to Overlap in Overloads
4204
4205 Mypy now doesn’t consider an overload item with an argument type None to overlap with a type variable:
4206
4207 ```python
4208 @overload
4209 def f(x: None) -> None: ..
4210 @overload
4211 def f(x: T) -> Foo[T]: ...
4212 ...
4213 ```
4214
4215 Previously mypy would generate an error about the definition of f above. This is slightly unsafe if the upper bound of T is object, since the value of the type variable could be None. We relaxed the rules a little, since this solves a common issue.
4216
4217 This feature was contributed by Ivan Levkivskyi (PR [15846](https://github.com/python/mypy/pull/15846)).
4218
4219 ### Improvements to \--new-type-inference
4220
4221 The experimental new type inference algorithm (polymorphic inference) introduced as an opt-in feature in mypy 1.5 has several improvements:
4222
4223 * Improve transitive closure computation during constraint solving (Ivan Levkivskyi, PR [15754](https://github.com/python/mypy/pull/15754))
4224 * Add support for upper bounds and values with \--new-type-inference (Ivan Levkivskyi, PR [15813](https://github.com/python/mypy/pull/15813))
4225 * Basic support for variadic types with \--new-type-inference (Ivan Levkivskyi, PR [15879](https://github.com/python/mypy/pull/15879))
4226 * Polymorphic inference: support for parameter specifications and lambdas (Ivan Levkivskyi, PR [15837](https://github.com/python/mypy/pull/15837))
4227 * Invalidate cache when adding \--new-type-inference (Marc Mueller, PR [16059](https://github.com/python/mypy/pull/16059))
4228
4229 **Note:** We are planning to enable \--new-type-inference by default in mypy 1.7. Please try this out and let us know if you encounter any issues.
4230
4231 ### ParamSpec Improvements
4232
4233 * Support self-types containing ParamSpec (Ivan Levkivskyi, PR [15903](https://github.com/python/mypy/pull/15903))
4234 * Allow “…” in Concatenate, and clean up ParamSpec literals (Ivan Levkivskyi, PR [15905](https://github.com/python/mypy/pull/15905))
4235 * Fix ParamSpec inference for callback protocols (Ivan Levkivskyi, PR [15986](https://github.com/python/mypy/pull/15986))
4236 * Infer ParamSpec constraint from arguments (Ivan Levkivskyi, PR [15896](https://github.com/python/mypy/pull/15896))
4237 * Fix crash on invalid type variable with ParamSpec (Ivan Levkivskyi, PR [15953](https://github.com/python/mypy/pull/15953))
4238 * Fix subtyping between ParamSpecs (Ivan Levkivskyi, PR [15892](https://github.com/python/mypy/pull/15892))
4239
4240 ### Stubgen Improvements
4241
4242 * Add option to include docstrings with stubgen (chylek, PR [13284](https://github.com/python/mypy/pull/13284))
4243 * Add required ... initializer to NamedTuple fields with default values (Nikita Sobolev, PR [15680](https://github.com/python/mypy/pull/15680))
4244
4245 ### Stubtest Improvements
4246
4247 * Fix \_\_mypy-replace false positives (Alex Waygood, PR [15689](https://github.com/python/mypy/pull/15689))
4248 * Fix edge case for bytes enum subclasses (Alex Waygood, PR [15943](https://github.com/python/mypy/pull/15943))
4249 * Generate error if typeshed is missing modules from the stdlib (Alex Waygood, PR [15729](https://github.com/python/mypy/pull/15729))
4250 * Fixes to new check for missing stdlib modules (Alex Waygood, PR [15960](https://github.com/python/mypy/pull/15960))
4251 * Fix stubtest enum.Flag edge case (Alex Waygood, PR [15933](https://github.com/python/mypy/pull/15933))
4252
4253 ### Documentation Improvements
4254
4255 * Do not advertise to create your own assert\_never helper (Nikita Sobolev, PR [15947](https://github.com/python/mypy/pull/15947))
4256 * Fix all the missing references found within the docs (Albert Tugushev, PR [15875](https://github.com/python/mypy/pull/15875))
4257 * Document await-not-async error code (Shantanu, PR [15858](https://github.com/python/mypy/pull/15858))
4258 * Improve documentation of disabling error codes (Shantanu, PR [15841](https://github.com/python/mypy/pull/15841))
4259
4260 ### Other Notable Changes and Fixes
4261
4262 * Make unsupported PEP 695 features (introduced in Python 3.12) give a reasonable error message (Shantanu, PR [16013](https://github.com/python/mypy/pull/16013))
4263 * Remove the \--py2 command-line argument (Marc Mueller, PR [15670](https://github.com/python/mypy/pull/15670))
4264 * Change empty tuple from tuple\[\] to tuple\[()\] in error messages (Nikita Sobolev, PR [15783](https://github.com/python/mypy/pull/15783))
4265 * Fix assert\_type failures when some nodes are deferred (Nikita Sobolev, PR [15920](https://github.com/python/mypy/pull/15920))
4266 * Generate error on unbound TypeVar with values (Nikita Sobolev, PR [15732](https://github.com/python/mypy/pull/15732))
4267 * Fix over-eager types-google-cloud-ndb suggestion (Shantanu, PR [15347](https://github.com/python/mypy/pull/15347))
4268 * Fix type narrowing of \== None and in (None,) conditions (Marti Raudsepp, PR [15760](https://github.com/python/mypy/pull/15760))
4269 * Fix inference for attrs.fields (Shantanu, PR [15688](https://github.com/python/mypy/pull/15688))
4270 * Make “await in non-async function” a non-blocking error and give it an error code (Gregory Santosa, PR [15384](https://github.com/python/mypy/pull/15384))
4271 * Add basic support for decorated overloads (Ivan Levkivskyi, PR [15898](https://github.com/python/mypy/pull/15898))
4272 * Fix TypeVar regression with self types (Ivan Levkivskyi, PR [15945](https://github.com/python/mypy/pull/15945))
4273 * Add \_\_match\_args\_\_ to dataclasses with no fields (Ali Hamdan, PR [15749](https://github.com/python/mypy/pull/15749))
4274 * Include stdout and stderr in dmypy verbose output (Valentin Stanciu, PR [15881](https://github.com/python/mypy/pull/15881))
4275 * Improve match narrowing and reachability analysis (Shantanu, PR [15882](https://github.com/python/mypy/pull/15882))
4276 * Support \_\_bool\_\_ with Literal in \--warn-unreachable (Jannic Warken, PR [15645](https://github.com/python/mypy/pull/15645))
4277 * Fix inheriting from generic @frozen attrs class (Ilya Priven, PR [15700](https://github.com/python/mypy/pull/15700))
4278 * Correctly narrow types for tuple\[type\[X\], ...\] (Nikita Sobolev, PR [15691](https://github.com/python/mypy/pull/15691))
4279 * Don't flag intentionally empty generators unreachable (Ilya Priven, PR [15722](https://github.com/python/mypy/pull/15722))
4280 * Add tox.ini to mypy sdist (Marcel Telka, PR [15853](https://github.com/python/mypy/pull/15853))
4281 * Fix mypyc regression with pretty (Shantanu, PR [16124](https://github.com/python/mypy/pull/16124))
4282
4283 ### Typeshed Updates
4284
4285 Typeshed is now modular and distributed as separate PyPI packages for everything except the standard library stubs. Please see [git log](https://github.com/python/typeshed/commits/main?after=6a8d653a671925b0a3af61729ff8cf3f90c9c662+0&branch=main&path=stdlib) for full list of typeshed changes.
4286
4287 ### Acknowledgements
4288
4289 Thanks to Max Murin, who did most of the release manager work for this release (I just did the final steps).
4290
4291 Thanks to all mypy contributors who contributed to this release:
4292
4293 * Albert Tugushev
4294 * Alex Waygood
4295 * Ali Hamdan
4296 * chylek
4297 * EXPLOSION
4298 * Gregory Santosa
4299 * Ilya Priven
4300 * Ivan Levkivskyi
4301 * Jannic Warken
4302 * KotlinIsland
4303 * Marc Mueller
4304 * Marcel Johannesmann
4305 * Marcel Telka
4306 * Mark Byrne
4307 * Marti Raudsepp
4308 * Max Murin
4309 * Nikita Sobolev
4310 * Shantanu
4311 * Valentin Stanciu
4312
4313 Posted by Jukka Lehtosalo
4314
4315
4316 ## Mypy 1.5
4317
4318 [Thursday, 10 August 2023](https://mypy-lang.blogspot.com/2023/08/mypy-15-released.html)
4319
4320 We’ve just uploaded mypy 1.5 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)). Mypy is a static type checker for Python. This release includes new features, deprecations and bug fixes. You can install it as follows:
4321
4322 python3 -m pip install -U mypy
4323
4324 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
4325
4326 ### Drop Support for Python 3.7
4327
4328 Mypy no longer supports running with Python 3.7, which has reached end-of-life. This was contributed by Shantanu (PR [15566](https://github.com/python/mypy/pull/15566)).
4329
4330 ### Optional Check to Require Explicit @override
4331
4332 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](https://peps.python.org/pep-0698/#strict-enforcement-per-project)). This way mypy will detect accidentally introduced overrides. Example:
4333
4334 ```python
4335 # mypy: enable-error-code="explicit-override"
4336
4337 from typing_extensions import override
4338
4339 class C:
4340 def foo(self) -> None: pass
4341 def bar(self) -> None: pass
4342
4343 class D(C):
4344 # Error: Method "foo" is not using @override but is
4345 # overriding a method
4346 def foo(self) -> None:
4347 ...
4348
4349 @override
4350 def bar(self) -> None: # OK
4351 ...
4352 ```
4353
4354 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.
4355
4356 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.
4357
4358 This feature was contributed by Marc Mueller(PR [15512](https://github.com/python/mypy/pull/15512)).
4359
4360 ### More Flexible TypedDict Creation and Update
4361
4362 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.
4363
4364 Construction using the `**` syntax is now more flexible:
4365
4366 ```python
4367 from typing import TypedDict
4368
4369 class A(TypedDict):
4370 foo: int
4371 bar: int
4372
4373 class B(TypedDict):
4374 foo: int
4375
4376 a: A = {"foo": 1, "bar": 2}
4377 b: B = {"foo": 3}
4378 a2: A = { **a, **b} # OK (previously an error)
4379 ```
4380
4381 You can also call update() with a TypedDict argument that contains a subset of the keys in the updated TypedDict:
4382 ```python
4383 a.update(b) # OK (previously an error)
4384 ```
4385
4386 This feature was contributed by Ivan Levkivskyi (PR [15425](https://github.com/python/mypy/pull/15425)).
4387
4388 ### Deprecated Flag: \--strict-concatenate
4389
4390 The behavior of \--strict-concatenate is now included in the new \--extra-checks flag, and the old flag is deprecated.
4391
4392 ### Optionally Show Links to Error Code Documentation
4393
4394 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.
4395
4396 Example output:
4397 ```
4398 a.py:1: error: Need type annotation for "foo" (hint: "x: List[<type>] = ...") [var-annotated]
4399 a.py:1: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-var-annotated for more info
4400 ```
4401 This was contributed by Ivan Levkivskyi (PR [15449](https://github.com/python/mypy/pull/15449)).
4402
4403 ### Consistently Avoid Type Checking Unreachable Code
4404
4405 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.
4406
4407 This was contributed by Ilya Priven (PR [15386](https://github.com/python/mypy/pull/15386)).
4408
4409 ### Experimental Improved Type Inference for Generic Functions
4410
4411 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.
4412
4413 This feature was contributed by Ivan Levkivskyi (PR [15287](https://github.com/python/mypy/pull/15287)).
4414
4415 ### Partial Support for Python 3.12
4416
4417 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.
4418
4419 * Fix ast warnings for Python 3.12 (Nikita Sobolev, PR [15558](https://github.com/python/mypy/pull/15558))
4420 * mypyc: Fix multiple inheritance with a protocol on Python 3.12 (Jukka Lehtosalo, PR [15572](https://github.com/python/mypy/pull/15572))
4421 * mypyc: Fix self-compilation on Python 3.12 (Jukka Lehtosalo, PR [15582](https://github.com/python/mypy/pull/15582))
4422 * mypyc: Fix 3.12 issue with pickling of instances with \_\_dict\_\_ (Jukka Lehtosalo, PR [15574](https://github.com/python/mypy/pull/15574))
4423 * mypyc: Fix i16 on Python 3.12 (Jukka Lehtosalo, PR [15510](https://github.com/python/mypy/pull/15510))
4424 * mypyc: Fix int operations on Python 3.12 (Jukka Lehtosalo, PR [15470](https://github.com/python/mypy/pull/15470))
4425 * mypyc: Fix generators on Python 3.12 (Jukka Lehtosalo, PR [15472](https://github.com/python/mypy/pull/15472))
4426 * mypyc: Fix classes with \_\_dict\_\_ on 3.12 (Jukka Lehtosalo, PR [15471](https://github.com/python/mypy/pull/15471))
4427 * mypyc: Fix coroutines on Python 3.12 (Jukka Lehtosalo, PR [15469](https://github.com/python/mypy/pull/15469))
4428 * mypyc: Don't use \_PyErr\_ChainExceptions on 3.12, since it's deprecated (Jukka Lehtosalo, PR [15468](https://github.com/python/mypy/pull/15468))
4429 * mypyc: Add Python 3.12 feature macro (Jukka Lehtosalo, PR [15465](https://github.com/python/mypy/pull/15465))
4430
4431 ### Improvements to Dataclasses
4432
4433 * Improve signature of dataclasses.replace (Ilya Priven, PR [14849](https://github.com/python/mypy/pull/14849))
4434 * Fix dataclass/protocol crash on joining types (Ilya Priven, PR [15629](https://github.com/python/mypy/pull/15629))
4435 * Fix strict optional handling in dataclasses (Ivan Levkivskyi, PR [15571](https://github.com/python/mypy/pull/15571))
4436 * Support optional types for custom dataclass descriptors (Marc Mueller, PR [15628](https://github.com/python/mypy/pull/15628))
4437 * Add `__slots__` attribute to dataclasses (Nikita Sobolev, PR [15649](https://github.com/python/mypy/pull/15649))
4438 * Support better \_\_post\_init\_\_ method signature for dataclasses (Nikita Sobolev, PR [15503](https://github.com/python/mypy/pull/15503))
4439
4440 ### Mypyc Improvements
4441
4442 * Support unsigned 8-bit native integer type: mypy\_extensions.u8 (Jukka Lehtosalo, PR [15564](https://github.com/python/mypy/pull/15564))
4443 * Support signed 16-bit native integer type: mypy\_extensions.i16 (Jukka Lehtosalo, PR [15464](https://github.com/python/mypy/pull/15464))
4444 * Define mypy\_extensions.i16 in stubs (Jukka Lehtosalo, PR [15562](https://github.com/python/mypy/pull/15562))
4445 * Document more unsupported features and update supported features (Richard Si, PR [15524](https://github.com/python/mypy/pull/15524))
4446 * Fix final NamedTuple classes (Richard Si, PR [15513](https://github.com/python/mypy/pull/15513))
4447 * Use C99 compound literals for undefined tuple values (Jukka Lehtosalo, PR [15453](https://github.com/python/mypy/pull/15453))
4448 * Don't explicitly assign NULL values in setup functions (Logan Hunt, PR [15379](https://github.com/python/mypy/pull/15379))
4449
4450 ### Stubgen Improvements
4451
4452 * Teach stubgen to work with complex and unary expressions (Nikita Sobolev, PR [15661](https://github.com/python/mypy/pull/15661))
4453 * Support ParamSpec and TypeVarTuple (Ali Hamdan, PR [15626](https://github.com/python/mypy/pull/15626))
4454 * Fix crash on non-str docstring (Ali Hamdan, PR [15623](https://github.com/python/mypy/pull/15623))
4455
4456 ### Documentation Updates
4457
4458 * Add documentation for additional error codes (Ivan Levkivskyi, PR [15539](https://github.com/python/mypy/pull/15539))
4459 * Improve documentation of type narrowing (Ilya Priven, PR [15652](https://github.com/python/mypy/pull/15652))
4460 * Small improvements to protocol documentation (Shantanu, PR [15460](https://github.com/python/mypy/pull/15460))
4461 * Remove confusing instance variable example in cheat sheet (Adel Atallah, PR [15441](https://github.com/python/mypy/pull/15441))
4462
4463 ### Other Notable Fixes and Improvements
4464
4465 * Constant fold additional unary and binary expressions (Richard Si, PR [15202](https://github.com/python/mypy/pull/15202))
4466 * Exclude the same special attributes from Protocol as CPython (Kyle Benesch, PR [15490](https://github.com/python/mypy/pull/15490))
4467 * Change the default value of the slots argument of attrs.define to True, to match runtime behavior (Ilya Priven, PR [15642](https://github.com/python/mypy/pull/15642))
4468 * Fix type of class attribute if attribute is defined in both class and metaclass (Alex Waygood, PR [14988](https://github.com/python/mypy/pull/14988))
4469 * Handle type the same as typing.Type in the first argument of classmethods (Erik Kemperman, PR [15297](https://github.com/python/mypy/pull/15297))
4470 * Fix \--find-occurrences flag (Shantanu, PR [15528](https://github.com/python/mypy/pull/15528))
4471 * Fix error location for class patterns (Nikita Sobolev, PR [15506](https://github.com/python/mypy/pull/15506))
4472 * Fix re-added file with errors in mypy daemon (Ivan Levkivskyi, PR [15440](https://github.com/python/mypy/pull/15440))
4473 * Fix dmypy run on Windows (Ivan Levkivskyi, PR [15429](https://github.com/python/mypy/pull/15429))
4474 * Fix abstract and non-abstract variant error for property deleter (Shantanu, PR [15395](https://github.com/python/mypy/pull/15395))
4475 * Remove special casing for "cannot" in error messages (Ilya Priven, PR [15428](https://github.com/python/mypy/pull/15428))
4476 * Add runtime `__slots__` attribute to attrs classes (Nikita Sobolev, PR [15651](https://github.com/python/mypy/pull/15651))
4477 * Add get\_expression\_type to CheckerPluginInterface (Ilya Priven, PR [15369](https://github.com/python/mypy/pull/15369))
4478 * Remove parameters that no longer exist from NamedTuple.\_make() (Alex Waygood, PR [15578](https://github.com/python/mypy/pull/15578))
4479 * Allow using typing.Self in `__all__` with an explicit @staticmethod decorator (Erik Kemperman, PR [15353](https://github.com/python/mypy/pull/15353))
4480 * Fix self types in subclass methods without Self annotation (Ivan Levkivskyi, PR [15541](https://github.com/python/mypy/pull/15541))
4481 * Check for abstract class objects in tuples (Nikita Sobolev, PR [15366](https://github.com/python/mypy/pull/15366))
4482
4483 ### Typeshed Updates
4484
4485 Typeshed is now modular and distributed as separate PyPI packages for everything except the standard library stubs. Please see [git log](https://github.com/python/typeshed/commits/main?after=fc7d4722eaa54803926cee5730e1f784979c0531+0&branch=main&path=stdlib) for full list of typeshed changes.
4486
4487 ### Acknowledgements
4488
4489 Thanks to all mypy contributors who contributed to this release:
4490
4491 * Adel Atallah
4492 * Alex Waygood
4493 * Ali Hamdan
4494 * Erik Kemperman
4495 * Federico Padua
4496 * Ilya Priven
4497 * Ivan Levkivskyi
4498 * Jelle Zijlstra
4499 * Jared Hance
4500 * Jukka Lehtosalo
4501 * Kyle Benesch
4502 * Logan Hunt
4503 * Marc Mueller
4504 * Nikita Sobolev
4505 * Richard Si
4506 * Shantanu
4507 * Stavros Ntentos
4508 * Valentin Stanciu
4509
4510 Posted by Valentin Stanciu
4511
4512
4513 ## Mypy 1.4
4514
4515 [Tuesday, 20 June 2023](https://mypy-lang.blogspot.com/2023/06/mypy-140-released.html)
4516
4517 We’ve just uploaded mypy 1.4 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:
4518
4519 python3 -m pip install -U mypy
4520
4521 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
4522
4523 ### The Override Decorator
4524
4525 Mypy can now ensure that when renaming a method, overrides are also renamed. You can explicitly mark a method as overriding a base class method by using the @typing.override decorator ([PEP 698](https://peps.python.org/pep-0698/)). If the method is then renamed in the base class while the method override is not, mypy will generate an error. The 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.
4526
4527 This feature was contributed byThomas M Kehrenberg (PR [14609](https://github.com/python/mypy/pull/14609)).
4528
4529 ### Propagating Type Narrowing to Nested Functions
4530
4531 Previously, type narrowing was not propagated to nested functions because it would not be sound if the narrowed variable changed between the definition of the nested function and the call site. Mypy will now propagate the narrowed type if the variable is not assigned to after the definition of the nested function:
4532
4533 ```python
4534 def outer(x: str | None = None) -> None:
4535 if x is None:
4536 x = calculate_default()
4537 reveal_type(x) # "str" (narrowed)
4538
4539 def nested() -> None:
4540 reveal_type(x) # Now "str" (used to be "str | None")
4541
4542 nested()
4543 ```
4544
4545 This may generate some new errors because asserts that were previously necessary may become tautological or no-ops.
4546
4547 This was contributed by Jukka Lehtosalo (PR [15133](https://github.com/python/mypy/pull/15133)).
4548
4549 ### Narrowing Enum Values Using “==”
4550
4551 Mypy now allows narrowing enum types using the \== operator. Previously this was only supported when using the is operator. This makes exhaustiveness checking with enum types more usable, as the requirement to use the is operator was not very intuitive. In this example mypy can detect that the developer forgot to handle the value MyEnum.C in example
4552
4553 ```python
4554 from enum import Enum
4555
4556 class MyEnum(Enum):
4557 A = 0
4558 B = 1
4559 C = 2
4560
4561 def example(e: MyEnum) -> str: # Error: Missing return statement
4562 if e == MyEnum.A:
4563 return 'x'
4564 elif e == MyEnum.B:
4565 return 'y'
4566 ```
4567
4568 Adding an extra elif case resolves the error:
4569
4570 ```python
4571 ...
4572 def example(e: MyEnum) -> str: # No error -- all values covered
4573 if e == MyEnum.A:
4574 return 'x'
4575 elif e == MyEnum.B:
4576 return 'y'
4577 elif e == MyEnum.C:
4578 return 'z'
4579 ```
4580
4581 This change can cause false positives in test cases that have assert statements like assert o.x == SomeEnum.X when using \--strict-equality. Example:
4582
4583 ```python
4584 # mypy: strict-equality
4585
4586 from enum import Enum
4587
4588 class MyEnum(Enum):
4589 A = 0
4590 B = 1
4591
4592 class C:
4593 x: MyEnum
4594 ...
4595
4596 def test_something() -> None:
4597 c = C(...)
4598 assert c.x == MyEnum.A
4599 c.do_something_that_changes_x()
4600 assert c.x == MyEnum.B # Error: Non-overlapping equality check
4601 ```
4602
4603 These errors can be ignored using \# type: ignore\[comparison-overlap\], or you can perform the assertion using a temporary variable as a workaround:
4604
4605 ```python
4606 ...
4607 def test_something() -> None:
4608 ...
4609 x = c.x
4610 assert x == MyEnum.A # Does not narrow c.x
4611 c.do_something_that_changes_x()
4612 x = c.x
4613 assert x == MyEnum.B # OK
4614 ```
4615
4616 This feature was contributed by Shantanu (PR [11521](https://github.com/python/mypy/pull/11521)).
4617
4618 ### Performance Improvements
4619
4620 * Speed up simplification of large union types and also fix a recursive tuple crash (Shantanu, PR [15128](https://github.com/python/mypy/pull/15128))
4621 * Speed up union subtyping (Shantanu, PR [15104](https://github.com/python/mypy/pull/15104))
4622 * Don't type check most function bodies when type checking third-party library code, or generally when ignoring errors (Jukka Lehtosalo, PR [14150](https://github.com/python/mypy/pull/14150))
4623
4624 ### Improvements to Plugins
4625
4626 * attrs.evolve: Support generics and unions (Ilya Konstantinov, PR [15050](https://github.com/python/mypy/pull/15050))
4627 * Fix ctypes plugin (Alex Waygood)
4628
4629 ### Fixes to Crashes
4630
4631 * Fix a crash when function-scope recursive alias appears as upper bound (Ivan Levkivskyi, PR [15159](https://github.com/python/mypy/pull/15159))
4632 * Fix crash on follow\_imports\_for\_stubs (Ivan Levkivskyi, PR [15407](https://github.com/python/mypy/pull/15407))
4633 * Fix stubtest crash in explicit init subclass (Shantanu, PR [15399](https://github.com/python/mypy/pull/15399))
4634 * Fix crash when indexing TypedDict with empty key (Shantanu, PR [15392](https://github.com/python/mypy/pull/15392))
4635 * Fix crash on NamedTuple as attribute (Ivan Levkivskyi, PR [15404](https://github.com/python/mypy/pull/15404))
4636 * Correctly track loop depth for nested functions/classes (Ivan Levkivskyi, PR [15403](https://github.com/python/mypy/pull/15403))
4637 * Fix crash on joins with recursive tuples (Ivan Levkivskyi, PR [15402](https://github.com/python/mypy/pull/15402))
4638 * Fix crash with custom ErrorCode subclasses (Marc Mueller, PR [15327](https://github.com/python/mypy/pull/15327))
4639 * Fix crash in dataclass protocol with self attribute assignment (Ivan Levkivskyi, PR [15157](https://github.com/python/mypy/pull/15157))
4640 * Fix crash on lambda in generic context with generic method in body (Ivan Levkivskyi, PR [15155](https://github.com/python/mypy/pull/15155))
4641 * Fix recursive type alias crash in make\_simplified\_union (Ivan Levkivskyi, PR [15216](https://github.com/python/mypy/pull/15216))
4642
4643 ### Improvements to Error Messages
4644
4645 * Use lower-case built-in collection types such as list\[…\] instead of List\[…\] in errors when targeting Python 3.9+ (Max Murin, PR [15070](https://github.com/python/mypy/pull/15070))
4646 * Use X | Y union syntax in error messages when targeting Python 3.10+ (Omar Silva, PR [15102](https://github.com/python/mypy/pull/15102))
4647 * Use type instead of Type in errors when targeting Python 3.9+ (Rohit Sanjay, PR [15139](https://github.com/python/mypy/pull/15139))
4648 * Do not show unused-ignore errors in unreachable code, and make it a real error code (Ivan Levkivskyi, PR [15164](https://github.com/python/mypy/pull/15164))
4649 * Don’t limit the number of errors shown by default (Rohit Sanjay, PR [15138](https://github.com/python/mypy/pull/15138))
4650 * Improver message for truthy functions (madt2709, PR [15193](https://github.com/python/mypy/pull/15193))
4651 * Output distinct types when type names are ambiguous (teresa0605, PR [15184](https://github.com/python/mypy/pull/15184))
4652 * Update message about invalid exception type in try (AJ Rasmussen, PR [15131](https://github.com/python/mypy/pull/15131))
4653 * Add explanation if argument type is incompatible because of an unsupported numbers type (Jukka Lehtosalo, PR [15137](https://github.com/python/mypy/pull/15137))
4654 * Add more detail to 'signature incompatible with supertype' messages for non-callables (Ilya Priven, PR [15263](https://github.com/python/mypy/pull/15263))
4655
4656 ### Documentation Updates
4657
4658 * Add \--local-partial-types note to dmypy docs (Alan Du, PR [15259](https://github.com/python/mypy/pull/15259))
4659 * Update getting started docs for mypyc for Windows (Valentin Stanciu, PR [15233](https://github.com/python/mypy/pull/15233))
4660 * Clarify usage of callables regarding type object in docs (Viicos, PR [15079](https://github.com/python/mypy/pull/15079))
4661 * Clarify difference between disallow\_untyped\_defs and disallow\_incomplete\_defs (Ilya Priven, PR [15247](https://github.com/python/mypy/pull/15247))
4662 * Use attrs and @attrs.define in documentation and tests (Ilya Priven, PR [15152](https://github.com/python/mypy/pull/15152))
4663
4664 ### Mypyc Improvements
4665
4666 * Fix unexpected TypeError for certain variables with an inferred optional type (Richard Si, PR [15206](https://github.com/python/mypy/pull/15206))
4667 * Inline math literals (Logan Hunt, PR [15324](https://github.com/python/mypy/pull/15324))
4668 * Support unpacking mappings in dict display (Richard Si, PR [15203](https://github.com/python/mypy/pull/15203))
4669
4670 ### Changes to Stubgen
4671
4672 * Do not remove Generic from base classes (Ali Hamdan, PR [15316](https://github.com/python/mypy/pull/15316))
4673 * Support yield from statements (Ali Hamdan, PR [15271](https://github.com/python/mypy/pull/15271))
4674 * Fix missing total from TypedDict class (Ali Hamdan, PR [15208](https://github.com/python/mypy/pull/15208))
4675 * Fix call-based namedtuple omitted from class bases (Ali Hamdan, PR [14680](https://github.com/python/mypy/pull/14680))
4676 * Support TypedDict alternative syntax (Ali Hamdan, PR [14682](https://github.com/python/mypy/pull/14682))
4677 * Make stubgen respect MYPY\_CACHE\_DIR (Henrik Bäärnhielm, PR [14722](https://github.com/python/mypy/pull/14722))
4678 * Fixes and simplifications (Ali Hamdan, PR [15232](https://github.com/python/mypy/pull/15232))
4679
4680 ### Other Notable Fixes and Improvements
4681
4682 * Fix nested async functions when using TypeVar value restriction (Jukka Lehtosalo, PR [14705](https://github.com/python/mypy/pull/14705))
4683 * Always allow returning Any from lambda (Ivan Levkivskyi, PR [15413](https://github.com/python/mypy/pull/15413))
4684 * Add foundation for TypeVar defaults (PEP 696) (Marc Mueller, PR [14872](https://github.com/python/mypy/pull/14872))
4685 * Update semantic analyzer for TypeVar defaults (PEP 696) (Marc Mueller, PR [14873](https://github.com/python/mypy/pull/14873))
4686 * Make dict expression inference more consistent (Ivan Levkivskyi, PR [15174](https://github.com/python/mypy/pull/15174))
4687 * Do not block on duplicate base classes (Nikita Sobolev, PR [15367](https://github.com/python/mypy/pull/15367))
4688 * Generate an error when both staticmethod and classmethod decorators are used (Juhi Chandalia, PR [15118](https://github.com/python/mypy/pull/15118))
4689 * Fix assert\_type behaviour with literals (Carl Karsten, PR [15123](https://github.com/python/mypy/pull/15123))
4690 * Fix match subject ignoring redefinitions (Vincent Vanlaer, PR [15306](https://github.com/python/mypy/pull/15306))
4691 * Support `__all__`.remove (Shantanu, PR [15279](https://github.com/python/mypy/pull/15279))
4692
4693 ### Typeshed Updates
4694
4695 Typeshed is now modular and distributed as separate PyPI packages for everything except the standard library stubs. Please see [git log](https://github.com/python/typeshed/commits/main?after=877e06ad1cfd9fd9967c0b0340a86d0c23ea89ce+0&branch=main&path=stdlib) for full list of typeshed changes.
4696
4697 ### Acknowledgements
4698
4699 Thanks to all mypy contributors who contributed to this release:
4700
4701 * Adrian Garcia Badaracco
4702 * AJ Rasmussen
4703 * Alan Du
4704 * Alex Waygood
4705 * Ali Hamdan
4706 * Carl Karsten
4707 * dosisod
4708 * Ethan Smith
4709 * Gregory Santosa
4710 * Heather White
4711 * Henrik Bäärnhielm
4712 * Ilya Konstantinov
4713 * Ilya Priven
4714 * Ivan Levkivskyi
4715 * Juhi Chandalia
4716 * Jukka Lehtosalo
4717 * Logan Hunt
4718 * madt2709
4719 * Marc Mueller
4720 * Max Murin
4721 * Nikita Sobolev
4722 * Omar Silva
4723 * Özgür
4724 * Richard Si
4725 * Rohit Sanjay
4726 * Shantanu
4727 * teresa0605
4728 * Thomas M Kehrenberg
4729 * Tin Tvrtković
4730 * Tushar Sadhwani
4731 * Valentin Stanciu
4732 * Viicos
4733 * Vincent Vanlaer
4734 * Wesley Collin Wright
4735 * William Santosa
4736 * yaegassy
4737
4738 I’d also like to thank my employer, Dropbox, for supporting mypy development.
4739
4740 Posted by Jared Hance
4741
4742
4743 ## Mypy 1.3
4744
4745 [Wednesday, 10 May 2023](https://mypy-lang.blogspot.com/2023/05/mypy-13-released.html)
4746
4747 We’ve just uploaded mypy 1.3 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:
4748
4749 python3 -m pip install -U mypy
4750
4751 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
4752
4753 ### Performance Improvements
4754
4755 * Improve performance of union subtyping (Shantanu, PR [15104](https://github.com/python/mypy/pull/15104))
4756 * Add negative subtype caches (Ivan Levkivskyi, PR [14884](https://github.com/python/mypy/pull/14884))
4757
4758 ### Stub Tooling Improvements
4759
4760 * Stubtest: Check that the stub is abstract if the runtime is, even when the stub is an overloaded method (Alex Waygood, PR [14955](https://github.com/python/mypy/pull/14955))
4761 * Stubtest: Verify stub methods or properties are decorated with @final if they are decorated with @final at runtime (Alex Waygood, PR [14951](https://github.com/python/mypy/pull/14951))
4762 * Stubtest: Fix stubtest false positives with TypedDicts at runtime (Alex Waygood, PR [14984](https://github.com/python/mypy/pull/14984))
4763 * Stubgen: Support @functools.cached\_property (Nikita Sobolev, PR [14981](https://github.com/python/mypy/pull/14981))
4764 * Improvements to stubgenc (Chad Dombrova, PR [14564](https://github.com/python/mypy/pull/14564))
4765
4766 ### Improvements to attrs
4767
4768 * Add support for converters with TypeVars on generic attrs classes (Chad Dombrova, PR [14908](https://github.com/python/mypy/pull/14908))
4769 * Fix attrs.evolve on bound TypeVar (Ilya Konstantinov, PR [15022](https://github.com/python/mypy/pull/15022))
4770
4771 ### Documentation Updates
4772
4773 * Improve async documentation (Shantanu, PR [14973](https://github.com/python/mypy/pull/14973))
4774 * Improvements to cheat sheet (Shantanu, PR [14972](https://github.com/python/mypy/pull/14972))
4775 * Add documentation for bytes formatting error code (Shantanu, PR [14971](https://github.com/python/mypy/pull/14971))
4776 * Convert insecure links to use HTTPS (Marti Raudsepp, PR [14974](https://github.com/python/mypy/pull/14974))
4777 * Also mention overloads in async iterator documentation (Shantanu, PR [14998](https://github.com/python/mypy/pull/14998))
4778 * stubtest: Improve allowlist documentation (Shantanu, PR [15008](https://github.com/python/mypy/pull/15008))
4779 * Clarify "Using types... but not at runtime" (Jon Shea, PR [15029](https://github.com/python/mypy/pull/15029))
4780 * Fix alignment of cheat sheet example (Ondřej Cvacho, PR [15039](https://github.com/python/mypy/pull/15039))
4781 * Fix error for callback protocol matching against callable type object (Shantanu, PR [15042](https://github.com/python/mypy/pull/15042))
4782
4783 ### Error Reporting Improvements
4784
4785 * Improve bytes formatting error (Shantanu, PR [14959](https://github.com/python/mypy/pull/14959))
4786
4787 ### Mypyc Improvements
4788
4789 * Fix unions of bools and ints (Tomer Chachamu, PR [15066](https://github.com/python/mypy/pull/15066))
4790
4791 ### Other Fixes and Improvements
4792
4793 * Fix narrowing union types that include Self with isinstance (Christoph Tyralla, PR [14923](https://github.com/python/mypy/pull/14923))
4794 * Allow objects matching SupportsKeysAndGetItem to be unpacked (Bryan Forbes, PR [14990](https://github.com/python/mypy/pull/14990))
4795 * Check type guard validity for staticmethods (EXPLOSION, PR [14953](https://github.com/python/mypy/pull/14953))
4796 * Fix sys.platform when cross-compiling with emscripten (Ethan Smith, PR [14888](https://github.com/python/mypy/pull/14888))
4797
4798 ### Typeshed Updates
4799
4800 Typeshed is now modular and distributed as separate PyPI packages for everything except the standard library stubs. Please see [git log](https://github.com/python/typeshed/commits/main?after=b0ed50e9392a23e52445b630a808153e0e256976+0&branch=main&path=stdlib) for full list of typeshed changes.
4801
4802 ### Acknowledgements
4803
4804 Thanks to all mypy contributors who contributed to this release:
4805
4806 * Alex Waygood
4807 * Amin Alaee
4808 * Bryan Forbes
4809 * Chad Dombrova
4810 * Charlie Denton
4811 * Christoph Tyralla
4812 * dosisod
4813 * Ethan Smith
4814 * EXPLOSION
4815 * Ilya Konstantinov
4816 * Ivan Levkivskyi
4817 * Jon Shea
4818 * Jukka Lehtosalo
4819 * KotlinIsland
4820 * Marti Raudsepp
4821 * Nikita Sobolev
4822 * Ondřej Cvacho
4823 * Shantanu
4824 * sobolevn
4825 * Tomer Chachamu
4826 * Yaroslav Halchenko
4827
4828 Posted by Wesley Collin Wright.
4829
4830
4831 ## Mypy 1.2
4832
4833 [Thursday, 6 April 2023](https://mypy-lang.blogspot.com/2023/04/mypy-12-released.html)
4834
4835 We’ve just uploaded mypy 1.2 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:
4836
4837 python3 -m pip install -U mypy
4838
4839 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
4840
4841 ### Improvements to Dataclass Transforms
4842
4843 * Support implicit default for "init" parameter in field specifiers (Wesley Collin Wright and Jukka Lehtosalo, PR [15010](https://github.com/python/mypy/pull/15010))
4844 * Support descriptors in dataclass transform (Jukka Lehtosalo, PR [15006](https://github.com/python/mypy/pull/15006))
4845 * Fix frozen\_default in incremental mode (Wesley Collin Wright)
4846 * Fix frozen behavior for base classes with direct metaclasses (Wesley Collin Wright, PR [14878](https://github.com/python/mypy/pull/14878))
4847
4848 ### Mypyc: Native Floats
4849
4850 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.
4851
4852 Various float operations and math functions also now have optimized implementations. Refer to the [documentation](https://mypyc.readthedocs.io/en/latest/float_operations.html) for a full list.
4853
4854 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:
4855
4856 ```python
4857 from lib import MyFloat # MyFloat ia a subclass of "float"
4858
4859 def example() -> None:
4860 x = MyFloat(1.5)
4861 y: float = x # Implicit conversion from MyFloat to float
4862 print(type(y)) # float, not MyFloat
4863 ```
4864
4865 Previously, implicit conversions were applied to int subclasses but not float subclasses.
4866
4867 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:
4868
4869 ```python
4870 def example(n: int) -> None:
4871 a: float = 1 # Error: cannot assign "int" to "float"
4872 b: float = 1.0 # OK
4873 c: float = n # Error
4874 d: float = float(n) # OK
4875 ```
4876
4877 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.
4878
4879 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.
4880
4881 Related changes:
4882
4883 * Use a native unboxed representation for floats (Jukka Lehtosalo, PR [14880](https://github.com/python/mypy/pull/14880))
4884 * Document native floats and integers (Jukka Lehtosalo, PR [14927](https://github.com/python/mypy/pull/14927))
4885 * Fixes to float to int conversion (Jukka Lehtosalo, PR [14936](https://github.com/python/mypy/pull/14936))
4886
4887 ### Mypyc: Native Integers
4888
4889 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.
4890
4891 Simple example:
4892 ```python
4893 from mypy_extensions import i64
4894
4895 def inc(x: i64) -> i64:
4896 return x + 1
4897 ```
4898
4899 Refer to the [documentation](https://mypyc.readthedocs.io/en/latest/using_type_annotations.html#native-integer-types) for more information. This feature was contributed by Jukka Lehtosalo.
4900
4901 ### Other Mypyc Fixes and Improvements
4902
4903 * Support iterating over a TypedDict (Richard Si, PR [14747](https://github.com/python/mypy/pull/14747))
4904 * Faster coercions between different tuple types (Jukka Lehtosalo, PR [14899](https://github.com/python/mypy/pull/14899))
4905 * Faster calls via type aliases (Jukka Lehtosalo, PR [14784](https://github.com/python/mypy/pull/14784))
4906 * Faster classmethod calls via cls (Jukka Lehtosalo, PR [14789](https://github.com/python/mypy/pull/14789))
4907
4908 ### Fixes to Crashes
4909
4910 * Fix crash on class-level import in protocol definition (Ivan Levkivskyi, PR [14926](https://github.com/python/mypy/pull/14926))
4911 * Fix crash on single item union of alias (Ivan Levkivskyi, PR [14876](https://github.com/python/mypy/pull/14876))
4912 * Fix crash on ParamSpec in incremental mode (Ivan Levkivskyi, PR [14885](https://github.com/python/mypy/pull/14885))
4913
4914 ### Documentation Updates
4915
4916 * Update adopting \--strict documentation for 1.0 (Shantanu, PR [14865](https://github.com/python/mypy/pull/14865))
4917 * Some minor documentation tweaks (Jukka Lehtosalo, PR [14847](https://github.com/python/mypy/pull/14847))
4918 * Improve documentation of top level mypy: disable-error-code comment (Nikita Sobolev, PR [14810](https://github.com/python/mypy/pull/14810))
4919
4920 ### Error Reporting Improvements
4921
4922 * Add error code to `typing_extensions` suggestion (Shantanu, PR [14881](https://github.com/python/mypy/pull/14881))
4923 * Add a separate error code for top-level await (Nikita Sobolev, PR [14801](https://github.com/python/mypy/pull/14801))
4924 * Don’t suggest two obsolete stub packages (Jelle Zijlstra, PR [14842](https://github.com/python/mypy/pull/14842))
4925 * Add suggestions for pandas-stubs and lxml-stubs (Shantanu, PR [14737](https://github.com/python/mypy/pull/14737))
4926
4927 ### Other Fixes and Improvements
4928
4929 * Multiple inheritance considers callable objects as subtypes of functions (Christoph Tyralla, PR [14855](https://github.com/python/mypy/pull/14855))
4930 * stubtest: Respect @final runtime decorator and enforce it in stubs (Nikita Sobolev, PR [14922](https://github.com/python/mypy/pull/14922))
4931 * Fix false positives related to type\[<type-var>\] (sterliakov, PR [14756](https://github.com/python/mypy/pull/14756))
4932 * Fix duplication of ParamSpec prefixes and properly substitute ParamSpecs (EXPLOSION, PR [14677](https://github.com/python/mypy/pull/14677))
4933 * Fix line number if `__iter__` is incorrectly reported as missing (Jukka Lehtosalo, PR [14893](https://github.com/python/mypy/pull/14893))
4934 * Fix incompatible overrides of overloaded generics with self types (Shantanu, PR [14882](https://github.com/python/mypy/pull/14882))
4935 * Allow SupportsIndex in slice expressions (Shantanu, PR [14738](https://github.com/python/mypy/pull/14738))
4936 * Support if statements in bodies of dataclasses and classes that use dataclass\_transform (Jacek Chałupka, PR [14854](https://github.com/python/mypy/pull/14854))
4937 * Allow iterable class objects to be unpacked (including enums) (Alex Waygood, PR [14827](https://github.com/python/mypy/pull/14827))
4938 * Fix narrowing for walrus expressions used in match statements (Shantanu, PR [14844](https://github.com/python/mypy/pull/14844))
4939 * Add signature for attr.evolve (Ilya Konstantinov, PR [14526](https://github.com/python/mypy/pull/14526))
4940 * Fix Any inference when unpacking iterators that don't directly inherit from typing.Iterator (Alex Waygood, PR [14821](https://github.com/python/mypy/pull/14821))
4941 * Fix unpack with overloaded `__iter__` method (Nikita Sobolev, PR [14817](https://github.com/python/mypy/pull/14817))
4942 * Reduce size of JSON data in mypy cache (dosisod, PR [14808](https://github.com/python/mypy/pull/14808))
4943 * Improve “used before definition” checks when a local definition has the same name as a global definition (Stas Ilinskiy, PR [14517](https://github.com/python/mypy/pull/14517))
4944 * Honor NoReturn as \_\_setitem\_\_ return type to mark unreachable code (sterliakov, PR [12572](https://github.com/python/mypy/pull/12572))
4945
4946 ### Typeshed Updates
4947
4948 Typeshed is now modular and distributed as separate PyPI packages for everything except the standard library stubs. Please see [git log](https://github.com/python/typeshed/commits/main?after=a544b75320e97424d2d927605316383c755cdac0+0&branch=main&path=stdlib) for full list of typeshed changes.
4949
4950 ### Acknowledgements
4951
4952 Thanks to all mypy contributors who contributed to this release:
4953
4954 * Alex Waygood
4955 * Avasam
4956 * Christoph Tyralla
4957 * dosisod
4958 * EXPLOSION
4959 * Ilya Konstantinov
4960 * Ivan Levkivskyi
4961 * Jacek Chałupka
4962 * Jelle Zijlstra
4963 * Jukka Lehtosalo
4964 * Marc Mueller
4965 * Max Murin
4966 * Nikita Sobolev
4967 * Richard Si
4968 * Shantanu
4969 * Stas Ilinskiy
4970 * sterliakov
4971 * Wesley Collin Wright
4972
4973 Posted by Jukka Lehtosalo
4974
4975
4976 ## Mypy 1.1.1
4977
4978 [Monday, 6 March 2023](https://mypy-lang.blogspot.com/2023/03/mypy-111-released.html)
4979
4980 We’ve just uploaded mypy 1.1.1 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:
4981
4982 python3 -m pip install -U mypy
4983
4984 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
4985
4986 ### Support for `dataclass_transform``
4987
4988 This release adds full support for the dataclass\_transform decorator defined in [PEP 681](https://peps.python.org/pep-0681/#decorator-function-example). This allows decorators, base classes, and metaclasses that generate a \_\_init\_\_ method or other methods based on the properties of that class (similar to dataclasses) to have those methods recognized by mypy.
4989
4990 This was contributed by Wesley Collin Wright.
4991
4992 ### Dedicated Error Code for Method Assignments
4993
4994 Mypy can’t safely check all assignments to methods (a form of monkey patching), so mypy generates an error by default. To make it easier to ignore this error, mypy now uses the new error code method-assign for this. By disabling this error code in a file or globally, mypy will no longer complain about assignments to methods if the signatures are compatible.
4995
4996 Mypy also supports the old error code assignment for these assignments to prevent a backward compatibility break. More generally, we can use this mechanism in the future if we wish to split or rename another existing error code without causing backward compatibility issues.
4997
4998 This was contributed by Ivan Levkivskyi (PR [14570](https://github.com/python/mypy/pull/14570)).
4999
5000 ### Fixes to Crashes
5001
5002 * Fix a crash on walrus in comprehension at class scope (Ivan Levkivskyi, PR [14556](https://github.com/python/mypy/pull/14556))
5003 * Fix crash related to value-constrained TypeVar (Shantanu, PR [14642](https://github.com/python/mypy/pull/14642))
5004
5005 ### Fixes to Cache Corruption
5006
5007 * Fix generic TypedDict/NamedTuple caching (Ivan Levkivskyi, PR [14675](https://github.com/python/mypy/pull/14675))
5008
5009 ### Mypyc Fixes and Improvements
5010
5011 * Raise "non-trait base must be first..." error less frequently (Richard Si, PR [14468](https://github.com/python/mypy/pull/14468))
5012 * Generate faster code for bool comparisons and arithmetic (Jukka Lehtosalo, PR [14489](https://github.com/python/mypy/pull/14489))
5013 * Optimize \_\_(a)enter\_\_/\_\_(a)exit\_\_ for native classes (Jared Hance, PR [14530](https://github.com/python/mypy/pull/14530))
5014 * Detect if attribute definition conflicts with base class/trait (Jukka Lehtosalo, PR [14535](https://github.com/python/mypy/pull/14535))
5015 * Support \_\_(r)divmod\_\_ dunders (Richard Si, PR [14613](https://github.com/python/mypy/pull/14613))
5016 * Support \_\_pow\_\_, \_\_rpow\_\_, and \_\_ipow\_\_ dunders (Richard Si, PR [14616](https://github.com/python/mypy/pull/14616))
5017 * Fix crash on star unpacking to underscore (Ivan Levkivskyi, PR [14624](https://github.com/python/mypy/pull/14624))
5018 * Fix iterating over a union of dicts (Richard Si, PR [14713](https://github.com/python/mypy/pull/14713))
5019
5020 ### Fixes to Detecting Undefined Names (used-before-def)
5021
5022 * Correctly handle walrus operator (Stas Ilinskiy, PR [14646](https://github.com/python/mypy/pull/14646))
5023 * Handle walrus declaration in match subject correctly (Stas Ilinskiy, PR [14665](https://github.com/python/mypy/pull/14665))
5024
5025 ### Stubgen Improvements
5026
5027 Stubgen is a tool for automatically generating draft stubs for libraries.
5028
5029 * Allow aliases below the top level (Chad Dombrova, PR [14388](https://github.com/python/mypy/pull/14388))
5030 * Fix crash with PEP 604 union in type variable bound (Shantanu, PR [14557](https://github.com/python/mypy/pull/14557))
5031 * Preserve PEP 604 unions in generated .pyi files (hamdanal, PR [14601](https://github.com/python/mypy/pull/14601))
5032
5033 ### Stubtest Improvements
5034
5035 Stubtest is a tool for testing that stubs conform to the implementations.
5036
5037 * Update message format so that it’s easier to go to error location (Avasam, PR [14437](https://github.com/python/mypy/pull/14437))
5038 * Handle name-mangling edge cases better (Alex Waygood, PR [14596](https://github.com/python/mypy/pull/14596))
5039
5040 ### Changes to Error Reporting and Messages
5041
5042 * Add new TypedDict error code typeddict-unknown-key (JoaquimEsteves, PR [14225](https://github.com/python/mypy/pull/14225))
5043 * Give arguments a more reasonable location in error messages (Max Murin, PR [14562](https://github.com/python/mypy/pull/14562))
5044 * In error messages, quote just the module's name (Ilya Konstantinov, PR [14567](https://github.com/python/mypy/pull/14567))
5045 * Improve misleading message about Enum() (Rodrigo Silva, PR [14590](https://github.com/python/mypy/pull/14590))
5046 * Suggest importing from `typing_extensions` if definition is not in typing (Shantanu, PR [14591](https://github.com/python/mypy/pull/14591))
5047 * Consistently use type-abstract error code (Ivan Levkivskyi, PR [14619](https://github.com/python/mypy/pull/14619))
5048 * Consistently use literal-required error code for TypedDicts (Ivan Levkivskyi, PR [14621](https://github.com/python/mypy/pull/14621))
5049 * Adjust inconsistent dataclasses plugin error messages (Wesley Collin Wright, PR [14637](https://github.com/python/mypy/pull/14637))
5050 * Consolidate literal bool argument error messages (Wesley Collin Wright, PR [14693](https://github.com/python/mypy/pull/14693))
5051
5052 ### Other Fixes and Improvements
5053
5054 * Check that type guards accept a positional argument (EXPLOSION, PR [14238](https://github.com/python/mypy/pull/14238))
5055 * Fix bug with in operator used with a union of Container and Iterable (Max Murin, PR [14384](https://github.com/python/mypy/pull/14384))
5056 * Support protocol inference for type\[T\] via metaclass (Ivan Levkivskyi, PR [14554](https://github.com/python/mypy/pull/14554))
5057 * Allow overlapping comparisons between bytes-like types (Shantanu, PR [14658](https://github.com/python/mypy/pull/14658))
5058 * Fix mypy daemon documentation link in README (Ivan Levkivskyi, PR [14644](https://github.com/python/mypy/pull/14644))
5059
5060 ### Typeshed Updates
5061
5062 Typeshed is now modular and distributed as separate PyPI packages for everything except the standard library stubs. Please see [git log](https://github.com/python/typeshed/commits/main?after=5ebf892d0710a6e87925b8d138dfa597e7bb11cc+0&branch=main&path=stdlib) for full list of typeshed changes.
5063
5064 ### Acknowledgements
5065
5066 Thanks to all mypy contributors who contributed to this release:
5067
5068 * Alex Waygood
5069 * Avasam
5070 * Chad Dombrova
5071 * dosisod
5072 * EXPLOSION
5073 * hamdanal
5074 * Ilya Konstantinov
5075 * Ivan Levkivskyi
5076 * Jared Hance
5077 * JoaquimEsteves
5078 * Jukka Lehtosalo
5079 * Marc Mueller
5080 * Max Murin
5081 * Michael Lee
5082 * Michael R. Crusoe
5083 * Richard Si
5084 * Rodrigo Silva
5085 * Shantanu
5086 * Stas Ilinskiy
5087 * Wesley Collin Wright
5088 * Yilei "Dolee" Yang
5089 * Yurii Karabas
5090
5091 We’d also like to thank our employer, Dropbox, for funding the mypy core team.
5092
5093 Posted by Max Murin
5094
5095
5096 ## Mypy 1.0
5097
5098 [Monday, 6 February 2023](https://mypy-lang.blogspot.com/2023/02/mypy-10-released.html)
5099
5100 We’ve just uploaded mypy 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:
5101
5102 python3 -m pip install -U mypy
5103
5104 You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
5105
5106 ### New Release Versioning Scheme
5107
5108 Now that mypy reached 1.0, we’ll switch to a new versioning scheme. Mypy version numbers will be of form x.y.z.
5109
5110 Rules:
5111
5112 * The major release number (x) is incremented if a feature release includes a significant backward incompatible change that affects a significant fraction of users.
5113 * The minor release number (y) is incremented on each feature release. Minor releases include updated stdlib stubs from typeshed.
5114 * The point release number (z) is incremented when there are fixes only.
5115
5116 Mypy doesn't use SemVer, since most minor releases have at least minor backward incompatible changes in typeshed, at the very least. Also, many type checking features find new legitimate issues in code. These are not considered backward incompatible changes, unless the number of new errors is very high.
5117
5118 Any significant backward incompatible change must be announced in the blog post for the previous feature release, before making the change. The previous release must also provide a flag to explicitly enable or disable the new behavior (whenever practical), so that users will be able to prepare for the changes and report issues. We should keep the feature flag for at least a few releases after we've switched the default.
5119
5120 See [”Release Process” in the mypy wiki](https://github.com/python/mypy/wiki/Release-Process) for more details and for the most up-to-date version of the versioning scheme.
5121
5122 ### Performance Improvements
5123
5124 Mypy 1.0 is up to 40% faster than mypy 0.991 when type checking the Dropbox internal codebase. We also set up a daily job to measure the performance of the most recent development version of mypy to make it easier to track changes in performance.
5125
5126 Many optimizations contributed to this improvement:
5127
5128 * Improve performance for errors on class with many attributes (Shantanu, PR [14379](https://github.com/python/mypy/pull/14379))
5129 * Speed up make\_simplified\_union (Jukka Lehtosalo, PR [14370](https://github.com/python/mypy/pull/14370))
5130 * Micro-optimize get\_proper\_type(s) (Jukka Lehtosalo, PR [14369](https://github.com/python/mypy/pull/14369))
5131 * Micro-optimize flatten\_nested\_unions (Jukka Lehtosalo, PR [14368](https://github.com/python/mypy/pull/14368))
5132 * Some semantic analyzer micro-optimizations (Jukka Lehtosalo, PR [14367](https://github.com/python/mypy/pull/14367))
5133 * A few miscellaneous micro-optimizations (Jukka Lehtosalo, PR [14366](https://github.com/python/mypy/pull/14366))
5134 * Optimization: Avoid a few uses of contextmanagers in semantic analyzer (Jukka Lehtosalo, PR [14360](https://github.com/python/mypy/pull/14360))
5135 * Optimization: Enable always defined attributes in Type subclasses (Jukka Lehtosalo, PR [14356](https://github.com/python/mypy/pull/14356))
5136 * Optimization: Remove expensive context manager in type analyzer (Jukka Lehtosalo, PR [14357](https://github.com/python/mypy/pull/14357))
5137 * subtypes: fast path for Union/Union subtype check (Hugues, PR [14277](https://github.com/python/mypy/pull/14277))
5138 * Micro-optimization: avoid Bogus\[int\] types that cause needless boxing (Jukka Lehtosalo, PR [14354](https://github.com/python/mypy/pull/14354))
5139 * Avoid slow error message logic if errors not shown to user (Jukka Lehtosalo, PR [14336](https://github.com/python/mypy/pull/14336))
5140 * Speed up the implementation of hasattr() checks (Jukka Lehtosalo, PR [14333](https://github.com/python/mypy/pull/14333))
5141 * Avoid the use of a context manager in hot code path (Jukka Lehtosalo, PR [14331](https://github.com/python/mypy/pull/14331))
5142 * Change various type queries into faster bool type queries (Jukka Lehtosalo, PR [14330](https://github.com/python/mypy/pull/14330))
5143 * Speed up recursive type check (Jukka Lehtosalo, PR [14326](https://github.com/python/mypy/pull/14326))
5144 * Optimize subtype checking by avoiding a nested function (Jukka Lehtosalo, PR [14325](https://github.com/python/mypy/pull/14325))
5145 * Optimize type parameter checks in subtype checking (Jukka Lehtosalo, PR [14324](https://github.com/python/mypy/pull/14324))
5146 * Speed up freshening type variables (Jukka Lehtosalo, PR [14323](https://github.com/python/mypy/pull/14323))
5147 * Optimize implementation of TypedDict types for \*\*kwds (Jukka Lehtosalo, PR [14316](https://github.com/python/mypy/pull/14316))
5148
5149 ### Warn About Variables Used Before Definition
5150
5151 Mypy will now generate an error if you use a variable before it’s defined. This feature is enabled by default. By default mypy reports an error when it infers that a variable is always undefined.
5152 ```python
5153 y = x # E: Name "x" is used before definition [used-before-def]
5154 x = 0
5155 ```
5156 This feature was contributed by Stas Ilinskiy.
5157
5158 ### Detect Possibly Undefined Variables (Experimental)
5159
5160 A new experimental possibly-undefined error code is now available that will detect variables that may be undefined:
5161 ```python
5162 if b:
5163 x = 0
5164 print(x) # Error: Name "x" may be undefined [possibly-undefined]
5165 ```
5166 The error code is disabled be default, since it can generate false positives.
5167
5168 This feature was contributed by Stas Ilinskiy.
5169
5170 ### Support the “Self” Type
5171
5172 There is now a simpler syntax for declaring [generic self types](https://mypy.readthedocs.io/en/stable/generics.html#generic-methods-and-generic-self) introduced in [PEP 673](https://peps.python.org/pep-0673/): the Self type. You no longer have to define a type variable to use “self types”, and you can use them with attributes. Example from mypy documentation:
5173 ```python
5174 from typing import Self
5175
5176 class Friend:
5177 other: Self | None = None
5178
5179 @classmethod
5180 def make_pair(cls) -> tuple[Self, Self]:
5181 a, b = cls(), cls()
5182 a.other = b
5183 b.other = a
5184 return a, b
5185
5186 class SuperFriend(Friend):
5187 pass
5188
5189 # a and b have the inferred type "SuperFriend", not "Friend"
5190 a, b = SuperFriend.make_pair()
5191 ```
5192 The feature was introduced in Python 3.11. In earlier Python versions a backport of Self is available in `typing_extensions`.
5193
5194 This was contributed by Ivan Levkivskyi (PR [14041](https://github.com/python/mypy/pull/14041)).
5195
5196 ### Support ParamSpec in Type Aliases
5197
5198 ParamSpec and Concatenate can now be used in type aliases. Example:
5199 ```python
5200 from typing import ParamSpec, Callable
5201
5202 P = ParamSpec("P")
5203 A = Callable[P, None]
5204
5205 def f(c: A[int, str]) -> None:
5206 c(1, "x")
5207 ```
5208 This feature was contributed by Ivan Levkivskyi (PR [14159](https://github.com/python/mypy/pull/14159)).
5209
5210 ### ParamSpec and Generic Self Types No Longer Experimental
5211
5212 Support for ParamSpec ([PEP 612](https://www.python.org/dev/peps/pep-0612/)) and generic self types are no longer considered experimental.
5213
5214 ### Miscellaneous New Features
5215
5216 * Minimal, partial implementation of dataclass\_transform ([PEP 681](https://peps.python.org/pep-0681/)) (Wesley Collin Wright, PR [14523](https://github.com/python/mypy/pull/14523))
5217 * Add basic support for `typing_extensions`.TypeVar (Marc Mueller, PR [14313](https://github.com/python/mypy/pull/14313))
5218 * Add \--debug-serialize option (Marc Mueller, PR [14155](https://github.com/python/mypy/pull/14155))
5219 * Constant fold initializers of final variables (Jukka Lehtosalo, PR [14283](https://github.com/python/mypy/pull/14283))
5220 * Enable Final instance attributes for attrs (Tin Tvrtković, PR [14232](https://github.com/python/mypy/pull/14232))
5221 * Allow function arguments as base classes (Ivan Levkivskyi, PR [14135](https://github.com/python/mypy/pull/14135))
5222 * Allow super() with mixin protocols (Ivan Levkivskyi, PR [14082](https://github.com/python/mypy/pull/14082))
5223 * Add type inference for dict.keys membership (Matthew Hughes, PR [13372](https://github.com/python/mypy/pull/13372))
5224 * Generate error for class attribute access if attribute is defined with `__slots__` (Harrison McCarty, PR [14125](https://github.com/python/mypy/pull/14125))
5225 * Support additional attributes in callback protocols (Ivan Levkivskyi, PR [14084](https://github.com/python/mypy/pull/14084))
5226
5227 ### Fixes to Crashes
5228
5229 * Fix crash on prefixed ParamSpec with forward reference (Ivan Levkivskyi, PR [14569](https://github.com/python/mypy/pull/14569))
5230 * Fix internal crash when resolving the same partial type twice (Shantanu, PR [14552](https://github.com/python/mypy/pull/14552))
5231 * Fix crash in daemon mode on new import cycle (Ivan Levkivskyi, PR [14508](https://github.com/python/mypy/pull/14508))
5232 * Fix crash in mypy daemon (Ivan Levkivskyi, PR [14497](https://github.com/python/mypy/pull/14497))
5233 * Fix crash on Any metaclass in incremental mode (Ivan Levkivskyi, PR [14495](https://github.com/python/mypy/pull/14495))
5234 * Fix crash in await inside comprehension outside function (Ivan Levkivskyi, PR [14486](https://github.com/python/mypy/pull/14486))
5235 * Fix crash in Self type on forward reference in upper bound (Ivan Levkivskyi, PR [14206](https://github.com/python/mypy/pull/14206))
5236 * Fix a crash when incorrect super() is used outside a method (Ivan Levkivskyi, PR [14208](https://github.com/python/mypy/pull/14208))
5237 * Fix crash on overriding with frozen attrs (Ivan Levkivskyi, PR [14186](https://github.com/python/mypy/pull/14186))
5238 * Fix incremental mode crash on generic function appearing in nested position (Ivan Levkivskyi, PR [14148](https://github.com/python/mypy/pull/14148))
5239 * Fix daemon crash on malformed NamedTuple (Ivan Levkivskyi, PR [14119](https://github.com/python/mypy/pull/14119))
5240 * Fix crash during ParamSpec inference (Ivan Levkivskyi, PR [14118](https://github.com/python/mypy/pull/14118))
5241 * Fix crash on nested generic callable (Ivan Levkivskyi, PR [14093](https://github.com/python/mypy/pull/14093))
5242 * Fix crashes with unpacking SyntaxError (Shantanu, PR [11499](https://github.com/python/mypy/pull/11499))
5243 * Fix crash on partial type inference within a lambda (Ivan Levkivskyi, PR [14087](https://github.com/python/mypy/pull/14087))
5244 * Fix crash with enums (Michael Lee, PR [14021](https://github.com/python/mypy/pull/14021))
5245 * Fix crash with malformed TypedDicts and disllow-any-expr (Michael Lee, PR [13963](https://github.com/python/mypy/pull/13963))
5246
5247 ### Error Reporting Improvements
5248
5249 * More helpful error for missing self (Shantanu, PR [14386](https://github.com/python/mypy/pull/14386))
5250 * Add error-code truthy-iterable (Marc Mueller, PR [13762](https://github.com/python/mypy/pull/13762))
5251 * Fix pluralization in error messages (KotlinIsland, PR [14411](https://github.com/python/mypy/pull/14411))
5252
5253 ### Mypyc: Support Match Statement
5254
5255 Mypyc can now compile Python 3.10 match statements.
5256
5257 This was contributed by dosisod (PR [13953](https://github.com/python/mypy/pull/13953)).
5258
5259 ### Other Mypyc Fixes and Improvements
5260
5261 * Optimize int(x)/float(x)/complex(x) on instances of native classes (Richard Si, PR [14450](https://github.com/python/mypy/pull/14450))
5262 * Always emit warnings (Richard Si, PR [14451](https://github.com/python/mypy/pull/14451))
5263 * Faster bool and integer conversions (Jukka Lehtosalo, PR [14422](https://github.com/python/mypy/pull/14422))
5264 * Support attributes that override properties (Jukka Lehtosalo, PR [14377](https://github.com/python/mypy/pull/14377))
5265 * Precompute set literals for "in" operations and iteration (Richard Si, PR [14409](https://github.com/python/mypy/pull/14409))
5266 * Don't load targets with forward references while setting up non-extension class `__all__` (Richard Si, PR [14401](https://github.com/python/mypy/pull/14401))
5267 * Compile away NewType type calls (Richard Si, PR [14398](https://github.com/python/mypy/pull/14398))
5268 * Improve error message for multiple inheritance (Joshua Bronson, PR [14344](https://github.com/python/mypy/pull/14344))
5269 * Simplify union types (Jukka Lehtosalo, PR [14363](https://github.com/python/mypy/pull/14363))
5270 * Fixes to union simplification (Jukka Lehtosalo, PR [14364](https://github.com/python/mypy/pull/14364))
5271 * Fix for typeshed changes to Collection (Shantanu, PR [13994](https://github.com/python/mypy/pull/13994))
5272 * Allow use of enum.Enum (Shantanu, PR [13995](https://github.com/python/mypy/pull/13995))
5273 * Fix compiling on Arch Linux (dosisod, PR [13978](https://github.com/python/mypy/pull/13978))
5274
5275 ### Documentation Improvements
5276
5277 * Various documentation and error message tweaks (Jukka Lehtosalo, PR [14574](https://github.com/python/mypy/pull/14574))
5278 * Improve Generics documentation (Shantanu, PR [14587](https://github.com/python/mypy/pull/14587))
5279 * Improve protocols documentation (Shantanu, PR [14577](https://github.com/python/mypy/pull/14577))
5280 * Improve dynamic typing documentation (Shantanu, PR [14576](https://github.com/python/mypy/pull/14576))
5281 * Improve the Common Issues page (Shantanu, PR [14581](https://github.com/python/mypy/pull/14581))
5282 * Add a top-level TypedDict page (Shantanu, PR [14584](https://github.com/python/mypy/pull/14584))
5283 * More improvements to getting started documentation (Shantanu, PR [14572](https://github.com/python/mypy/pull/14572))
5284 * Move truthy-function documentation from “optional checks” to “enabled by default” (Anders Kaseorg, PR [14380](https://github.com/python/mypy/pull/14380))
5285 * Avoid use of implicit optional in decorator factory documentation (Tom Schraitle, PR [14156](https://github.com/python/mypy/pull/14156))
5286 * Clarify documentation surrounding install-types (Shantanu, PR [14003](https://github.com/python/mypy/pull/14003))
5287 * Improve searchability for module level type ignore errors (Shantanu, PR [14342](https://github.com/python/mypy/pull/14342))
5288 * Advertise mypy daemon in README (Ivan Levkivskyi, PR [14248](https://github.com/python/mypy/pull/14248))
5289 * Add link to error codes in README (Ivan Levkivskyi, PR [14249](https://github.com/python/mypy/pull/14249))
5290 * Document that report generation disables cache (Ilya Konstantinov, PR [14402](https://github.com/python/mypy/pull/14402))
5291 * Stop saying mypy is beta software (Ivan Levkivskyi, PR [14251](https://github.com/python/mypy/pull/14251))
5292 * Flycheck-mypy is deprecated, since its functionality was merged to Flycheck (Ivan Levkivskyi, PR [14247](https://github.com/python/mypy/pull/14247))
5293 * Update code example in "Declaring decorators" (ChristianWitzler, PR [14131](https://github.com/python/mypy/pull/14131))
5294
5295 ### Stubtest Improvements
5296
5297 Stubtest is a tool for testing that stubs conform to the implementations.
5298
5299 * Improve error message for `__all__`\-related errors (Alex Waygood, PR [14362](https://github.com/python/mypy/pull/14362))
5300 * Improve heuristics for determining whether global-namespace names are imported (Alex Waygood, PR [14270](https://github.com/python/mypy/pull/14270))
5301 * Catch BaseException on module imports (Shantanu, PR [14284](https://github.com/python/mypy/pull/14284))
5302 * Associate exported symbol error with `__all__` object\_path (Nikita Sobolev, PR [14217](https://github.com/python/mypy/pull/14217))
5303 * Add \_\_warningregistry\_\_ to the list of ignored module dunders (Nikita Sobolev, PR [14218](https://github.com/python/mypy/pull/14218))
5304 * If a default is present in the stub, check that it is correct (Jelle Zijlstra, PR [14085](https://github.com/python/mypy/pull/14085))
5305
5306 ### Stubgen Improvements
5307
5308 Stubgen is a tool for automatically generating draft stubs for libraries.
5309
5310 * Treat dlls as C modules (Shantanu, PR [14503](https://github.com/python/mypy/pull/14503))
5311
5312 ### Other Notable Fixes and Improvements
5313
5314 * Update stub suggestions based on recent typeshed changes (Alex Waygood, PR [14265](https://github.com/python/mypy/pull/14265))
5315 * Fix attrs protocol check with cache (Marc Mueller, PR [14558](https://github.com/python/mypy/pull/14558))
5316 * Fix strict equality check if operand item type has custom \_\_eq\_\_ (Jukka Lehtosalo, PR [14513](https://github.com/python/mypy/pull/14513))
5317 * Don't consider object always truthy (Jukka Lehtosalo, PR [14510](https://github.com/python/mypy/pull/14510))
5318 * Properly support union of TypedDicts as dict literal context (Ivan Levkivskyi, PR [14505](https://github.com/python/mypy/pull/14505))
5319 * Properly expand type in generic class with Self and TypeVar with values (Ivan Levkivskyi, PR [14491](https://github.com/python/mypy/pull/14491))
5320 * Fix recursive TypedDicts/NamedTuples defined with call syntax (Ivan Levkivskyi, PR [14488](https://github.com/python/mypy/pull/14488))
5321 * Fix type inference issue when a class inherits from Any (Shantanu, PR [14404](https://github.com/python/mypy/pull/14404))
5322 * Fix false positive on generic base class with six (Ivan Levkivskyi, PR [14478](https://github.com/python/mypy/pull/14478))
5323 * Don't read scripts without extensions as modules in namespace mode (Tim Geypens, PR [14335](https://github.com/python/mypy/pull/14335))
5324 * Fix inference for constrained type variables within unions (Christoph Tyralla, PR [14396](https://github.com/python/mypy/pull/14396))
5325 * Fix Unpack imported from typing (Marc Mueller, PR [14378](https://github.com/python/mypy/pull/14378))
5326 * Allow trailing commas in ini configuration of multiline values (Nikita Sobolev, PR [14240](https://github.com/python/mypy/pull/14240))
5327 * Fix false negatives involving Unions and generators or coroutines (Shantanu, PR [14224](https://github.com/python/mypy/pull/14224))
5328 * Fix ParamSpec constraint for types as callable (Vincent Vanlaer, PR [14153](https://github.com/python/mypy/pull/14153))
5329 * Fix type aliases with fixed-length tuples (Jukka Lehtosalo, PR [14184](https://github.com/python/mypy/pull/14184))
5330 * Fix issues with type aliases and new style unions (Jukka Lehtosalo, PR [14181](https://github.com/python/mypy/pull/14181))
5331 * Simplify unions less aggressively (Ivan Levkivskyi, PR [14178](https://github.com/python/mypy/pull/14178))
5332 * Simplify callable overlap logic (Ivan Levkivskyi, PR [14174](https://github.com/python/mypy/pull/14174))
5333 * Try empty context when assigning to union typed variables (Ivan Levkivskyi, PR [14151](https://github.com/python/mypy/pull/14151))
5334 * Improvements to recursive types (Ivan Levkivskyi, PR [14147](https://github.com/python/mypy/pull/14147))
5335 * Make non-numeric non-empty FORCE\_COLOR truthy (Shantanu, PR [14140](https://github.com/python/mypy/pull/14140))
5336 * Fix to recursive type aliases (Ivan Levkivskyi, PR [14136](https://github.com/python/mypy/pull/14136))
5337 * Correctly handle Enum name on Python 3.11 (Ivan Levkivskyi, PR [14133](https://github.com/python/mypy/pull/14133))
5338 * Fix class objects falling back to metaclass for callback protocol (Ivan Levkivskyi, PR [14121](https://github.com/python/mypy/pull/14121))
5339 * Correctly support self types in callable ClassVar (Ivan Levkivskyi, PR [14115](https://github.com/python/mypy/pull/14115))
5340 * Fix type variable clash in nested positions and in attributes (Ivan Levkivskyi, PR [14095](https://github.com/python/mypy/pull/14095))
5341 * Allow class variable as implementation for read only attribute (Ivan Levkivskyi, PR [14081](https://github.com/python/mypy/pull/14081))
5342 * Prevent warnings from causing dmypy to fail (Andrzej Bartosiński, PR [14102](https://github.com/python/mypy/pull/14102))
5343 * Correctly process nested definitions in mypy daemon (Ivan Levkivskyi, PR [14104](https://github.com/python/mypy/pull/14104))
5344 * Don't consider a branch unreachable if there is a possible promotion (Ivan Levkivskyi, PR [14077](https://github.com/python/mypy/pull/14077))
5345 * Fix incompatible overrides of overloaded methods in concrete subclasses (Shantanu, PR [14017](https://github.com/python/mypy/pull/14017))
5346 * Fix new style union syntax in type aliases (Jukka Lehtosalo, PR [14008](https://github.com/python/mypy/pull/14008))
5347 * Fix and optimise overload compatibility checking (Shantanu, PR [14018](https://github.com/python/mypy/pull/14018))
5348 * Improve handling of redefinitions through imports (Shantanu, PR [13969](https://github.com/python/mypy/pull/13969))
5349 * Preserve (some) implicitly exported types (Shantanu, PR [13967](https://github.com/python/mypy/pull/13967))
5350
5351 ### Typeshed Updates
5352
5353 Typeshed is now modular and distributed as separate PyPI packages for everything except the standard library stubs. Please see [git log](https://github.com/python/typeshed/commits/main?after=ea0ae2155e8a04c9837903c3aff8dd5ad5f36ebc+0&branch=main&path=stdlib) for full list of typeshed changes.
5354
5355 ### Acknowledgements
5356
5357 Thanks to all mypy contributors who contributed to this release:
5358
5359 * Alessio Izzo
5360 * Alex Waygood
5361 * Anders Kaseorg
5362 * Andrzej Bartosiński
5363 * Avasam
5364 * ChristianWitzler
5365 * Christoph Tyralla
5366 * dosisod
5367 * Harrison McCarty
5368 * Hugo van Kemenade
5369 * Hugues
5370 * Ilya Konstantinov
5371 * Ivan Levkivskyi
5372 * Jelle Zijlstra
5373 * jhance
5374 * johnthagen
5375 * Jonathan Daniel
5376 * Joshua Bronson
5377 * Jukka Lehtosalo
5378 * KotlinIsland
5379 * Lakshay Bisht
5380 * Lefteris Karapetsas
5381 * Marc Mueller
5382 * Matthew Hughes
5383 * Michael Lee
5384 * Nick Drozd
5385 * Nikita Sobolev
5386 * Richard Si
5387 * Shantanu
5388 * Stas Ilinskiy
5389 * Tim Geypens
5390 * Tin Tvrtković
5391 * Tom Schraitle
5392 * Valentin Stanciu
5393 * Vincent Vanlaer
5394
5395 We’d also like to thank our employer, Dropbox, for funding the mypy core team.
5396
5397 Posted by Stas Ilinskiy
5398
5399 ## Previous releases
5400
5401 For information about previous releases, refer to the posts at https://mypy-lang.blogspot.com/