Skip to content

Commit 0247068

Browse files
Merge branch 'master' into weak-proxy
2 parents 8b1f64b + c66417d commit 0247068

File tree

6 files changed

+207
-34
lines changed

6 files changed

+207
-34
lines changed

CHANGELOG.md

Lines changed: 177 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,70 @@
22

33
## Next Release
44

5-
### Remove Support for targeting Python 3.8
5+
## Mypy 1.17
66

7-
Mypy now requires `--python-version 3.9` or greater. Support for only Python 3.8 is
8-
fully removed now. Given an unsupported version, mypy will default to the oldest
9-
supported one, currently 3.9.
7+
We’ve just uploaded mypy 1.17 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 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+
### Optionally Check That Match Is Exhaustive
16+
17+
Mypy can now optionally generate an error if a match statement does not
18+
match exhaustively, without having to use `assert_never(...)`. Enable
19+
this by using `--enable-error-code exhaustive-match`.
20+
21+
Example:
22+
23+
```python
24+
# mypy: enable-error-code=exhaustive-match
25+
26+
import enum
27+
28+
class Color(enum.Enum):
29+
RED = 1
30+
BLUE = 2
31+
32+
def show_color(val: Color) -> None:
33+
# error: Unhandled case for values of type "Literal[Color.BLUE]"
34+
match val:
35+
case Color.RED:
36+
print("red")
37+
```
38+
39+
This feature was contributed by Donal Burns (PR [19144](https://github.com/python/mypy/pull/19144)).
40+
41+
### Further Improvements to Attribute Resolution
42+
43+
This release includes additional improvements to how attribute types
44+
and kinds are resolved. These fix many bugs and overall improve consistency.
45+
46+
* Handle corner case: protocol/class variable/descriptor (Ivan Levkivskyi, PR [19277](https://github.com/python/mypy/pull/19277))
47+
* Fix a few inconsistencies in protocol/type object interactions (Ivan Levkivskyi, PR [19267](https://github.com/python/mypy/pull/19267))
48+
* Refactor/unify access to static attributes (Ivan Levkivskyi, PR [19254](https://github.com/python/mypy/pull/19254))
49+
* Remove inconsistencies in operator handling (Ivan Levkivskyi, PR [19250](https://github.com/python/mypy/pull/19250))
50+
* Make protocol subtyping more consistent (Ivan Levkivskyi, PR [18943](https://github.com/python/mypy/pull/18943))
51+
52+
### Fixes to Nondeterministic Type Checking
53+
54+
Previous mypy versions could infer different types for certain expressions
55+
across different runs (typically depending on which order certain types
56+
were processed, and this order was nondeterministic). This release includes
57+
fixes to several such issues.
58+
59+
* Fix nondeterministic type checking by making join with explicit Protocol and type promotion commute (Shantanu, PR [18402](https://github.com/python/mypy/pull/18402))
60+
* Fix nondeterministic type checking caused by nonassociative of None joins (Shantanu, PR [19158](https://github.com/python/mypy/pull/19158))
61+
* Fix nondeterministic type checking caused by nonassociativity of joins (Shantanu, PR [19147](https://github.com/python/mypy/pull/19147))
62+
* Fix nondeterministic type checking by making join between `type` and TypeVar commute (Shantanu, PR [19149](https://github.com/python/mypy/pull/19149))
63+
64+
### Remove Support for Targeting Python 3.8
65+
66+
Mypy now requires `--python-version 3.9` or greater. Support for targeting Python 3.8 is
67+
fully removed now. Since 3.8 is an unsupported version, mypy will default to the oldest
68+
supported version (currently 3.9) if you still try to target 3.8.
1069

1170
This change is necessary because typeshed stopped supporting Python 3.8 after it
1271
reached its End of Life in October 2024.
@@ -17,18 +76,128 @@ Contributed by Marc Mueller
1776
### Initial Support for Python 3.14
1877

1978
Mypy is now tested on 3.14 and mypyc works with 3.14.0b3 and later.
20-
Mypyc compiled wheels of mypy itself will be available for new versions after 3.14.0rc1 is released.
79+
Binary wheels compiled with mypyc for mypy itself will be available for 3.14
80+
some time after 3.14.0rc1 has been released.
2181

22-
Note that not all new features might be supported just yet.
82+
Note that not all features are supported just yet.
2383

2484
Contributed by Marc Mueller (PR [19164](https://github.com/python/mypy/pull/19164))
2585

26-
### Deprecated Flag: \--force-uppercase-builtins
86+
### Deprecated Flag: `--force-uppercase-builtins`
2787

28-
Mypy only supports Python 3.9+. The \--force-uppercase-builtins flag is now deprecated and a no-op. It will be removed in a future version.
88+
Mypy only supports Python 3.9+. The `--force-uppercase-builtins` flag is now
89+
deprecated as unnecessary, and a no-op. It will be removed in a future version.
2990

3091
Contributed by Marc Mueller (PR [19176](https://github.com/python/mypy/pull/19176))
3192

93+
### Mypyc: Improvements to Generators and Async Functions
94+
95+
This release includes both performance improvements and bug fixes related
96+
to generators and async functions (these share many implementation details).
97+
98+
* Fix exception swallowing in async try/finally blocks with await (Chainfire, PR [19353](https://github.com/python/mypy/pull/19353))
99+
* Fix AttributeError in async try/finally with mixed return paths (Chainfire, PR [19361](https://github.com/python/mypy/pull/19361))
100+
* Make generated generator helper method internal (Jukka Lehtosalo, PR [19268](https://github.com/python/mypy/pull/19268))
101+
* Free coroutine after await encounters StopIteration (Jukka Lehtosalo, PR [19231](https://github.com/python/mypy/pull/19231))
102+
* Use non-tagged integer for generator label (Jukka Lehtosalo, PR [19218](https://github.com/python/mypy/pull/19218))
103+
* Merge generator and environment classes in simple cases (Jukka Lehtosalo, PR [19207](https://github.com/python/mypy/pull/19207))
104+
105+
### Mypyc: Partial, Unsafe Support for Free Threading
106+
107+
Mypyc has minimal, quite memory-unsafe support for the free threaded
108+
builds of 3.14. It is also only lightly tested. Bug reports and experience
109+
reports are welcome!
110+
111+
Here are some of the major limitations:
112+
* Free threading only works when compiling a single module at a time.
113+
* If there is concurrent access to an object while another thread is mutating the same
114+
object, it's possible to encounter segfaults and memory corruption.
115+
* There are no efficient native primitives for thread synthronization, though the
116+
regular `threading` module can be used.
117+
* Some workloads don't scale well to multiple threads for no clear reason.
118+
119+
Related PRs:
120+
121+
* Enable partial, unsafe support for free-threading (Jukka Lehtosalo, PR [19167](https://github.com/python/mypy/pull/19167))
122+
* Fix incref/decref on free-threaded builds (Jukka Lehtosalo, PR [19127](https://github.com/python/mypy/pull/19127))
123+
124+
### Other Mypyc Fixes and Improvements
125+
126+
* Derive .c file name from full module name if using multi_file (Jukka Lehtosalo, PR [19278](https://github.com/python/mypy/pull/19278))
127+
* Support overriding the group name used in output files (Jukka Lehtosalo, PR [19272](https://github.com/python/mypy/pull/19272))
128+
* Add note about using non-native class to subclass built-in types (Jukka Lehtosalo, PR [19236](https://github.com/python/mypy/pull/19236))
129+
* Make some generated classes implicitly final (Jukka Lehtosalo, PR [19235](https://github.com/python/mypy/pull/19235))
130+
* Don't simplify module prefixes if using separate compilation (Jukka Lehtosalo, PR [19206](https://github.com/python/mypy/pull/19206))
131+
132+
### Stubgen Improvements
133+
134+
* Add import for `types` in `__exit__` method signature (Alexey Makridenko, PR [19120](https://github.com/python/mypy/pull/19120))
135+
* Add support for including class and property docstrings (Chad Dombrova, PR [17964](https://github.com/python/mypy/pull/17964))
136+
* Don't generate `Incomplete | None = None` argument annotation (Sebastian Rittau, PR [19097](https://github.com/python/mypy/pull/19097))
137+
* Support several more constructs in stubgen's alias printer (Stanislav Terliakov, PR [18888](https://github.com/python/mypy/pull/18888))
138+
139+
### Miscellaneous Fixes and Improvements
140+
141+
* Combine the revealed types of multiple iteration steps in a more robust manner (Christoph Tyralla, PR [19324](https://github.com/python/mypy/pull/19324))
142+
* Improve the handling of "iteration dependent" errors and notes in finally clauses (Christoph Tyralla, PR [19270](https://github.com/python/mypy/pull/19270))
143+
* Lessen dmypy suggest path limitations for Windows machines (CoolCat467, PR [19337](https://github.com/python/mypy/pull/19337))
144+
* Fix type ignore comments erroneously marked as unused by dmypy (Charlie Denton, PR [15043](https://github.com/python/mypy/pull/15043))
145+
* Fix misspelled `exhaustive-match` error code (johnthagen, PR [19276](https://github.com/python/mypy/pull/19276))
146+
* Fix missing error context for unpacking assignment involving star expression (Brian Schubert, PR [19258](https://github.com/python/mypy/pull/19258))
147+
* Fix and simplify error de-duplication (Ivan Levkivskyi, PR [19247](https://github.com/python/mypy/pull/19247))
148+
* Disallow `ClassVar` in type aliases (Brian Schubert, PR [19263](https://github.com/python/mypy/pull/19263))
149+
* Add script that prints list of compiled files when compiling mypy (Jukka Lehtosalo, PR [19260](https://github.com/python/mypy/pull/19260))
150+
* Fix help message url for "None and Optional handling" section (Guy Wilson, PR [19252](https://github.com/python/mypy/pull/19252))
151+
* Display fully qualified name of imported base classes in errors about incompatible overrides (Mikhail Golubev, PR [19115](https://github.com/python/mypy/pull/19115))
152+
* 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))
153+
* Fix type extraction from `isinstance` checks (Stanislav Terliakov, PR [19223](https://github.com/python/mypy/pull/19223))
154+
* Erase stray type variables in `functools.partial` (Stanislav Terliakov, PR [18954](https://github.com/python/mypy/pull/18954))
155+
* Make inferring condition value recognize the whole truth table (Stanislav Terliakov, PR [18944](https://github.com/python/mypy/pull/18944))
156+
* Support type aliases, `NamedTuple` and `TypedDict` in constrained TypeVar defaults (Stanislav Terliakov, PR [18884](https://github.com/python/mypy/pull/18884))
157+
* Move dataclass `kw_only` fields to the end of the signature (Stanislav Terliakov, PR [19018](https://github.com/python/mypy/pull/19018))
158+
* Provide a better fallback value for the `python_version` option (Marc Mueller, PR [19162](https://github.com/python/mypy/pull/19162))
159+
* Avoid spurious non-overlapping equality error with metaclass with `__eq__` (Michael J. Sullivan, PR [19220](https://github.com/python/mypy/pull/19220))
160+
* Narrow type variable bounds (Ivan Levkivskyi, PR [19183](https://github.com/python/mypy/pull/19183))
161+
* Add classifier for Python 3.14 (Marc Mueller, PR [19199](https://github.com/python/mypy/pull/19199))
162+
* Capitalize syntax error messages (Charulata, PR [19114](https://github.com/python/mypy/pull/19114))
163+
* Infer constraints eagerly if actual is Any (Ivan Levkivskyi, PR [19190](https://github.com/python/mypy/pull/19190))
164+
* Include walrus assignments in conditional inference (Stanislav Terliakov, PR [19038](https://github.com/python/mypy/pull/19038))
165+
* Use PEP 604 syntax when converting types to strings (Marc Mueller, PR [19179](https://github.com/python/mypy/pull/19179))
166+
* Use more lower-case builtin types in error messages (Marc Mueller, PR [19177](https://github.com/python/mypy/pull/19177))
167+
* Fix example to use correct method of Stack (Łukasz Kwieciński, PR [19123](https://github.com/python/mypy/pull/19123))
168+
* Forbid `.pop` of `Readonly` `NotRequired` TypedDict items (Stanislav Terliakov, PR [19133](https://github.com/python/mypy/pull/19133))
169+
* Emit a friendlier warning on invalid exclude regex, instead of a stacktrace (wyattscarpenter, PR [19102](https://github.com/python/mypy/pull/19102))
170+
* Enable ANSI color codes for dmypy client in Windows (wyattscarpenter, PR [19088](https://github.com/python/mypy/pull/19088))
171+
* 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))
172+
173+
### Acknowledgements
174+
175+
Thanks to all mypy contributors who contributed to this release:
176+
177+
* Alexey Makridenko
178+
* Brian Schubert
179+
* Chad Dombrova
180+
* Chainfire
181+
* Charlie Denton
182+
* Charulata
183+
* Christoph Tyralla
184+
* CoolCat467
185+
* Donal Burns
186+
* Guy Wilson
187+
* Ivan Levkivskyi
188+
* johnthagen
189+
* Jukka Lehtosalo
190+
* Łukasz Kwieciński
191+
* Marc Mueller
192+
* Michael J. Sullivan
193+
* Mikhail Golubev
194+
* Sebastian Rittau
195+
* Shantanu
196+
* Stanislav Terliakov
197+
* wyattscarpenter
198+
199+
I’d also like to thank my employer, Dropbox, for supporting mypy development.
200+
32201
## Mypy 1.16
33202

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

mypyc/irbuild/for_helpers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
from mypyc.primitives.misc_ops import stop_async_iteration_op
7777
from mypyc.primitives.registry import CFunctionDescription
7878
from mypyc.primitives.set_ops import set_add_op
79+
from mypyc.primitives.str_ops import str_get_item_unsafe_op
7980
from mypyc.primitives.tuple_ops import tuple_get_item_unsafe_op
8081

8182
GenFunc = Callable[[], None]
@@ -772,6 +773,8 @@ def unsafe_index(builder: IRBuilder, target: Value, index: Value, line: int) ->
772773
return builder.primitive_op(list_get_item_unsafe_op, [target, index], line)
773774
elif is_tuple_rprimitive(target.type):
774775
return builder.call_c(tuple_get_item_unsafe_op, [target, index], line)
776+
elif is_str_rprimitive(target.type):
777+
return builder.call_c(str_get_item_unsafe_op, [target, index], line)
775778
else:
776779
return builder.gen_method_call(target, "__getitem__", [index], None, line)
777780

mypyc/lib-rt/CPy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ static inline char CPyDict_CheckSize(PyObject *dict, Py_ssize_t size) {
727727
char CPyStr_Equal(PyObject *str1, PyObject *str2);
728728
PyObject *CPyStr_Build(Py_ssize_t len, ...);
729729
PyObject *CPyStr_GetItem(PyObject *str, CPyTagged index);
730+
PyObject *CPyStr_GetItemUnsafe(PyObject *str, Py_ssize_t index);
730731
CPyTagged CPyStr_Find(PyObject *str, PyObject *substr, CPyTagged start, int direction);
731732
CPyTagged CPyStr_FindWithEnd(PyObject *str, PyObject *substr, CPyTagged start, CPyTagged end, int direction);
732733
PyObject *CPyStr_Split(PyObject *str, PyObject *sep, CPyTagged max_split);

mypyc/lib-rt/str_ops.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ PyObject *CPyStr_GetItem(PyObject *str, CPyTagged index) {
117117
}
118118
}
119119

120+
PyObject *CPyStr_GetItemUnsafe(PyObject *str, Py_ssize_t index) {
121+
// This is unsafe since we don't check for overflow when doing <<.
122+
return CPyStr_GetItem(str, index << 1);
123+
}
124+
120125
// A simplification of _PyUnicode_JoinArray() from CPython 3.9.6
121126
PyObject *CPyStr_Build(Py_ssize_t len, ...) {
122127
Py_ssize_t i;

mypyc/primitives/str_ops.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@
9595
error_kind=ERR_MAGIC,
9696
)
9797

98+
# This is unsafe since it assumes that the index is within reasonable bounds.
99+
# In the future this might do no bounds checking at all.
100+
str_get_item_unsafe_op = custom_op(
101+
arg_types=[str_rprimitive, c_pyssize_t_rprimitive],
102+
return_type=str_rprimitive,
103+
c_function_name="CPyStr_GetItemUnsafe",
104+
error_kind=ERR_MAGIC,
105+
)
106+
98107
# str[begin:end]
99108
str_slice_op = custom_op(
100109
arg_types=[str_rprimitive, int_rprimitive, int_rprimitive],

mypyc/test-data/irbuild-tuple.test

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ L4:
272272
a = r6
273273
return 1
274274

275-
[case testTupleBuiltFromStr_64bit]
275+
[case testTupleBuiltFromStr]
276276
def f2(val: str) -> str:
277277
return val + "f2"
278278

@@ -292,10 +292,9 @@ def test():
292292
r2 :: bit
293293
r3 :: tuple
294294
r4, r5 :: native_int
295-
r6, r7, r8, r9 :: bit
296-
r10, r11, r12 :: int
297-
r13, x, r14 :: str
298-
r15 :: native_int
295+
r6, r7 :: bit
296+
r8, x, r9 :: str
297+
r10 :: native_int
299298
a :: tuple
300299
L0:
301300
r0 = 'abc'
@@ -308,30 +307,17 @@ L1:
308307
r5 = CPyStr_Size_size_t(source)
309308
r6 = r5 >= 0 :: signed
310309
r7 = r4 < r5 :: signed
311-
if r7 goto L2 else goto L8 :: bool
310+
if r7 goto L2 else goto L4 :: bool
312311
L2:
313-
r8 = r4 <= 4611686018427387903 :: signed
314-
if r8 goto L3 else goto L4 :: bool
312+
r8 = CPyStr_GetItemUnsafe(source, r4)
313+
x = r8
314+
r9 = f2(x)
315+
CPySequenceTuple_SetItemUnsafe(r3, r4, r9)
315316
L3:
316-
r9 = r4 >= -4611686018427387904 :: signed
317-
if r9 goto L5 else goto L4 :: bool
318-
L4:
319-
r10 = CPyTagged_FromInt64(r4)
320-
r11 = r10
321-
goto L6
322-
L5:
323-
r12 = r4 << 1
324-
r11 = r12
325-
L6:
326-
r13 = CPyStr_GetItem(source, r11)
327-
x = r13
328-
r14 = f2(x)
329-
CPySequenceTuple_SetItemUnsafe(r3, r4, r14)
330-
L7:
331-
r15 = r4 + 1
332-
r4 = r15
317+
r10 = r4 + 1
318+
r4 = r10
333319
goto L1
334-
L8:
320+
L4:
335321
a = r3
336322
return 1
337323

0 commit comments

Comments
 (0)