Skip to content

Commit 3d05e58

Browse files
committed
Merge branch 'master' into drop-3.9
2 parents 2c253d0 + 81eaa5d commit 3d05e58

File tree

232 files changed

+13264
-990
lines changed

Some content is hidden

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

232 files changed

+13264
-990
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ jobs:
7979
toxenv: py
8080
tox_extra_args: "-n 3 mypyc/test/test_run.py mypyc/test/test_external.py"
8181

82-
- name: mypyc runtime tests with py313-ubuntu
83-
python: '3.13'
82+
- name: mypyc runtime tests with py310-ubuntu
83+
python: '3.10'
8484
os: ubuntu-latest
8585
toxenv: py
8686
tox_extra_args: "-n 3 mypyc/test/test_run.py mypyc/test/test_external.py"

CHANGELOG.md

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,241 @@ Support for this will be dropped in the first half of 2026!
1111

1212
Contributed by Marc Mueller (PR [20156](https://github.com/python/mypy/pull/20156)).
1313

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

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

LICENSE

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,38 @@ FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
227227
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
228228
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
229229
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
230+
231+
= = = = =
232+
233+
Files under lib-rt/base64 are licensed under the following license.
234+
235+
= = = = =
236+
237+
Copyright (c) 2005-2007, Nick Galbreath
238+
Copyright (c) 2015-2018, Wojciech Muła
239+
Copyright (c) 2016-2017, Matthieu Darbois
240+
Copyright (c) 2013-2022, Alfred Klomp
241+
All rights reserved.
242+
243+
Redistribution and use in source and binary forms, with or without
244+
modification, are permitted provided that the following conditions are
245+
met:
246+
247+
- Redistributions of source code must retain the above copyright notice,
248+
this list of conditions and the following disclaimer.
249+
250+
- Redistributions in binary form must reproduce the above copyright
251+
notice, this list of conditions and the following disclaimer in the
252+
documentation and/or other materials provided with the distribution.
253+
254+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
255+
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
256+
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
257+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
258+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
259+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
260+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
261+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
262+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
263+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
264+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

docs/source/command_line.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ format into the specified directory.
11591159
Enabling incomplete/experimental features
11601160
*****************************************
11611161

1162-
.. option:: --enable-incomplete-feature {PreciseTupleTypes, InlineTypedDict}
1162+
.. option:: --enable-incomplete-feature {PreciseTupleTypes,InlineTypedDict,TypeForm}
11631163

11641164
Some features may require several mypy releases to implement, for example
11651165
due to their complexity, potential for backwards incompatibility, or
@@ -1211,8 +1211,11 @@ List of currently incomplete/experimental features:
12111211

12121212
.. code-block:: python
12131213
1214-
def test_values() -> {"int": int, "str": str}:
1215-
return {"int": 42, "str": "test"}
1214+
def test_values() -> {"width": int, "description": str}:
1215+
return {"width": 42, "description": "test"}
1216+
1217+
* ``TypeForm``: this feature enables ``TypeForm``, as described in
1218+
`PEP 747 – Annotating Type Forms <https://peps.python.org/pep-0747/>_`.
12161219

12171220

12181221
Miscellaneous

docs/source/duck_type_compatibility.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ supported for a small set of built-in types:
99
* ``int`` is duck type compatible with ``float`` and ``complex``.
1010
* ``float`` is duck type compatible with ``complex``.
1111
* ``bytearray`` and ``memoryview`` are duck type compatible with ``bytes``.
12+
(this will be disabled by default in **mypy 2.0**, and currently can be
13+
disabled with :option:`--strict-bytes <mypy --strict-bytes>`.)
1214

1315
For example, mypy considers an ``int`` object to be valid whenever a
1416
``float`` object is expected. Thus code like this is nice and clean

0 commit comments

Comments
 (0)