Skip to content

Commit 82d0425

Browse files
Add changelog for mypy 1.12 (#17889)
Related to #17815. --------- Co-authored-by: Jelle Zijlstra <[email protected]>
1 parent 7255ece commit 82d0425

File tree

1 file changed

+286
-0
lines changed

1 file changed

+286
-0
lines changed

CHANGELOG.md

Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,292 @@
22

33
## Next release
44

5+
## Mypy 1.12
6+
7+
We’ve just uploaded mypy 1.12 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)). Mypy is a static type
8+
checker for Python. This release includes new features, performance improvements and bug fixes.
9+
You can install it as follows:
10+
11+
python3 -m pip install -U mypy
12+
13+
You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
14+
15+
### Support Python 3.12 Syntax for Generics (PEP 695)
16+
17+
Support for the new type parameter syntax introduced in Python 3.12 is now enabled by default,
18+
documented, and no longer experimental. It was available through a feature flag in
19+
mypy 1.11 as an experimental feature.
20+
21+
This example demonstrates the new syntax:
22+
23+
```python
24+
# Generic function
25+
def f[T](x: T) -> T: ...
26+
27+
reveal_type(f(1)) # Revealed type is 'int'
28+
29+
# Generic class
30+
class C[T]:
31+
def __init__(self, x: T) -> None:
32+
self.x = x
33+
34+
c = C('a')
35+
reveal_type(c.x) # Revealed type is 'str'
36+
37+
# Type alias
38+
type A[T] = C[list[T]]
39+
```
40+
41+
For more information, refer to the [documentation](https://mypy.readthedocs.io/en/latest/generics.html).
42+
43+
These improvements are included:
44+
45+
* Document Python 3.12 type parameter syntax (Jukka Lehtosalo, PR [17816](https://github.com/python/mypy/pull/17816))
46+
* Further documentation updates (Jukka Lehtosalo, PR [17826](https://github.com/python/mypy/pull/17826))
47+
* Allow Self return types with contravariance (Jukka Lehtosalo, PR [17786](https://github.com/python/mypy/pull/17786))
48+
* Enable new type parameter syntax by default (Jukka Lehtosalo, PR [17798](https://github.com/python/mypy/pull/17798))
49+
* Generate error if new-style type alias used as base class (Jukka Lehtosalo, PR [17789](https://github.com/python/mypy/pull/17789))
50+
* Inherit variance if base class has explicit variance (Jukka Lehtosalo, PR [17787](https://github.com/python/mypy/pull/17787))
51+
* Fix crash on invalid type var reference (Jukka Lehtosalo, PR [17788](https://github.com/python/mypy/pull/17788))
52+
* Fix covariance of frozen dataclasses (Jukka Lehtosalo, PR [17783](https://github.com/python/mypy/pull/17783))
53+
* Allow covariance with attribute that has "`_`" name prefix (Jukka Lehtosalo, PR [17782](https://github.com/python/mypy/pull/17782))
54+
* Support `Annotated[...]` in new-style type aliases (Jukka Lehtosalo, PR [17777](https://github.com/python/mypy/pull/17777))
55+
* Fix nested generic classes (Jukka Lehtosalo, PR [17776](https://github.com/python/mypy/pull/17776))
56+
* 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))
57+
58+
### Basic Support for Python 3.13
59+
60+
This release adds partial support for Python 3.13 features and compiled binaries for
61+
Python 3.13. Mypyc now also supports Python 3.13.
62+
63+
In particular, these features are supported:
64+
* Various new stdlib features and changes (through typeshed stub improvements)
65+
* `typing.ReadOnly` (see below for more)
66+
* `typing.TypeIs` (added in mypy 1.10, [PEP 742](https://peps.python.org/pep-0742/))
67+
* Type parameter defaults when using the legacy syntax ([PEP 696](https://peps.python.org/pep-0696/))
68+
69+
These features are not supported yet:
70+
* `warnings.deprecated` ([PEP 702](https://peps.python.org/pep-0702/))
71+
* Type parameter defaults when using Python 3.12 type parameter syntax
72+
73+
### Mypyc Support for Python 3.13
74+
75+
Mypyc now supports Python 3.13. This was contributed by Marc Mueller, with additional
76+
fixes by Jukka Lehtosalo. Free threaded Python 3.13 builds are not supported yet.
77+
78+
List of changes:
79+
80+
* Add additional includes for Python 3.13 (Marc Mueller, PR [17506](https://github.com/python/mypy/pull/17506))
81+
* Add another include for Python 3.13 (Marc Mueller, PR [17509](https://github.com/python/mypy/pull/17509))
82+
* Fix ManagedDict functions for Python 3.13 (Marc Mueller, PR [17507](https://github.com/python/mypy/pull/17507))
83+
* Update mypyc test output for Python 3.13 (Marc Mueller, PR [17508](https://github.com/python/mypy/pull/17508))
84+
* Fix `PyUnicode` functions for Python 3.13 (Marc Mueller, PR [17504](https://github.com/python/mypy/pull/17504))
85+
* Fix `_PyObject_LookupAttrId` for Python 3.13 (Marc Mueller, PR [17505](https://github.com/python/mypy/pull/17505))
86+
* Fix `_PyList_Extend` for Python 3.13 (Marc Mueller, PR [17503](https://github.com/python/mypy/pull/17503))
87+
* Fix `gen_is_coroutine` for Python 3.13 (Marc Mueller, PR [17501](https://github.com/python/mypy/pull/17501))
88+
* Fix `_PyObject_FastCall` for Python 3.13 (Marc Mueller, PR [17502](https://github.com/python/mypy/pull/17502))
89+
* Avoid uses of `_PyObject_CallMethodOneArg` on 3.13 (Jukka Lehtosalo, PR [17526](https://github.com/python/mypy/pull/17526))
90+
* Don't rely on `_PyType_CalculateMetaclass` on 3.13 (Jukka Lehtosalo, PR [17525](https://github.com/python/mypy/pull/17525))
91+
* Don't use `_PyUnicode_FastCopyCharacters` on 3.13 (Jukka Lehtosalo, PR [17524](https://github.com/python/mypy/pull/17524))
92+
* 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))
93+
94+
### Inferring Unions for Conditional Expressions
95+
96+
Mypy now always tries to infer a union type for a conditional expression if left and right
97+
operand types are different. This results in more precise inferred types and lets mypy detect
98+
more issues. Example:
99+
100+
```python
101+
s = "foo" if cond() else 1
102+
# Type of "s" is now "str | int" (it used to be "object")
103+
```
104+
105+
Notably, if one of the operands has type `Any`, the type of a conditional expression is
106+
now `<type> | Any`. Previously the inferred type was just `Any`. The new type essentially
107+
indicates that the value can be of type `<type>`, and potentially of some (unknown) type.
108+
Most operations performed on the result must also be valid for `<type>`.
109+
Example where this is relevant:
110+
111+
```python
112+
from typing import Any
113+
114+
def func(a: Any, b: bool) -> None:
115+
x = a if b else None
116+
# Type of x is "Any | None"
117+
print(x.y) # Error: None has no attribute "y"
118+
```
119+
120+
This feature was contributed by Ivan Levkivskyi (PR [17427](https://github.com/python/mypy/pull/17427)).
121+
122+
### ReadOnly Support for TypedDict (PEP 705)
123+
124+
You can now use `typing.ReadOnly` to specity TypedDict items as
125+
read-only ([PEP 705](https://peps.python.org/pep-0705/)):
126+
127+
```python
128+
from typing import TypedDict
129+
130+
# Or "from typing ..." on Python 3.13
131+
from typing_extensions import ReadOnly
132+
133+
class TD(TypedDict):
134+
a: int
135+
b: ReadOnly[int]
136+
137+
d: TD = {"a": 1, "b": 2}
138+
d["a"] = 3 # OK
139+
d["b"] = 5 # Error: "b" is ReadOnly
140+
```
141+
142+
This feature was contributed by Nikita Sobolev (PR [17644](https://github.com/python/mypy/pull/17644)).
143+
144+
### Python 3.8 End of Life Approaching
145+
146+
We are planning to drop support for Python 3.8 in the next mypy feature release or the
147+
one after that. Python 3.8 reaches end of life in October 2024.
148+
149+
### Planned Changes to Defaults
150+
151+
We are planning to enable `--local-partial-types` by default in mypy 2.0. This will
152+
often require at least minor code changes. This option is implicitly enabled by mypy
153+
daemon, so this makes the behavior of daemon and non-daemon modes consistent.
154+
155+
We recommend that mypy users start using local partial types soon (or to explicitly disable
156+
them) to prepare for the change.
157+
158+
This can also be configured in a mypy configuration file:
159+
160+
```
161+
local_partial_types = True
162+
```
163+
164+
For more information, refer to the
165+
[documentation](https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-local-partial-types).
166+
167+
### Documentation Updates
168+
169+
Mypy documentation now uses modern syntax variants and imports in many examples. Some
170+
examples no longer work on Python 3.8, which is the earliest Python version that mypy supports.
171+
172+
Notably, `Iterable` and other protocols/ABCs are imported from `collections.abc` instead of
173+
`typing`:
174+
```python
175+
from collections.abc import Iterable, Callable
176+
```
177+
178+
Examples also avoid the upper-case aliases to built-in types: `list[str]` is used instead
179+
of `List[str]`. The `X | Y` union type syntax introduced in Python 3.10 is also now prevalent.
180+
181+
List of documentation updates:
182+
183+
* Document `--output=json` CLI option (Edgar Ramírez Mondragón, PR [17611](https://github.com/python/mypy/pull/17611))
184+
* Update various references to deprecated type aliases in docs (Jukka Lehtosalo, PR [17829](https://github.com/python/mypy/pull/17829))
185+
* Make "X | Y" union syntax more prominent in documentation (Jukka Lehtosalo, PR [17835](https://github.com/python/mypy/pull/17835))
186+
* Discuss upper bounds before self types in documentation (Jukka Lehtosalo, PR [17827](https://github.com/python/mypy/pull/17827))
187+
* Make changelog visible in mypy documentation (quinn-sasha, PR [17742](https://github.com/python/mypy/pull/17742))
188+
* List all incomplete features in `--enable-incomplete-feature` docs (sobolevn, PR [17633](https://github.com/python/mypy/pull/17633))
189+
* Remove the explicit setting of a pygments theme (Pradyun Gedam, PR [17571](https://github.com/python/mypy/pull/17571))
190+
191+
### Experimental Inline TypedDict Syntax
192+
193+
Mypy now supports a non-standard, experimental syntax for defining anonymous TypedDicts.
194+
Example:
195+
196+
```python
197+
def func(n: str, y: int) -> {"name": str, "year": int}:
198+
return {"name": n, "year": y}
199+
```
200+
201+
The feature is disabled by default. Use `--enable-incomplete-feature=InlineTypedDict` to
202+
enable it. *We might remove this feature in a future release.*
203+
204+
This feature was contributed by Ivan Levkivskyi (PR [17457](https://github.com/python/mypy/pull/17457)).
205+
206+
### Stubgen Improvements
207+
208+
* Fix crash on literal class-level keywords (sobolevn, PR [17663](https://github.com/python/mypy/pull/17663))
209+
* Stubgen add `--version` (sobolevn, PR [17662](https://github.com/python/mypy/pull/17662))
210+
* Fix `stubgen --no-analysis/--parse-only` docs (sobolevn, PR [17632](https://github.com/python/mypy/pull/17632))
211+
* Include keyword only args when generating signatures in stubgenc (Eric Mark Martin, PR [17448](https://github.com/python/mypy/pull/17448))
212+
* Add support for detecting `Literal` types when extracting types from docstrings (Michael Carlstrom, PR [17441](https://github.com/python/mypy/pull/17441))
213+
* Use `Generator` type var defaults (Sebastian Rittau, PR [17670](https://github.com/python/mypy/pull/17670))
214+
215+
### Stubtest Improvements
216+
* Add support for `cached_property` (Ali Hamdan, PR [17626](https://github.com/python/mypy/pull/17626))
217+
* Add `enable_incomplete_feature` validation to `stubtest` (sobolevn, PR [17635](https://github.com/python/mypy/pull/17635))
218+
* Fix error code handling in `stubtest` with `--mypy-config-file` (sobolevn, PR [17629](https://github.com/python/mypy/pull/17629))
219+
220+
### Other Notables Fixes and Improvements
221+
222+
* Report error if using unsupported type parameter defaults (Jukka Lehtosalo, PR [17876](https://github.com/python/mypy/pull/17876))
223+
* Fix re-processing cross-reference in mypy daemon when node kind changes (Ivan Levkivskyi, PR [17883](https://github.com/python/mypy/pull/17883))
224+
* Don't use equality to narrow when value is IntEnum/StrEnum (Jukka Lehtosalo, PR [17866](https://github.com/python/mypy/pull/17866))
225+
* Don't consider None vs IntEnum comparison ambiguous (Jukka Lehtosalo, PR [17877](https://github.com/python/mypy/pull/17877))
226+
* Fix narrowing of IntEnum and StrEnum types (Jukka Lehtosalo, PR [17874](https://github.com/python/mypy/pull/17874))
227+
* Filter overload items based on self type during type inference (Jukka Lehtosalo, PR [17873](https://github.com/python/mypy/pull/17873))
228+
* Enable negative narrowing of union TypeVar upper bounds (Brian Schubert, PR [17850](https://github.com/python/mypy/pull/17850))
229+
* Fix issue with member expression formatting (Brian Schubert, PR [17848](https://github.com/python/mypy/pull/17848))
230+
* Avoid type size explosion when expanding types (Jukka Lehtosalo, PR [17842](https://github.com/python/mypy/pull/17842))
231+
* Fix negative narrowing of tuples in match statement (Brian Schubert, PR [17817](https://github.com/python/mypy/pull/17817))
232+
* Narrow falsey str/bytes/int to literal type (Brian Schubert, PR [17818](https://github.com/python/mypy/pull/17818))
233+
* Test against latest Python 3.13, make testing 3.14 easy (Shantanu, PR [17812](https://github.com/python/mypy/pull/17812))
234+
* Reject ParamSpec-typed callables calls with insufficient arguments (Stanislav Terliakov, PR [17323](https://github.com/python/mypy/pull/17323))
235+
* 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))
236+
* Fix TypeVar upper bounds sometimes not being displayed in pretty callables (Brian Schubert, PR [17802](https://github.com/python/mypy/pull/17802))
237+
* Added error code for overlapping function signatures (Katrina Connors, PR [17597](https://github.com/python/mypy/pull/17597))
238+
* Check for `truthy-bool` in `not ...` unary expressions (sobolevn, PR [17773](https://github.com/python/mypy/pull/17773))
239+
* Add missing lines-covered and lines-valid attributes (Soubhik Kumar Mitra, PR [17738](https://github.com/python/mypy/pull/17738))
240+
* Fix another crash scenario with recursive tuple types (Ivan Levkivskyi, PR [17708](https://github.com/python/mypy/pull/17708))
241+
* Resolve TypeVar upper bounds in `functools.partial` (Shantanu, PR [17660](https://github.com/python/mypy/pull/17660))
242+
* Always reset binder when checking deferred nodes (Ivan Levkivskyi, PR [17643](https://github.com/python/mypy/pull/17643))
243+
* Fix crash on a callable attribute with single unpack (Ivan Levkivskyi, PR [17641](https://github.com/python/mypy/pull/17641))
244+
* Fix mismatched signature between checker plugin API and implementation (bzoracler, PR [17343](https://github.com/python/mypy/pull/17343))
245+
* Indexing a type also produces a GenericAlias (Shantanu, PR [17546](https://github.com/python/mypy/pull/17546))
246+
* Fix crash on self-type in callable protocol (Ivan Levkivskyi, PR [17499](https://github.com/python/mypy/pull/17499))
247+
* Fix crash on NamedTuple with method and error in function (Ivan Levkivskyi, PR [17498](https://github.com/python/mypy/pull/17498))
248+
* Add `__replace__` for dataclasses in 3.13 (Max Muoto, PR [17469](https://github.com/python/mypy/pull/17469))
249+
* Fix help message for `--no-namespace-packages` (Raphael Krupinski, PR [17472](https://github.com/python/mypy/pull/17472))
250+
* Fix typechecking for async generators (Danny Yang, PR [17452](https://github.com/python/mypy/pull/17452))
251+
* Fix strict optional handling in attrs plugin (Ivan Levkivskyi, PR [17451](https://github.com/python/mypy/pull/17451))
252+
* Allow mixing ParamSpec and TypeVarTuple in Generic (Ivan Levkivskyi, PR [17450](https://github.com/python/mypy/pull/17450))
253+
254+
### Typeshed Updates
255+
256+
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.
257+
258+
### Acknowledgements
259+
Thanks to all mypy contributors who contributed to this release:
260+
261+
- Ali Hamdan
262+
- Anders Kaseorg
263+
- Bénédikt Tran
264+
- Brian Schubert
265+
- bzoracler
266+
- Danny Yang
267+
- Edgar Ramírez Mondragón
268+
- Eric Mark Martin
269+
- InSync
270+
- Ivan Levkivskyi
271+
- Jordandev678
272+
- Katrina Connors
273+
- Kirill Podoprigora
274+
- Marc Mueller
275+
- Max Muoto
276+
- Max Murin
277+
- Michael Carlstrom
278+
- Michael I Chen
279+
- Pradyun Gedam
280+
- quinn-sasha
281+
- Raphael Krupinski
282+
- Sebastian Rittau
283+
- Shantanu
284+
- sobolevn
285+
- Soubhik Kumar Mitra
286+
- Stanislav Terliakov
287+
- wyattscarpenter
288+
289+
I’d also like to thank my employer, Dropbox, for supporting mypy development.
290+
5291

6292
## Mypy 1.11
7293

0 commit comments

Comments
 (0)