Skip to content

Commit ba68974

Browse files
JukkaLJelleZijlstra
andcommitted
Add changelog for mypy 1.12 (#17889)
Related to #17815. Co-authored-by: Jelle Zijlstra <[email protected]>
1 parent b2deaae commit ba68974

File tree

1 file changed

+117
-18
lines changed

1 file changed

+117
-18
lines changed

CHANGELOG.md

+117-18
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,32 @@ You can read the full documentation for this release on [Read the Docs](http://m
1414

1515
### Support Python 3.12 Syntax for Generics (PEP 695)
1616

17-
Support for the new type parameter syntax introduced in 3.12 is now enabled by default,
17+
Support for the new type parameter syntax introduced in Python 3.12 is now enabled by default,
1818
documented, and no longer experimental. It was available through a feature flag in
1919
mypy 1.11 as an experimental feature.
2020

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+
2143
These improvements are included:
2244

2345
* Document Python 3.12 type parameter syntax (Jukka Lehtosalo, PR [17816](https://github.com/python/mypy/pull/17816))
@@ -35,14 +57,14 @@ These improvements are included:
3557

3658
### Basic Support for Python 3.13
3759

38-
This release adds compiled binaries for Python 3.13 and partial support for Python 3.13
39-
features. Mypyc also now supports Python 3.13.
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.
4062

41-
These features are supported:
63+
In particular, these features are supported:
4264
* Various new stdlib features and changes (through typeshed stub improvements)
4365
* `typing.ReadOnly` (see below for more)
44-
* `typing.TypeIs` (support was added in mypy 1.10)
45-
* Type parameter defaults when using the legacy syntax ([PEP 695](https://peps.python.org/pep-0696/))
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/))
4668

4769
These features are not supported yet:
4870
* `warnings.deprecated` ([PEP 702](https://peps.python.org/pep-0702/))
@@ -71,12 +93,20 @@ List of changes:
7193

7294
### Inferring Unions for Conditional Expressions
7395

74-
Mypy now always tries to infer a union type for a conditional expression. This results in
75-
more precise inferred types and lets mypy detect more issues.
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+
```
76104

77105
Notably, if one of the operands has type `Any`, the type of a conditional expression is
78-
now `<type> | Any`. Previously the inferred type was just `Any`. Example where this is
79-
relevant:
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:
80110

81111
```python
82112
from typing import Any
@@ -89,14 +119,32 @@ def func(a: Any, b: bool) -> None:
89119

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

92-
### ReadOnly Support for TypedDict
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
93132

94-
* Add `ReadOnly` support for TypedDicts (sobolevn, PR [17644](https://github.com/python/mypy/pull/17644))
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)).
95143

96144
### Python 3.8 End of Life Approaching
97145

98146
We are planning to drop support for Python 3.8 in the next mypy feature release or the
99-
one after that. Python 3.8 reaches end of life in Octoboer 2024.
147+
one after that. Python 3.8 reaches end of life in October 2024.
100148

101149
### Planned Changes to Defaults
102150

@@ -121,6 +169,17 @@ For more information, refer to the
121169
Mypy documentation now uses modern syntax variants and imports in many examples. Some
122170
examples no longer work on Python 3.8, which is the earliest Python version that mypy supports.
123171

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+
124183
* Document `--output=json` CLI option (Edgar Ramírez Mondragón, PR [17611](https://github.com/python/mypy/pull/17611))
125184
* Update various references to deprecated type aliases in docs (Jukka Lehtosalo, PR [17829](https://github.com/python/mypy/pull/17829))
126185
* Make "X | Y" union syntax more prominent in documentation (Jukka Lehtosalo, PR [17835](https://github.com/python/mypy/pull/17835))
@@ -129,13 +188,28 @@ examples no longer work on Python 3.8, which is the earliest Python version that
129188
* List all incomplete features in `--enable-incomplete-feature` docs (sobolevn, PR [17633](https://github.com/python/mypy/pull/17633))
130189
* Remove the explicit setting of a pygments theme (Pradyun Gedam, PR [17571](https://github.com/python/mypy/pull/17571))
131190

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+
132206
### Stubgen Improvements
133207

134208
* Fix crash on literal class-level keywords (sobolevn, PR [17663](https://github.com/python/mypy/pull/17663))
135209
* Stubgen add `--version` (sobolevn, PR [17662](https://github.com/python/mypy/pull/17662))
136210
* Fix `stubgen --no-analysis/--parse-only` docs (sobolevn, PR [17632](https://github.com/python/mypy/pull/17632))
137211
* Include keyword only args when generating signatures in stubgenc (Eric Mark Martin, PR [17448](https://github.com/python/mypy/pull/17448))
138-
* Add Literal support for docstrings (Michael Carlstrom, PR [17441](https://github.com/python/mypy/pull/17441))
212+
* Add support for detecting `Literal` types when extracting types from docstrings (Michael Carlstrom, PR [17441](https://github.com/python/mypy/pull/17441))
139213
* Use `Generator` type var defaults (Sebastian Rittau, PR [17670](https://github.com/python/mypy/pull/17670))
140214

141215
### Stubtest Improvements
@@ -152,7 +226,7 @@ examples no longer work on Python 3.8, which is the earliest Python version that
152226
* Fix narrowing of IntEnum and StrEnum types (Jukka Lehtosalo, PR [17874](https://github.com/python/mypy/pull/17874))
153227
* Filter overload items based on self type during type inference (Jukka Lehtosalo, PR [17873](https://github.com/python/mypy/pull/17873))
154228
* Enable negative narrowing of union TypeVar upper bounds (Brian Schubert, PR [17850](https://github.com/python/mypy/pull/17850))
155-
* Fix get_member_expr_fullname returning strings with embedded "None" (Brian Schubert, PR [17848](https://github.com/python/mypy/pull/17848))
229+
* Fix issue with member expression formatting (Brian Schubert, PR [17848](https://github.com/python/mypy/pull/17848))
156230
* Avoid type size explosion when expanding types (Jukka Lehtosalo, PR [17842](https://github.com/python/mypy/pull/17842))
157231
* Fix negative narrowing of tuples in match statement (Brian Schubert, PR [17817](https://github.com/python/mypy/pull/17817))
158232
* Narrow falsey str/bytes/int to literal type (Brian Schubert, PR [17818](https://github.com/python/mypy/pull/17818))
@@ -163,13 +237,12 @@ examples no longer work on Python 3.8, which is the earliest Python version that
163237
* Added error code for overlapping function signatures (Katrina Connors, PR [17597](https://github.com/python/mypy/pull/17597))
164238
* Check for `truthy-bool` in `not ...` unary expressions (sobolevn, PR [17773](https://github.com/python/mypy/pull/17773))
165239
* Add missing lines-covered and lines-valid attributes (Soubhik Kumar Mitra, PR [17738](https://github.com/python/mypy/pull/17738))
166-
* Fix another crash scenario on recursive tuple types (Ivan Levkivskyi, PR [17708](https://github.com/python/mypy/pull/17708))
240+
* Fix another crash scenario with recursive tuple types (Ivan Levkivskyi, PR [17708](https://github.com/python/mypy/pull/17708))
167241
* Resolve TypeVar upper bounds in `functools.partial` (Shantanu, PR [17660](https://github.com/python/mypy/pull/17660))
168242
* Always reset binder when checking deferred nodes (Ivan Levkivskyi, PR [17643](https://github.com/python/mypy/pull/17643))
169243
* Fix crash on a callable attribute with single unpack (Ivan Levkivskyi, PR [17641](https://github.com/python/mypy/pull/17641))
170244
* Fix mismatched signature between checker plugin API and implementation (bzoracler, PR [17343](https://github.com/python/mypy/pull/17343))
171245
* Indexing a type also produces a GenericAlias (Shantanu, PR [17546](https://github.com/python/mypy/pull/17546))
172-
* Experimental: allow inline/anonymous TypedDicts (Ivan Levkivskyi, PR [17457](https://github.com/python/mypy/pull/17457))
173246
* Fix crash on self-type in callable protocol (Ivan Levkivskyi, PR [17499](https://github.com/python/mypy/pull/17499))
174247
* Fix crash on NamedTuple with method and error in function (Ivan Levkivskyi, PR [17498](https://github.com/python/mypy/pull/17498))
175248
* Add `__replace__` for dataclasses in 3.13 (Max Muoto, PR [17469](https://github.com/python/mypy/pull/17469))
@@ -185,7 +258,33 @@ Please see [git log](https://github.com/python/typeshed/commits/main?after=91a58
185258
### Acknowledgements
186259
Thanks to all mypy contributors who contributed to this release:
187260

188-
- TODO
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
189288

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

0 commit comments

Comments
 (0)