Skip to content

Commit 9d04ab0

Browse files
authored
Merge branch 'master' into bugfix/gh-19839-paramspec-reveal-crash
2 parents 795b962 + 64d953d commit 9d04ab0

File tree

285 files changed

+5932
-2917
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

285 files changed

+5932
-2917
lines changed

.github/workflows/mypy_primer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
persist-credentials: false
4040
- uses: actions/setup-python@v5
4141
with:
42-
python-version: "3.13"
42+
python-version: "3.14"
4343
- name: Install dependencies
4444
run: |
4545
python -m pip install -U pip

.github/workflows/test.yml

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,22 @@ jobs:
3131
include:
3232
# Make sure to run mypyc compiled unit tests for both
3333
# the oldest and newest supported Python versions
34-
- name: Test suite with py39-ubuntu, mypyc-compiled
35-
python: '3.9'
36-
os: ubuntu-24.04-arm
37-
toxenv: py
38-
tox_extra_args: "-n 4"
39-
test_mypyc: true
40-
- name: Test suite with py310-ubuntu
34+
- name: Test suite with py310-ubuntu, mypyc-compiled
4135
python: '3.10'
4236
os: ubuntu-24.04-arm
4337
toxenv: py
4438
tox_extra_args: "-n 4"
39+
test_mypyc: true
4540
- name: Test suite with py311-ubuntu
4641
python: '3.11'
4742
os: ubuntu-24.04-arm
4843
toxenv: py
4944
tox_extra_args: "-n 4"
50-
- name: Test suite with py312-ubuntu, mypyc-compiled
45+
- name: Test suite with py312-ubuntu
5146
python: '3.12'
5247
os: ubuntu-24.04-arm
5348
toxenv: py
5449
tox_extra_args: "-n 4"
55-
test_mypyc: true
5650
- name: Test suite with py313-ubuntu, mypyc-compiled
5751
python: '3.13'
5852
os: ubuntu-24.04-arm
@@ -65,6 +59,12 @@ jobs:
6559
toxenv: py
6660
tox_extra_args: "-n 4"
6761
test_mypyc: true
62+
- name: Test suite with py314t-ubuntu, mypyc-compiled
63+
python: '3.14t'
64+
os: ubuntu-24.04-arm
65+
toxenv: py
66+
tox_extra_args: "-n 4"
67+
test_mypyc: true
6868
- name: Test suite with py314-windows-64
6969
python: '3.14'
7070
os: windows-latest
@@ -101,12 +101,24 @@ jobs:
101101
# tox_extra_args: "-n 4 mypyc/test/test_run.py mypyc/test/test_external.py"
102102
# debug_build: true
103103

104-
- name: Type check our own code (py39-ubuntu)
105-
python: '3.9'
104+
- name: Parallel tests with py314-ubuntu, interpreted
105+
python: '3.14'
106+
os: ubuntu-24.04-arm
107+
toxenv: py
108+
tox_extra_args: "-n 4 --mypy-num-workers=4 mypy/test/testcheck.py"
109+
- name: Parallel tests with py314-ubuntu, mypyc-compiled
110+
python: '3.14'
111+
os: ubuntu-24.04-arm
112+
toxenv: py
113+
tox_extra_args: "-n 4 --mypy-num-workers=4 mypy/test/testcheck.py"
114+
test_mypyc: true
115+
116+
- name: Type check our own code (py310-ubuntu)
117+
python: '3.10'
106118
os: ubuntu-latest
107119
toxenv: type
108-
- name: Type check our own code (py39-windows-64)
109-
python: '3.9'
120+
- name: Type check our own code (py310-windows-64)
121+
python: '3.10'
110122
os: windows-latest
111123
toxenv: type
112124

.github/workflows/test_stubgenc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ jobs:
3232
with:
3333
persist-credentials: false
3434

35-
- name: Setup 🐍 3.9
35+
- name: Setup 🐍 3.10
3636
uses: actions/setup-python@v5
3737
with:
38-
python-version: 3.9
38+
python-version: '3.10'
3939

4040
- name: Test stubgenc
4141
run: misc/test-stubgenc.sh

CHANGELOG.md

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

33
## Next Release
44

5+
### Drop Support for Python 3.9
6+
7+
Mypy no longer supports running with Python 3.9, which has reached end-of-life.
8+
When running mypy with Python 3.10+, it is still possible to type check code
9+
that needs to support Python 3.9 with the `--python-version 3.9` argument.
10+
Support for this will be dropped in the first half of 2026!
11+
12+
Contributed by Marc Mueller (PR [20156](https://github.com/python/mypy/pull/20156)).
13+
14+
### Removed Flag: `--force-uppercase-builtins`
15+
16+
Removed the deprecated `--force-uppercase-builtins` flag. It has been a no-op since mypy 1.17.0.
17+
18+
Contributed by Marc Mueller (PR [20410](https://github.com/python/mypy/pull/20410))
19+
20+
### Removed Flag: `--force-union-syntax`
21+
22+
Mypy only supports Python 3.10+. Removed the `--force-union-syntax` flag as it's no longer necessary.
23+
24+
Contributed by Marc Mueller (PR [20405](https://github.com/python/mypy/pull/20405))
25+
26+
## Mypy 1.19
27+
28+
We’ve just uploaded mypy 1.19.0 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).
29+
Mypy is a static type checker for Python. This release includes new features, performance
30+
improvements and bug fixes. You can install it as follows:
31+
32+
python3 -m pip install -U mypy
33+
34+
You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
35+
36+
### Python 3.9 Support Ending Soon
37+
38+
This is the last mypy feature release that supports Python 3.9, which reached
39+
end of life in October 2025.
40+
41+
### Performance Improvements
42+
- Switch to a more dynamic SCC processing logic (Ivan Levkivskyi, PR [20053](https://github.com/python/mypy/pull/20053))
43+
- Speed up type aliases (Ivan Levkivskyi, PR [19810](https://github.com/python/mypy/pull/19810))
44+
45+
### Fixed‑Format Cache Improvements
46+
47+
Mypy uses a cache by default to speed up incremental runs by reusing partial results
48+
from earlier runs. Mypy 1.18 added a new binary fixed-format cache representation as
49+
an experimental feature. The feature is no longer experimental, and we are planning
50+
to enable it by default in a future mypy release (possibly 1.20), since it's faster
51+
and uses less space than the original, JSON-based cache format. Use
52+
`--fixed-format-cache` to enable the fixed-format cache.
53+
54+
Mypy now has an extra dependency on the `librt` PyPI package, as it's needed for
55+
cache serialization and deserialization.
56+
57+
Mypy ships with a tool to convert fixed-format cache files to the old JSON format.
58+
Example of how to use this:
59+
```
60+
$ python -m mypy.exportjson .mypy_cache/.../my_module.data.ff
61+
```
62+
63+
This way existing use cases that parse JSON cache files can be supported when using
64+
the new format, though an extra conversion step is needed.
65+
66+
This release includes these improvements:
67+
68+
- Force-discard cache if cache format changed (Ivan Levkivskyi, PR [20152](https://github.com/python/mypy/pull/20152))
69+
- Add tool to convert binary cache files to JSON (Jukka Lehtosalo, PR [20071](https://github.com/python/mypy/pull/20071))
70+
- Use more efficient serialization format for long integers in cache files (Jukka Lehtosalo, PR [20151](https://github.com/python/mypy/pull/20151))
71+
- More robust packing of floats in fixed-format cache (Ivan Levkivskyi, PR [20150](https://github.com/python/mypy/pull/20150))
72+
- Use self-descriptive cache with type tags (Ivan Levkivskyi, PR [20137](https://github.com/python/mypy/pull/20137))
73+
- Use fixed format for cache metas (Ivan Levkivskyi, PR [20088](https://github.com/python/mypy/pull/20088))
74+
- Make metas more compact; fix indirect suppression (Ivan Levkivskyi, PR [20075](https://github.com/python/mypy/pull/20075))
75+
- Use dedicated tags for most common cached instances (Ivan Levkivskyi, PR [19762](https://github.com/python/mypy/pull/19762))
76+
77+
### PEP 747: Annotating Type Forms
78+
79+
Mypy now recognizes `TypeForm[T]` as a type and implements
80+
[PEP 747](https://peps.python.org/pep-0747/). The feature is still experimental,
81+
and it's disabled by default. Use `--enable-incomplete-feature=TypeForm` to
82+
enable type forms. A type form object captures the type information provided by a
83+
runtime type expression. Example:
84+
85+
```python
86+
from typing_extensions import TypeForm
87+
88+
def trycast[T](typx: TypeForm[T], value: object) -> T | None: ...
89+
90+
def example(o: object) -> None:
91+
# 'int | str' below is an expression that represents a type.
92+
# Unlike type[T], TypeForm[T] can be used with all kinds of types,
93+
# including union types.
94+
x = trycast(int | str, o)
95+
if x is not None:
96+
# Type of 'x' is 'int | str' here
97+
...
98+
```
99+
100+
This feature was contributed by David Foster (PR [19596](https://github.com/python/mypy/pull/19596)).
101+
102+
### Fixes to Crashes
103+
- Do not push partial types to the binder (Stanislav Terliakov, PR [20202](https://github.com/python/mypy/pull/20202))
104+
- Fix crash on recursive tuple with Hashable (Ivan Levkivskyi, PR [20232](https://github.com/python/mypy/pull/20232))
105+
- Fix crash related to decorated functions (Stanislav Terliakov, PR [20203](https://github.com/python/mypy/pull/20203))
106+
- Do not abort constructing TypeAlias if only type parameters hold us back (Stanislav Terliakov, PR [20162](https://github.com/python/mypy/pull/20162))
107+
- Use the fallback for `ModuleSpec` early if it can never be resolved (Stanislav Terliakov, PR [20167](https://github.com/python/mypy/pull/20167))
108+
- Do not store deferred NamedTuple fields as redefinitions (Stanislav Terliakov, PR [20147](https://github.com/python/mypy/pull/20147))
109+
- Discard partial types remaining after inference failure (Stanislav Terliakov, PR [20126](https://github.com/python/mypy/pull/20126))
110+
- Fix an infinite recursion bug (Stanislav Terliakov, PR [20127](https://github.com/python/mypy/pull/20127))
111+
- Fix IsADirectoryError for namespace packages when using --linecoverage-report (wyattscarpenter, PR [20109](https://github.com/python/mypy/pull/20109))
112+
- Fix an internal error when creating cobertura output for namespace package (wyattscarpenter, PR [20112](https://github.com/python/mypy/pull/20112))
113+
- Allow type parameters reusing the name missing from current module (Stanislav Terliakov, PR [20081](https://github.com/python/mypy/pull/20081))
114+
- Prevent TypeGuardedType leak from narrowing declared type as part of type variable bound (Stanislav Terliakov, PR [20046](https://github.com/python/mypy/pull/20046))
115+
- Fix crash on invalid unpack in base class (Ivan Levkivskyi, PR [19962](https://github.com/python/mypy/pull/19962))
116+
- Traverse ParamSpec prefix where we should (Ivan Levkivskyi, PR [19800](https://github.com/python/mypy/pull/19800))
117+
- Fix daemon crash related to imports (Ivan Levkivskyi, PR [20271](https://github.com/python/mypy/pull/20271))
118+
119+
### Mypyc: Support for `__getattr__`, `__setattr__`, and `__delattr__`
120+
121+
Mypyc now has partial support for `__getattr__`, `__setattr__` and
122+
`__delattr__` methods in native classes.
123+
124+
Note that native attributes are not stored using `__dict__`. Setting attributes
125+
directly while bypassing `__setattr__` is possible by using
126+
`super().__setattr__(...)` or `object.__setattr__(...)`, but not via `__dict__`.
127+
128+
Example:
129+
```python
130+
class Demo:
131+
_data: dict[str, str]
132+
133+
def __init__(self) -> None:
134+
# Initialize data dict without calling our __setattr__
135+
super().__setattr__("_data", {})
136+
137+
def __setattr__(self, name: str, value: str) -> None:
138+
print(f"Setting {name} = {value!r}")
139+
140+
if name == "_data":
141+
raise AttributeError("'_data' cannot be set")
142+
143+
self._data[name] = value
144+
145+
def __getattr__(self, name: str) -> str:
146+
print(f"Getting {name}")
147+
148+
try:
149+
return self._data[name]
150+
except KeyError:
151+
raise AttributeError(name)
152+
153+
d = Demo()
154+
d.x = "hello"
155+
d.y = "world"
156+
157+
print(d.x)
158+
print(d.y)
159+
```
160+
161+
Related PRs:
162+
- Generate `__setattr__` wrapper (Piotr Sawicki, PR [19937](https://github.com/python/mypy/pull/19937))
163+
- Generate `__getattr__` wrapper (Piotr Sawicki, PR [19909](https://github.com/python/mypy/pull/19909))
164+
- Support deleting attributes in `__setattr__` wrapper (Piotr Sawicki, PR [19997](https://github.com/python/mypy/pull/19997))
165+
166+
### Miscellaneous Mypyc Improvements
167+
- Fix `__new__` in native classes with inheritance (Piotr Sawicki, PR [20302](https://github.com/python/mypy/pull/20302))
168+
- Fix crash on `super` in generator (Ivan Levkivskyi, PR [20291](https://github.com/python/mypy/pull/20291))
169+
- Fix calling base class async method using `super()` (Jukka Lehtosalo, PR [20254](https://github.com/python/mypy/pull/20254))
170+
- Fix async or generator methods in traits (Jukka Lehtosalo, PR [20246](https://github.com/python/mypy/pull/20246))
171+
- Optimize equality check with string literals (BobTheBuidler, PR [19883](https://github.com/python/mypy/pull/19883))
172+
- Fix inheritance of async defs (Jukka Lehtosalo, PR [20044](https://github.com/python/mypy/pull/20044))
173+
- Reject invalid `mypyc_attr` args (BobTheBuidler, PR [19963](https://github.com/python/mypy/pull/19963))
174+
- Optimize `isinstance` with tuple of primitive types (BobTheBuidler, PR [19949](https://github.com/python/mypy/pull/19949))
175+
- Optimize away first index check in for loops if length > 1 (BobTheBuidler, PR [19933](https://github.com/python/mypy/pull/19933))
176+
- Fix broken exception/cancellation handling in async def (Jukka Lehtosalo, PR [19951](https://github.com/python/mypy/pull/19951))
177+
- Transform `object.__new__` inside `__new__` (Piotr Sawicki, PR [19866](https://github.com/python/mypy/pull/19866))
178+
- Fix crash with NewType and other non-class types in incremental builds (Jukka Lehtosalo, PR [19837](https://github.com/python/mypy/pull/19837))
179+
- Optimize container creation from expressions with length known at compile time (BobTheBuidler, PR [19503](https://github.com/python/mypy/pull/19503))
180+
- Allow per-class free list to be used with inheritance (Jukka Lehtosalo, PR [19790](https://github.com/python/mypy/pull/19790))
181+
- Fix object finalization (Marc Mueller, PR [19749](https://github.com/python/mypy/pull/19749))
182+
- Allow defining a single-item free "list" for a native class (Jukka Lehtosalo, PR [19785](https://github.com/python/mypy/pull/19785))
183+
- Speed up unary "not" (Jukka Lehtosalo, PR [19774](https://github.com/python/mypy/pull/19774))
184+
185+
### Stubtest Improvements
186+
- Check `_value_` for ellipsis-valued stub enum members (Stanislav Terliakov, PR [19760](https://github.com/python/mypy/pull/19760))
187+
- Include function name in overload assertion messages (Joren Hammudoglu, PR [20063](https://github.com/python/mypy/pull/20063))
188+
- Fix special case in analyzing function signature (iap, PR [19822](https://github.com/python/mypy/pull/19822))
189+
- Improve `allowlist` docs with better example (sobolevn, PR [20007](https://github.com/python/mypy/pull/20007))
190+
191+
### Documentation Updates
192+
- Update duck type compatibility: mention strict-bytes and mypy 2.0 (wyattscarpenter, PR [20121](https://github.com/python/mypy/pull/20121))
193+
- Document `--enable-incomplete-feature TypeForm` (wyattscarpenter, PR [20173](https://github.com/python/mypy/pull/20173))
194+
- Change the inline TypedDict example (wyattscarpenter, PR [20172](https://github.com/python/mypy/pull/20172))
195+
- Replace `List` with built‑in `list` (PEP 585) (Thiago J. Barbalho, PR [20000](https://github.com/python/mypy/pull/20000))
196+
- Improve junit documentation (wyattscarpenter, PR [19867](https://github.com/python/mypy/pull/19867))
197+
198+
### Other Notable Fixes and Improvements
199+
- Fix annotated with function as type keyword list parameter (KarelKenens, PR [20094](https://github.com/python/mypy/pull/20094))
200+
- Fix errors for raise NotImplemented (Shantanu, PR [20168](https://github.com/python/mypy/pull/20168))
201+
- Don't let help formatter line-wrap URLs (Frank Dana, PR [19825](https://github.com/python/mypy/pull/19825))
202+
- Do not cache fast container types inside lambdas (Stanislav Terliakov, PR [20166](https://github.com/python/mypy/pull/20166))
203+
- Respect force-union-syntax flag in error hint (Marc Mueller, PR [20165](https://github.com/python/mypy/pull/20165))
204+
- Fix type checking of dict type aliases (Shantanu, PR [20170](https://github.com/python/mypy/pull/20170))
205+
- Use pretty callable formatting more often for callable expressions (Theodore Ando, PR [20128](https://github.com/python/mypy/pull/20128))
206+
- Use dummy concrete type instead of `Any` when checking protocol variance (bzoracler, PR [20110](https://github.com/python/mypy/pull/20110))
207+
- PEP 696: Fix swapping TypeVars with defaults (Randolf Scholz, PR [19449](https://github.com/python/mypy/pull/19449))
208+
- Fix narrowing of class pattern with union type (Randolf Scholz, PR [19517](https://github.com/python/mypy/pull/19517))
209+
- Do not emit unreachable warnings for lines that return `NotImplemented` (Christoph Tyralla, PR [20083](https://github.com/python/mypy/pull/20083))
210+
- Fix matching against `typing.Callable` and `Protocol` types (Randolf Scholz, PR [19471](https://github.com/python/mypy/pull/19471))
211+
- Make `--pretty` work better on multi-line issues (A5rocks, PR [20056](https://github.com/python/mypy/pull/20056))
212+
- More precise return types for `TypedDict.get` (Randolf Scholz, PR [19897](https://github.com/python/mypy/pull/19897))
213+
- 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))
214+
- Check class references to catch non-existent classes in match cases (A5rocks, PR [20042](https://github.com/python/mypy/pull/20042))
215+
- Do not sort unused error codes in unused error codes warning (wyattscarpenter, PR [20036](https://github.com/python/mypy/pull/20036))
216+
- Fix `[name-defined]` false positive in `class A[X, Y=X]:` case (sobolevn, PR [20021](https://github.com/python/mypy/pull/20021))
217+
- Filter SyntaxWarnings during AST parsing (Marc Mueller, PR [20023](https://github.com/python/mypy/pull/20023))
218+
- Make untyped decorator its own error code (wyattscarpenter, PR [19911](https://github.com/python/mypy/pull/19911))
219+
- Support error codes from plugins in options (Sigve Sebastian Farstad, PR [19719](https://github.com/python/mypy/pull/19719))
220+
- Allow returning Literals in `__new__` (James Hilton-Balfe, PR [15687](https://github.com/python/mypy/pull/15687))
221+
- Inverse interface freshness logic (Ivan Levkivskyi, PR [19809](https://github.com/python/mypy/pull/19809))
222+
- Do not report exhaustive-match after deferral (Stanislav Terliakov, PR [19804](https://github.com/python/mypy/pull/19804))
223+
- Make `untyped_calls_exclude` invalidate cache (Ivan Levkivskyi, PR [19801](https://github.com/python/mypy/pull/19801))
224+
- Add await to empty context hack (Stanislav Terliakov, PR [19777](https://github.com/python/mypy/pull/19777))
225+
- Consider non-empty enums assignable to Self (Stanislav Terliakov, PR [19779](https://github.com/python/mypy/pull/19779))
226+
227+
### Typeshed updates
228+
229+
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.
230+
231+
### Acknowledgements
232+
233+
Thanks to all mypy contributors who contributed to this release:
234+
- A5rocks
235+
- BobTheBuidler
236+
- bzoracler
237+
- Chainfire
238+
- Christoph Tyralla
239+
- David Foster
240+
- Frank Dana
241+
- Guo Ci
242+
- iap
243+
- Ivan Levkivskyi
244+
- James Hilton-Balfe
245+
- jhance
246+
- Joren Hammudoglu
247+
- Jukka Lehtosalo
248+
- KarelKenens
249+
- Kevin Kannammalil
250+
- Marc Mueller
251+
- Michael Carlstrom
252+
- Michael J. Sullivan
253+
- Piotr Sawicki
254+
- Randolf Scholz
255+
- Shantanu
256+
- Sigve Sebastian Farstad
257+
- sobolevn
258+
- Stanislav Terliakov
259+
- Stephen Morton
260+
- Theodore Ando
261+
- Thiago J. Barbalho
262+
- wyattscarpenter
263+
264+
I’d also like to thank my employer, Dropbox, for supporting mypy development.
265+
5266
## Mypy 1.18.1
6267

7268
We’ve just uploaded mypy 1.18.1 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ hash -r # This resets shell PATH cache, not necessary on Windows
5151
```
5252

5353
> **Note**
54-
> You'll need Python 3.9 or higher to install all requirements listed in
54+
> You'll need Python 3.10 or higher to install all requirements listed in
5555
> test-requirements.txt
5656
5757
### Running tests

docs/source/additional_features.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Type annotations can be added as follows:
135135

136136
.. code-block:: python
137137
138-
import attr
138+
import attrs
139139
140140
@attrs.define
141141
class A:

docs/source/command_line.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -958,12 +958,6 @@ in error messages.
958958
useful or they may be overly noisy. If ``N`` is negative, there is
959959
no limit. The default limit is -1.
960960

961-
.. option:: --force-union-syntax
962-
963-
Always use ``Union[]`` and ``Optional[]`` for union types
964-
in error messages (instead of the ``|`` operator),
965-
even on Python 3.10+.
966-
967961

968962
.. _incremental:
969963

0 commit comments

Comments
 (0)