Skip to content

Commit 2fa302b

Browse files
committed
Merge branch 'master' into feature/name_mangling
# Conflicts: # mypy/nodes.py # test-data/unit/check-classes.test
2 parents 44a9e32 + 52c7735 commit 2fa302b

File tree

215 files changed

+3289
-1580
lines changed

Some content is hidden

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

215 files changed

+3289
-1580
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
# the oldest and newest supported Python versions
3434
- name: Test suite with py39-ubuntu, mypyc-compiled
3535
python: '3.9'
36-
os: ubuntu-24.04-arm
36+
os: ubuntu-22.04-arm
3737
toxenv: py
3838
tox_extra_args: "-n 4"
3939
test_mypyc: true
@@ -44,31 +44,31 @@ jobs:
4444
tox_extra_args: "-n 4"
4545
- name: Test suite with py310-ubuntu
4646
python: '3.10'
47-
os: ubuntu-24.04-arm
47+
os: ubuntu-22.04-arm
4848
toxenv: py
4949
tox_extra_args: "-n 4"
5050
- name: Test suite with py311-ubuntu, mypyc-compiled
5151
python: '3.11'
52-
os: ubuntu-24.04-arm
52+
os: ubuntu-22.04-arm
5353
toxenv: py
5454
tox_extra_args: "-n 4"
5555
test_mypyc: true
5656
- name: Test suite with py312-ubuntu, mypyc-compiled
5757
python: '3.12'
58-
os: ubuntu-24.04-arm
58+
os: ubuntu-22.04-arm
5959
toxenv: py
6060
tox_extra_args: "-n 4"
6161
test_mypyc: true
6262
- name: Test suite with py313-ubuntu, mypyc-compiled
6363
python: '3.13'
64-
os: ubuntu-24.04-arm
64+
os: ubuntu-22.04-arm
6565
toxenv: py
6666
tox_extra_args: "-n 4"
6767
test_mypyc: true
6868

6969
# - name: Test suite with py314-dev-ubuntu
7070
# python: '3.14-dev'
71-
# os: ubuntu-24.04-arm
71+
# os: ubuntu-22.04-arm
7272
# toxenv: py
7373
# tox_extra_args: "-n 4"
7474
# allow_failure: true

.pre-commit-config.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ repos:
2121
- id: check-github-workflows
2222
- id: check-github-actions
2323
- id: check-readthedocs
24+
- repo: https://github.com/codespell-project/codespell
25+
rev: v2.4.1
26+
hooks:
27+
- id: codespell
28+
args:
29+
- --ignore-words-list=HAX,ccompiler,ot,statics,whet,zar
30+
exclude: ^(mypy/test/|mypy/typeshed/|mypyc/test-data/|test-data/).+$
2431
- repo: https://github.com/rhysd/actionlint
2532
rev: v1.7.7
2633
hooks:
@@ -39,6 +46,14 @@ repos:
3946
rev: v1.0.1
4047
hooks:
4148
- id: zizmor
49+
- repo: local
50+
hooks:
51+
- id: bad-pr-link
52+
name: Bad PR link
53+
description: Detect PR links text that don't match their URL
54+
language: pygrep
55+
entry: '\[(\d+)\]\(https://github.com/python/mypy/pull/(?!\1/?\))\d+/?\)'
56+
files: CHANGELOG.md
4257
# Should be the last one:
4358
- repo: meta
4459
hooks:

CHANGELOG.md

Lines changed: 182 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,119 @@
11
# Mypy Release Notes
22

3-
## Next release
3+
## Next Release
44

5-
### Performance improvements
5+
### Different Property Getter and Setter Types
66

7-
Mypy may be 5-30% faster. This improvement comes largely from tuning the performance of the
8-
garbage collector.
7+
Mypy now supports using different types for property getter and setter.
8+
```python
9+
class A:
10+
value: int
11+
12+
@property
13+
def f(self) -> int:
14+
return self.value
15+
@f.setter
16+
def f(self, x: str | int) -> None:
17+
try:
18+
self.value = int(x)
19+
except ValueError:
20+
raise Exception(f"'{x}' is not a valid value for 'f'")
21+
```
22+
23+
Contributed by Ivan Levkivskyi (PR [18510](https://github.com/python/mypy/pull/18510))
24+
25+
### Selectively Disable Deprecated Warnings
26+
27+
It's now possible to selectively disable warnings generated from
28+
[`warnings.deprecated`](https://docs.python.org/3/library/warnings.html#warnings.deprecated)
29+
using the [`--deprecated-calls-exclude`](https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-deprecated-calls-exclude)
30+
option.
31+
32+
```python
33+
# mypy --enable-error-code deprecated
34+
# --deprecated-calls-exclude=foo.A
35+
import foo
36+
37+
foo.A().func() # OK, the deprecated warning is ignored
38+
39+
# file foo.py
40+
from typing_extensions import deprecated
41+
class A:
42+
@deprecated("Use A.func2 instead")
43+
def func(self): pass
44+
```
45+
46+
Contributed by Marc Mueller (PR [18641](https://github.com/python/mypy/pull/18641))
47+
48+
## Mypy 1.15
49+
50+
We’ve just uploaded mypy 1.15 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).
51+
Mypy is a static type checker for Python. This release includes new features, performance
52+
improvements and bug fixes. You can install it as follows:
53+
54+
python3 -m pip install -U mypy
955

10-
Contributed by Jukka Lehtosalo (PR [18306](https://github.com/python/mypy/pull/18306)).
56+
You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
57+
58+
### Performance Improvements
59+
60+
Mypy is up to 40% faster in some use cases. This improvement comes largely from tuning the performance
61+
of the garbage collector. Additionally, the release includes several micro-optimizations that may
62+
be impactful for large projects.
1163

12-
### Mypyc accelerated mypy wheels for aarch64
64+
Contributed by Jukka Lehtosalo
65+
- PR [18306](https://github.com/python/mypy/pull/18306)
66+
- PR [18302](https://github.com/python/mypy/pull/18302)
67+
- PR [18298](https://github.com/python/mypy/pull/18298)
68+
- PR [18299](https://github.com/python/mypy/pull/18299)
1369

14-
Mypy can compile itself to C extension modules using mypyc. This makes mypy 3-5x faster
15-
than if mypy is interpreted with pure Python. We now build and upload mypyc accelerated
16-
mypy wheels for `manylinux_aarch64` to PyPI, making it easy for users on such platforms
17-
to realise this speedup.
70+
### Mypyc Accelerated Mypy Wheels for ARM Linux
71+
72+
For best performance, mypy can be compiled to C extension modules using mypyc. This makes
73+
mypy 3-5x faster than when interpreted with pure Python. We now build and upload mypyc
74+
accelerated mypy wheels for `manylinux_aarch64` to PyPI, making it easy for Linux users on
75+
ARM platforms to realise this speedup -- just `pip install` the latest mypy.
1876

1977
Contributed by Christian Bundy and Marc Mueller
2078
(PR [mypy_mypyc-wheels#76](https://github.com/mypyc/mypy_mypyc-wheels/pull/76),
2179
PR [mypy_mypyc-wheels#89](https://github.com/mypyc/mypy_mypyc-wheels/pull/89)).
2280

2381
### `--strict-bytes`
2482

25-
By default, mypy treats an annotation of ``bytes`` as permitting ``bytearray`` and ``memoryview``.
26-
[PEP 688](https://peps.python.org/pep-0688) specified the removal of this special case.
27-
Use this flag to disable this behavior. `--strict-bytes` will be enabled by default in **mypy 2.0**.
83+
By default, mypy treats `bytearray` and `memoryview` values as assignable to the `bytes`
84+
type, for historical reasons. Use the `--strict-bytes` flag to disable this
85+
behavior. [PEP 688](https://peps.python.org/pep-0688) specified the removal of this
86+
special case. The flag will be enabled by default in **mypy 2.0**.
2887

29-
Contributed by Ali Hamdan (PR [18137](https://github.com/python/mypy/pull/18263/)) and
88+
Contributed by Ali Hamdan (PR [18263](https://github.com/python/mypy/pull/18263)) and
3089
Shantanu Jain (PR [13952](https://github.com/python/mypy/pull/13952)).
3190

32-
### Improvements to reachability analysis and partial type handling in loops
91+
### Improvements to Reachability Analysis and Partial Type Handling in Loops
3392

34-
This change results in mypy better modelling control flow within loops and hence detecting several
35-
issues it previously did not detect. In some cases, this change may require use of an additional
36-
explicit annotation of a variable.
93+
This change results in mypy better modelling control flow within loops and hence detecting
94+
several previously ignored issues. In some cases, this change may require additional
95+
explicit variable annotations.
3796

3897
Contributed by Christoph Tyralla (PR [18180](https://github.com/python/mypy/pull/18180),
39-
[PR](https://github.com/python/mypy/pull/18433)).
98+
PR [18433](https://github.com/python/mypy/pull/18433)).
4099

41-
(Speaking of partial types, another reminder that mypy plans on enabling `--local-partial-types`
42-
by default in **mypy 2.0**).
100+
(Speaking of partial types, remember that we plan to enable `--local-partial-types`
101+
by default in **mypy 2.0**.)
43102

44-
### Better discovery of configuration files
103+
### Better Discovery of Configuration Files
45104

46105
Mypy will now walk up the filesystem (up until a repository or file system root) to discover
47106
configuration files. See the
48107
[mypy configuration file documentation](https://mypy.readthedocs.io/en/stable/config_file.html)
49108
for more details.
50109

51110
Contributed by Mikhail Shiryaev and Shantanu Jain
52-
(PR [16965](https://github.com/python/mypy/pull/16965), PR [18482](https://github.com/python/mypy/pull/18482)
111+
(PR [16965](https://github.com/python/mypy/pull/16965), PR [18482](https://github.com/python/mypy/pull/18482))
53112

54-
### Better line numbers for decorators and slice expressions
113+
### Better Line Numbers for Decorators and Slice Expressions
55114

56-
Mypy now uses more correct line numbers for decorators and slice expressions. In some cases, this
57-
may necessitate changing the location of a `# type: ignore` comment.
115+
Mypy now uses more correct line numbers for decorators and slice expressions. In some cases,
116+
you may have to change the location of a `# type: ignore` comment.
58117

59118
Contributed by Shantanu Jain (PR [18392](https://github.com/python/mypy/pull/18392),
60119
PR [18397](https://github.com/python/mypy/pull/18397)).
@@ -68,6 +127,103 @@ Support for this will be dropped in the first half of 2025!
68127

69128
Contributed by Marc Mueller (PR [17492](https://github.com/python/mypy/pull/17492)).
70129

130+
### Mypyc Improvements
131+
132+
* Fix `__init__` for classes with `@attr.s(slots=True)` (Advait Dixit, PR [18447](https://github.com/python/mypy/pull/18447))
133+
* Report error for nested class instead of crashing (Valentin Stanciu, PR [18460](https://github.com/python/mypy/pull/18460))
134+
* Fix `InitVar` for dataclasses (Advait Dixit, PR [18319](https://github.com/python/mypy/pull/18319))
135+
* Remove unnecessary mypyc files from wheels (Marc Mueller, PR [18416](https://github.com/python/mypy/pull/18416))
136+
* Fix issues with relative imports (Advait Dixit, PR [18286](https://github.com/python/mypy/pull/18286))
137+
* Add faster primitive for some list get item operations (Jukka Lehtosalo, PR [18136](https://github.com/python/mypy/pull/18136))
138+
* Fix iteration over `NamedTuple` objects (Advait Dixit, PR [18254](https://github.com/python/mypy/pull/18254))
139+
* Mark mypyc package with `py.typed` (bzoracler, PR [18253](https://github.com/python/mypy/pull/18253))
140+
* Fix list index while checking for `Enum` class (Advait Dixit, PR [18426](https://github.com/python/mypy/pull/18426))
141+
142+
### Stubgen Improvements
143+
144+
* Improve dataclass init signatures (Marc Mueller, PR [18430](https://github.com/python/mypy/pull/18430))
145+
* Preserve `dataclass_transform` decorator (Marc Mueller, PR [18418](https://github.com/python/mypy/pull/18418))
146+
* Fix `UnpackType` for 3.11+ (Marc Mueller, PR [18421](https://github.com/python/mypy/pull/18421))
147+
* Improve `self` annotations (Marc Mueller, PR [18420](https://github.com/python/mypy/pull/18420))
148+
* Print `InspectError` traceback in stubgen `walk_packages` when verbose is specified (Gareth, PR [18224](https://github.com/python/mypy/pull/18224))
149+
150+
### Stubtest Improvements
151+
152+
* Fix crash with numpy array default values (Ali Hamdan, PR [18353](https://github.com/python/mypy/pull/18353))
153+
* Distinguish metaclass attributes from class attributes (Stephen Morton, PR [18314](https://github.com/python/mypy/pull/18314))
154+
155+
### Fixes to Crashes
156+
157+
* Prevent crash with `Unpack` of a fixed tuple in PEP695 type alias (Stanislav Terliakov, PR [18451](https://github.com/python/mypy/pull/18451))
158+
* Fix crash with `--cache-fine-grained --cache-dir=/dev/null` (Shantanu, PR [18457](https://github.com/python/mypy/pull/18457))
159+
* Prevent crashing when `match` arms use name of existing callable (Stanislav Terliakov, PR [18449](https://github.com/python/mypy/pull/18449))
160+
* Gracefully handle encoding errors when writing to stdout (Brian Schubert, PR [18292](https://github.com/python/mypy/pull/18292))
161+
* Prevent crash on generic NamedTuple with unresolved typevar bound (Stanislav Terliakov, PR [18585](https://github.com/python/mypy/pull/18585))
162+
163+
### Documentation Updates
164+
165+
* Add inline tabs to documentation (Marc Mueller, PR [18262](https://github.com/python/mypy/pull/18262))
166+
* Document any `TYPE_CHECKING` name works (Shantanu, PR [18443](https://github.com/python/mypy/pull/18443))
167+
* Update documentation to not mention 3.8 where possible (sobolevn, PR [18455](https://github.com/python/mypy/pull/18455))
168+
* Mention `ignore_errors` in exclude documentation (Shantanu, PR [18412](https://github.com/python/mypy/pull/18412))
169+
* Add `Self` misuse to common issues (Shantanu, PR [18261](https://github.com/python/mypy/pull/18261))
170+
171+
### Other Notable Fixes and Improvements
172+
173+
* Fix literal context for ternary expressions (Ivan Levkivskyi, PR [18545](https://github.com/python/mypy/pull/18545))
174+
* Ignore `dataclass.__replace__` LSP violations (Marc Mueller, PR [18464](https://github.com/python/mypy/pull/18464))
175+
* Bind `self` to the class being defined when checking multiple inheritance (Stanislav Terliakov, PR [18465](https://github.com/python/mypy/pull/18465))
176+
* Fix attribute type resolution with multiple inheritance (Stanislav Terliakov, PR [18415](https://github.com/python/mypy/pull/18415))
177+
* Improve security of our GitHub Actions (sobolevn, PR [18413](https://github.com/python/mypy/pull/18413))
178+
* Unwrap `type[Union[...]]` when solving type variable constraints (Stanislav Terliakov, PR [18266](https://github.com/python/mypy/pull/18266))
179+
* Allow `Any` to match sequence patterns in match/case (Stanislav Terliakov, PR [18448](https://github.com/python/mypy/pull/18448))
180+
* Fix parent generics mapping when overriding generic attribute with property (Stanislav Terliakov, PR [18441](https://github.com/python/mypy/pull/18441))
181+
* Add dedicated error code for explicit `Any` (Shantanu, PR [18398](https://github.com/python/mypy/pull/18398))
182+
* Reject invalid `ParamSpec` locations (Stanislav Terliakov, PR [18278](https://github.com/python/mypy/pull/18278))
183+
* Stop suggesting stubs that have been removed from typeshed (Shantanu, PR [18373](https://github.com/python/mypy/pull/18373))
184+
* Allow inverting `--local-partial-types` (Shantanu, PR [18377](https://github.com/python/mypy/pull/18377))
185+
* Allow to use `Final` and `ClassVar` after Python 3.13 (정승원, PR [18358](https://github.com/python/mypy/pull/18358))
186+
* Update suggestions to include latest stubs in typeshed (Shantanu, PR [18366](https://github.com/python/mypy/pull/18366))
187+
* Fix `--install-types` masking failure details (wyattscarpenter, PR [17485](https://github.com/python/mypy/pull/17485))
188+
* Reject promotions when checking against protocols (Christoph Tyralla, PR [18360](https://github.com/python/mypy/pull/18360))
189+
* Don't erase type object arguments in diagnostics (Shantanu, PR [18352](https://github.com/python/mypy/pull/18352))
190+
* Clarify status in `dmypy status` output (Kcornw, PR [18331](https://github.com/python/mypy/pull/18331))
191+
* Disallow no-argument generic aliases when using PEP 613 explicit aliases (Brian Schubert, PR [18173](https://github.com/python/mypy/pull/18173))
192+
* Suppress errors for unreachable branches in conditional expressions (Brian Schubert, PR [18295](https://github.com/python/mypy/pull/18295))
193+
* Do not allow `ClassVar` and `Final` in `TypedDict` and `NamedTuple` (sobolevn, PR [18281](https://github.com/python/mypy/pull/18281))
194+
* Report error if not enough or too many types provided to `TypeAliasType` (bzoracler, PR [18308](https://github.com/python/mypy/pull/18308))
195+
* Use more precise context for `TypedDict` plugin errors (Brian Schubert, PR [18293](https://github.com/python/mypy/pull/18293))
196+
* Use more precise context for invalid type argument errors (Brian Schubert, PR [18290](https://github.com/python/mypy/pull/18290))
197+
* Do not allow `type[]` to contain `Literal` types (sobolevn, PR [18276](https://github.com/python/mypy/pull/18276))
198+
* Allow bytearray/bytes comparisons with `--strict-bytes` (Jukka Lehtosalo, PR [18255](https://github.com/python/mypy/pull/18255))
199+
200+
### Acknowledgements
201+
202+
Thanks to all mypy contributors who contributed to this release:
203+
204+
- Advait Dixit
205+
- Ali Hamdan
206+
- Brian Schubert
207+
- bzoracler
208+
- Cameron Matsui
209+
- Christoph Tyralla
210+
- Gareth
211+
- Ivan Levkivskyi
212+
- Jukka Lehtosalo
213+
- Kcornw
214+
- Marc Mueller
215+
- Mikhail f. Shiryaev
216+
- Shantanu
217+
- sobolevn
218+
- Stanislav Terliakov
219+
- Stephen Morton
220+
- Valentin Stanciu
221+
- Viktor Szépe
222+
- wyattscarpenter
223+
- 정승원
224+
225+
I’d also like to thank my employer, Dropbox, for supporting mypy development.
226+
71227
## Mypy 1.14
72228

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

docs/source/command_line.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,26 @@ potentially problematic or redundant in some way.
556556
notes, causing mypy to eventually finish with a zero exit code. Features
557557
are considered deprecated when decorated with ``warnings.deprecated``.
558558

559+
.. option:: --deprecated-calls-exclude
560+
561+
This flag allows to selectively disable :ref:`deprecated<code-deprecated>` warnings
562+
for functions and methods defined in specific packages, modules, or classes.
563+
Note that each exclude entry acts as a prefix. For example (assuming ``foo.A.func`` is deprecated):
564+
565+
.. code-block:: python
566+
567+
# mypy --enable-error-code deprecated
568+
# --deprecated-calls-exclude=foo.A
569+
import foo
570+
571+
foo.A().func() # OK, the deprecated warning is ignored
572+
573+
# file foo.py
574+
from typing_extensions import deprecated
575+
class A:
576+
@deprecated("Use A.func2 instead")
577+
def func(self): pass
578+
559579
.. _miscellaneous-strictness-flags:
560580

561581
Miscellaneous strictness flags

docs/source/config_file.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,16 @@ section of the command line docs.
666666
Shows a warning when encountering any code inferred to be unreachable or
667667
redundant after performing type analysis.
668668

669+
.. confval:: deprecated_calls_exclude
670+
671+
:type: comma-separated list of strings
672+
673+
Selectively excludes functions and methods defined in specific packages,
674+
modules, and classes from the :ref:`deprecated<code-deprecated>` error code.
675+
This also applies to all submodules of packages (i.e. everything inside
676+
a given prefix). Note, this option does not support per-file configuration,
677+
the exclusions list is defined globally for all your code.
678+
669679

670680
Suppressing errors
671681
******************

docs/source/error_code_list2.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ locally. Features are considered deprecated when decorated with ``warnings.depr
243243
specified in `PEP 702 <https://peps.python.org/pep-0702>`_.
244244
Use the :option:`--report-deprecated-as-note <mypy --report-deprecated-as-note>` option to
245245
turn all such errors into notes.
246+
Use :option:`--deprecated-calls-exclude <mypy --deprecated-calls-exclude>` to hide warnings
247+
for specific functions, classes and packages.
246248

247249
.. note::
248250

docs/source/generics.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ similarly supported via generics (Python 3.12 syntax):
999999

10001000
.. code-block:: python
10011001
1002-
from colletions.abc import Callable
1002+
from collections.abc import Callable
10031003
from typing import Any
10041004
10051005
def route[F: Callable[..., Any]](url: str) -> Callable[[F], F]:

docs/source/more_types.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ program:
390390
The ``summarize([])`` call matches both variants: an empty list could
391391
be either a ``list[int]`` or a ``list[str]``. In this case, mypy
392392
will break the tie by picking the first matching variant: ``output``
393-
will have an inferred type of ``float``. The implementor is responsible
393+
will have an inferred type of ``float``. The implementer is responsible
394394
for making sure ``summarize`` breaks ties in the same way at runtime.
395395

396396
However, there are two exceptions to the "pick the first match" rule.

0 commit comments

Comments
 (0)