Debian Codegraph @

CHANGELOG.md

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