Skip to content

Commit 8e449f6

Browse files
committed
Merge remote-tracking branch 'upstream/master' into stubgen-builtin-containers
Fix conflicts
2 parents efefee0 + bfbac5e commit 8e449f6

File tree

370 files changed

+5234
-5834
lines changed

Some content is hidden

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

370 files changed

+5234
-5834
lines changed

.github/workflows/build_wheels.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@v4
17-
- uses: actions/setup-python@v4
17+
- uses: actions/setup-python@v5
1818
with:
1919
python-version: '3.11'
2020
- name: Trigger script

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
VERIFY_MYPY_ERROR_CODES: 1
3535
steps:
3636
- uses: actions/checkout@v4
37-
- uses: actions/setup-python@v4
37+
- uses: actions/setup-python@v5
3838
with:
3939
python-version: '3.8'
4040
- name: Install tox

.github/workflows/mypy_primer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
with:
3838
path: mypy_to_test
3939
fetch-depth: 0
40-
- uses: actions/setup-python@v4
40+
- uses: actions/setup-python@v5
4141
with:
4242
python-version: "3.10"
4343
- name: Install dependencies

.github/workflows/mypy_primer_comment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
4545
- name: Post comment
4646
id: post-comment
47-
uses: actions/github-script@v6
47+
uses: actions/github-script@v7
4848
with:
4949
github-token: ${{ secrets.GITHUB_TOKEN }}
5050
script: |

.github/workflows/sync_typeshed.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
fetch-depth: 0
2121
# TODO: use whatever solution ends up working for
2222
# https://github.com/python/typeshed/issues/8434
23-
- uses: actions/setup-python@v4
23+
- uses: actions/setup-python@v5
2424
with:
2525
python-version: "3.10"
2626
- name: git config

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ jobs:
120120
PYTEST_ADDOPTS: --color=yes
121121
steps:
122122
- uses: actions/checkout@v4
123-
- uses: actions/setup-python@v4
123+
- uses: actions/setup-python@v5
124124
with:
125125
python-version: ${{ matrix.python }}
126126
architecture: ${{ matrix.arch }}

.github/workflows/test_stubgenc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- uses: actions/checkout@v4
3131

3232
- name: Setup 🐍 3.8
33-
uses: actions/setup-python@v4
33+
uses: actions/setup-python@v5
3434
with:
3535
python-version: 3.8
3636

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ repos:
66
- id: trailing-whitespace
77
- id: end-of-file-fixer
88
- repo: https://github.com/psf/black-pre-commit-mirror
9-
rev: 23.9.1 # must match test-requirements.txt
9+
rev: 24.1.1 # must match test-requirements.txt
1010
hooks:
1111
- id: black
1212
exclude: '^(test-data/)'
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.1.4 # must match test-requirements.txt
14+
rev: v0.2.0 # must match test-requirements.txt
1515
hooks:
1616
- id: ruff
1717
args: [--exit-non-zero-on-fix]

CHANGELOG.md

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

33
## Next release
44

5+
Stubtest will ignore private function/method parameters when they are missing from the stub. Private parameters
6+
names start with a single underscore and have a default (PR [16507](https://github.com/python/mypy/pull/16507)).
7+
58
## Mypy 1.8
69

710
We’ve just uploaded mypy 1.8 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)). Mypy is a static type checker for Python. This release includes new features, performance improvements and bug fixes. You can install it as follows:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ To report a bug or request an enhancement:
4141

4242
To discuss a new type system feature:
4343

44-
- discuss at [typing-sig mailing list](https://mail.python.org/archives/list/typing[email protected]/)
45-
- there is also some historical discussion [here](https://github.com/python/typing/issues)
44+
- discuss at [discuss.python.org](https://discuss.python.org/c/typing/32)
45+
- there is also some historical discussion at the [typing-sig mailing list](https://mail.python.org/archives/list/[email protected]/) and the [python/typing repo](https://github.com/python/typing/issues)
4646

4747
What is mypy?
4848
-------------

docs/source/cheat_sheet_py3.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ Classes
209209
# This will allow access to any A.x, if x is compatible with the return type
210210
def __getattr__(self, name: str) -> int: ...
211211
212+
a = A()
212213
a.foo = 42 # Works
213214
a.bar = 'Ex-parrot' # Fails type checking
214215

docs/source/config_file.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
The mypy configuration file
44
===========================
55

6+
Mypy is very configurable. This is most useful when introducing typing to
7+
an existing codebase. See :ref:`existing-code` for concrete advice for
8+
that situation.
9+
610
Mypy supports reading configuration settings from a file with the following precedence order:
711

812
1. ``./mypy.ini``

docs/source/error_code_list2.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,11 +484,11 @@ Example:
484484
485485
.. _code-mutable-override:
486486

487-
Check that overrides of mutable attributes are safe
488-
---------------------------------------------------
487+
Check that overrides of mutable attributes are safe [mutable-override]
488+
----------------------------------------------------------------------
489489

490-
This will enable the check for unsafe overrides of mutable attributes. For
491-
historical reasons, and because this is a relatively common pattern in Python,
490+
`mutable-override` will enable the check for unsafe overrides of mutable attributes.
491+
For historical reasons, and because this is a relatively common pattern in Python,
492492
this check is not enabled by default. The example below is unsafe, and will be
493493
flagged when this error code is enabled:
494494

docs/source/error_codes.rst

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,6 @@ Most error codes are shared between multiple related error messages.
1919
Error codes may change in future mypy releases.
2020

2121

22-
23-
Displaying error codes
24-
----------------------
25-
26-
Error codes are displayed by default. Use :option:`--hide-error-codes <mypy --hide-error-codes>`
27-
or config ``hide_error_codes = True`` to hide error codes. Error codes are shown inside square brackets:
28-
29-
.. code-block:: text
30-
31-
$ mypy prog.py
32-
prog.py:1: error: "str" has no attribute "trim" [attr-defined]
33-
34-
It's also possible to require error codes for ``type: ignore`` comments.
35-
See :ref:`ignore-without-code<code-ignore-without-code>` for more information.
36-
37-
3822
.. _silence-error-codes:
3923

4024
Silencing errors based on error codes
@@ -121,3 +105,10 @@ Similar logic works for disabling error codes globally. If a given error code
121105
is a subcode of another one, it will be mentioned in the documentation for the narrower
122106
code. This hierarchy is not nested: there cannot be subcodes of other
123107
subcodes.
108+
109+
110+
Requiring error codes
111+
---------------------
112+
113+
It's possible to require error codes be specified in ``type: ignore`` comments.
114+
See :ref:`ignore-without-code<code-ignore-without-code>` for more information.

docs/source/existing_code.rst

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ invocation to your codebase, or adding your mypy invocation to
3131
existing tools you use to run tests, like ``tox``.
3232

3333
* Make sure everyone runs mypy with the same options. Checking a mypy
34-
:ref:`configuration file <config-file>` into your codebase can help
35-
with this.
34+
:ref:`configuration file <config-file>` into your codebase is the
35+
easiest way to do this.
3636

3737
* Make sure everyone type checks the same set of files. See
3838
:ref:`specifying-code-to-be-checked` for details.
@@ -48,7 +48,7 @@ A simple CI script could look something like this:
4848

4949
.. code-block:: text
5050
51-
python3 -m pip install mypy==0.971
51+
python3 -m pip install mypy==1.8
5252
# Run your standardised mypy invocation, e.g.
5353
mypy my_project
5454
# This could also look like `scripts/run_mypy.sh`, `tox run -e mypy`, `make mypy`, etc
@@ -74,6 +74,11 @@ You could even invert this, by setting ``ignore_errors = True`` in your global
7474
config section and only enabling error reporting with ``ignore_errors = False``
7575
for the set of modules you are ready to type check.
7676

77+
The per-module configuration that mypy's configuration file allows can be
78+
extremely useful. Many configuration options can be enabled or disabled
79+
only for specific modules. In particular, you can also enable or disable
80+
various error codes on a per-module basis, see :ref:`error-codes`.
81+
7782
Fixing errors related to imports
7883
--------------------------------
7984

@@ -89,7 +94,7 @@ that it can't find, that don't have types, or don't have stub files:
8994
Sometimes these can be fixed by installing the relevant packages or
9095
stub libraries in the environment you're running ``mypy`` in.
9196

92-
See :ref:`ignore-missing-imports` for a complete reference on these errors
97+
See :ref:`fix-missing-imports` for a complete reference on these errors
9398
and the ways in which you can fix them.
9499

95100
You'll likely find that you want to suppress all errors from importing
@@ -118,13 +123,15 @@ codebase, use a config like this:
118123
ignore_missing_imports = True
119124
120125
If you get a large number of errors, you may want to ignore all errors
121-
about missing imports, for instance by setting :confval:`ignore_missing_imports`
122-
to true globally. This can hide errors later on, so we recommend avoiding this
126+
about missing imports, for instance by setting
127+
:option:`--disable-error-code=import-untyped <mypy --ignore-missing-imports>`.
128+
or setting :confval:`ignore_missing_imports` to true globally.
129+
This can hide errors later on, so we recommend avoiding this
123130
if possible.
124131

125132
Finally, mypy allows fine-grained control over specific import following
126133
behaviour. It's very easy to silently shoot yourself in the foot when playing
127-
around with these, so it's mostly recommended as a last resort. For more
134+
around with these, so this should be a last resort. For more
128135
details, look :ref:`here <follow-imports>`.
129136

130137
Prioritise annotating widely imported modules

docs/source/mypy_daemon.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ you have a large codebase.)
6161

6262
.. note::
6363

64-
The mypy daemon automatically enables ``--local-partial-types`` by default.
64+
The mypy daemon requires ``--local-partial-types`` and automatically enables it.
6565

6666

6767
Daemon client commands

docs/source/running_mypy.rst

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -305,16 +305,20 @@ not catch errors in its use.
305305
The ``.*`` after ``foobar`` will ignore imports of ``foobar`` modules
306306
and subpackages in addition to the ``foobar`` top-level package namespace.
307307

308-
3. To suppress *all* missing import errors for *all* libraries in your codebase,
309-
invoke mypy with the :option:`--ignore-missing-imports <mypy --ignore-missing-imports>` command line flag or set
310-
the :confval:`ignore_missing_imports`
311-
config file option to True
312-
in the *global* section of your mypy config file::
308+
3. To suppress *all* missing import errors for *all* untyped libraries
309+
in your codebase, use :option:`--disable-error-code=import-untyped <mypy --ignore-missing-imports>`.
310+
See :ref:`code-import-untyped` for more details on this error code.
311+
312+
You can also set :confval:`disable_error_code`, like so::
313313

314314
[mypy]
315-
ignore_missing_imports = True
315+
disable_error_code = import-untyped
316+
316317

317-
We recommend using this approach only as a last resort: it's equivalent
318+
You can also set the :option:`--ignore-missing-imports <mypy --ignore-missing-imports>`
319+
command line flag or set the :confval:`ignore_missing_imports` config file
320+
option to True in the *global* section of your mypy config file. We
321+
recommend avoiding ``--ignore-missing-imports`` if possible: it's equivalent
318322
to adding a ``# type: ignore`` to all unresolved imports in your codebase.
319323

320324

@@ -387,11 +391,11 @@ this error, try:
387391
installing into the environment you expect by running pip like
388392
``python -m pip ...``.
389393

390-
2. Reading the :ref:`finding-imports` section below to make sure you
394+
3. Reading the :ref:`finding-imports` section below to make sure you
391395
understand how exactly mypy searches for and finds modules and modify
392396
how you're invoking mypy accordingly.
393397

394-
3. Directly specifying the directory containing the module you want to
398+
4. Directly specifying the directory containing the module you want to
395399
type check from the command line, by using the :confval:`mypy_path`
396400
or :confval:`files` config file options,
397401
or by using the ``MYPYPATH`` environment variable.

misc/sync-typeshed.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ def main() -> None:
179179
print("Created typeshed sync commit.")
180180

181181
commits_to_cherry_pick = [
182-
"588623ff2", # LiteralString reverts
183-
"bdcc90e85", # sum reverts
184-
"3e5d81337", # ctypes reverts
185-
"344298e3a", # ParamSpec for functools.wraps
182+
"d25e4a9eb", # LiteralString reverts
183+
"d132999ba", # sum reverts
184+
"dd12a2d81", # ctypes reverts
185+
"0dd4b6f75", # ParamSpec for functools.wraps
186186
]
187187
for commit in commits_to_cherry_pick:
188188
try:

mypy/applytype.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ def apply_generic_arguments(
9393
bound or constraints, instead of giving an error.
9494
"""
9595
tvars = callable.variables
96-
assert len(tvars) == len(orig_types)
96+
min_arg_count = sum(not tv.has_default() for tv in tvars)
97+
assert min_arg_count <= len(orig_types) <= len(tvars)
9798
# Check that inferred type variable values are compatible with allowed
9899
# values and bounds. Also, promote subtype values to allowed values.
99100
# Create a map from type variable id to target type.
@@ -146,7 +147,18 @@ def apply_generic_arguments(
146147
# TODO: move apply_poly() logic from checkexpr.py here when new inference
147148
# becomes universally used (i.e. in all passes + in unification).
148149
# With this new logic we can actually *add* some new free variables.
149-
remaining_tvars = [tv for tv in tvars if tv.id not in id_to_type]
150+
remaining_tvars: list[TypeVarLikeType] = []
151+
for tv in tvars:
152+
if tv.id in id_to_type:
153+
continue
154+
if not tv.has_default():
155+
remaining_tvars.append(tv)
156+
continue
157+
# TypeVarLike isn't in id_to_type mapping.
158+
# Only expand the TypeVar default here.
159+
typ = expand_type(tv, id_to_type)
160+
assert isinstance(typ, TypeVarLikeType)
161+
remaining_tvars.append(typ)
150162

151163
return callable.copy_modified(
152164
ret_type=expand_type(callable.ret_type, id_to_type),

mypy/build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
The function build() is the main interface to this module.
1010
"""
11+
1112
# TODO: More consistent terminology, e.g. path/fnam, module/id, state/file
1213

1314
from __future__ import annotations

0 commit comments

Comments
 (0)