Skip to content

Commit e5edcc1

Browse files
authored
Merge branch 'master' into numbers
2 parents 994a4ab + e93f06c commit e5edcc1

File tree

267 files changed

+6326
-2814
lines changed

Some content is hidden

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

267 files changed

+6326
-2814
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.12"
42+
python-version: "3.13"
4343
- name: Install dependencies
4444
run: |
4545
python -m pip install -U pip

.pre-commit-config.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ repos:
66
- id: trailing-whitespace
77
- id: end-of-file-fixer
88
- repo: https://github.com/psf/black-pre-commit-mirror
9-
rev: 24.10.0
9+
rev: 25.1.0
1010
hooks:
1111
- id: black
1212
exclude: '^(test-data/)'
@@ -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/)).

CREDITS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Dropbox core team:
1515

1616
Non-Dropbox core team members:
1717

18-
Ethan Smith
18+
Emma Harper Smith <[email protected]>
1919
Guido van Rossum <[email protected]>
2020
Jelle Zijlstra <[email protected]>
2121
Michael J. Sullivan <[email protected]>

docs/source/command_line.rst

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ for full details, see :ref:`running-mypy`.
8181
never recursively discover files with extensions other than ``.py`` or
8282
``.pyi``.
8383

84+
.. option:: --exclude-gitignore
85+
86+
This flag will add everything that matches ``.gitignore`` file(s) to :option:`--exclude`.
87+
8488

8589
Optional arguments
8690
******************
@@ -556,6 +560,26 @@ potentially problematic or redundant in some way.
556560
notes, causing mypy to eventually finish with a zero exit code. Features
557561
are considered deprecated when decorated with ``warnings.deprecated``.
558562

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

561585
Miscellaneous strictness flags
@@ -692,9 +716,8 @@ of the above sections.
692716
.. option:: --extra-checks
693717

694718
This flag enables additional checks that are technically correct but may be
695-
impractical in real code. In particular, it prohibits partial overlap in
696-
``TypedDict`` updates, and makes arguments prepended via ``Concatenate``
697-
positional-only. For example:
719+
impractical. In particular, it prohibits partial overlap in ``TypedDict`` updates,
720+
and makes arguments prepended via ``Concatenate`` positional-only. For example:
698721

699722
.. code-block:: python
700723
@@ -717,6 +740,13 @@ of the above sections.
717740
bad: Bad = {"a": 0, "b": "no"}
718741
test(bad, bar)
719742
743+
In future more checks may be added to this flag if:
744+
745+
* The corresponding use cases are rare, thus not justifying a dedicated
746+
strictness flag.
747+
748+
* The new check cannot be supported as an opt-in error code.
749+
720750
.. option:: --strict
721751

722752
This flag mode enables all optional error checking flags. You can see the

0 commit comments

Comments
 (0)