Skip to content

Commit 6cbc7ac

Browse files
Merge branch 'master' into default-strict-bytes
2 parents 2524f19 + 84e8f1f commit 6cbc7ac

296 files changed

Lines changed: 15640 additions & 3526 deletions

File tree

Some content is hidden

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

.github/workflows/test.yml

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ jobs:
9494
# This is broken. See
9595
# - https://github.com/python/mypy/issues/17819
9696
# - https://github.com/python/mypy/pull/17822
97-
# - name: mypyc runtime tests with py38-debug-build-ubuntu
98-
# python: '3.9.21'
97+
# - name: mypyc runtime tests with py310-debug-build-ubuntu
98+
# python: '3.10'
9999
# os: ubuntu-latest
100100
# toxenv: py
101101
# tox_extra_args: "-n 4 mypyc/test/test_run.py mypyc/test/test_external.py"
@@ -152,24 +152,15 @@ jobs:
152152
with:
153153
persist-credentials: false
154154

155-
- name: Debug build
156-
if: ${{ matrix.debug_build }}
157-
run: |
158-
PYTHONVERSION=${{ matrix.python }}
159-
PYTHONDIR=~/python-debug/python-$PYTHONVERSION
160-
VENV=$PYTHONDIR/env
161-
./misc/build-debug-python.sh $PYTHONVERSION $PYTHONDIR $VENV
162-
# TODO: does this do anything? env vars aren't passed to the next step right
163-
source $VENV/bin/activate
164155
- name: Latest dev build
165156
if: ${{ endsWith(matrix.python, '-dev') }}
166157
run: |
167158
git clone --depth 1 https://github.com/python/cpython.git /tmp/cpython --branch $( echo ${{ matrix.python }} | sed 's/-dev//' )
168159
cd /tmp/cpython
169160
echo git rev-parse HEAD; git rev-parse HEAD
170161
git show --no-patch
171-
sudo apt-get update
172-
sudo apt-get install -y --no-install-recommends \
162+
sudo apt-get update -q
163+
sudo apt-get install -q -y --no-install-recommends \
173164
build-essential gdb lcov libbz2-dev libffi-dev libgdbm-dev liblzma-dev libncurses5-dev \
174165
libreadline6-dev libsqlite3-dev libssl-dev lzma lzma-dev tk-dev uuid-dev zlib1g-dev
175166
./configure --prefix=/opt/pythondev
@@ -178,6 +169,23 @@ jobs:
178169
sudo ln -s /opt/pythondev/bin/python3 /opt/pythondev/bin/python
179170
sudo ln -s /opt/pythondev/bin/pip3 /opt/pythondev/bin/pip
180171
echo "/opt/pythondev/bin" >> $GITHUB_PATH
172+
- name: Debug build
173+
if: ${{ matrix.debug_build }}
174+
run: |
175+
git clone --depth 1 https://github.com/python/cpython.git /tmp/cpython --branch ${{ matrix.python }}
176+
cd /tmp/cpython
177+
echo git rev-parse HEAD; git rev-parse HEAD
178+
git show --no-patch
179+
sudo apt-get update -q
180+
sudo apt-get install -q -y --no-install-recommends \
181+
build-essential gdb lcov libbz2-dev libffi-dev libgdbm-dev liblzma-dev libncurses5-dev \
182+
libreadline6-dev libsqlite3-dev libssl-dev lzma lzma-dev tk-dev uuid-dev zlib1g-dev
183+
./configure CFLAGS="-DPy_DEBUG -DPy_TRACE_REFS -DPYMALLOC_DEBUG" --with-pydebug -with-trace-refs --prefix=/opt/pythondev
184+
make -j$(nproc)
185+
sudo make install
186+
sudo ln -s /opt/pythondev/bin/python3 /opt/pythondev/bin/python
187+
sudo ln -s /opt/pythondev/bin/pip3 /opt/pythondev/bin/pip
188+
echo "/opt/pythondev/bin" >> $GITHUB_PATH
181189
- uses: actions/setup-python@v5
182190
if: ${{ !(matrix.debug_build || endsWith(matrix.python, '-dev')) }}
183191
with:

.pre-commit-config.yaml

Lines changed: 1 addition & 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: 25.9.0
9+
rev: 26.1.0
1010
hooks:
1111
- id: black
1212
exclude: '^(test-data/)'

docs/source/command_line.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,13 +537,15 @@ potentially problematic or redundant in some way.
537537
print(x + "bad")
538538
539539
To help prevent mypy from generating spurious warnings, the "Statement is
540-
unreachable" warning will be silenced in exactly two cases:
540+
unreachable" warning will be silenced in exactly three cases:
541541

542542
1. When the unreachable statement is a ``raise`` statement, is an
543543
``assert False`` statement, or calls a function that has the :py:data:`~typing.NoReturn`
544544
return type hint. In other words, when the unreachable statement
545545
throws an error or terminates the program in some way.
546-
2. When the unreachable statement was *intentionally* marked as unreachable
546+
2. When the unreachable statement is ``return NotImplemented``. This
547+
is allowed by mypy due to its use in operator overloading.
548+
3. When the unreachable statement was *intentionally* marked as unreachable
547549
using :ref:`version_and_platform_checks`.
548550

549551
.. note::

docs/source/error_code_list2.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Example:
3232
3333
# mypy: disallow-any-generics
3434
35-
# Error: Missing type parameters for generic type "list" [type-arg]
35+
# Error: Missing type arguments for generic type "list" [type-arg]
3636
def remove_dups(items: list) -> list:
3737
...
3838

docs/source/type_inference_and_annotations.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ on the declared type of ``arg`` in ``foo``:
159159
.. code-block:: python
160160
161161
def foo(arg: list[int]) -> None:
162-
print('Items:', ''.join(str(a) for a in arg))
162+
print('Items:', ', '.join(str(a) for a in arg))
163163
164164
foo([]) # OK
165165
@@ -170,7 +170,7 @@ in the following statement:
170170
.. code-block:: python
171171
172172
def foo(arg: list[int]) -> None:
173-
print('Items:', ', '.join(arg))
173+
print('Items:', ', '.join(str(a) for a in arg))
174174
175175
a = [] # Error: Need type annotation for "a"
176176
foo(a)

misc/sync-typeshed.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,12 @@ def main() -> None:
184184
assert commit
185185

186186
# Create a commit
187-
message = textwrap.dedent(
188-
f"""\
187+
message = textwrap.dedent(f"""\
189188
Sync typeshed
190189
191190
Source commit:
192191
https://github.com/python/typeshed/commit/{commit}
193-
"""
194-
)
192+
""")
195193
subprocess.run(["git", "add", "--all", os.path.join("mypy", "typeshed")], check=True)
196194
subprocess.run(["git", "commit", "-m", message], check=True)
197195
print("Created typeshed sync commit.")

misc/typeshed_patches/0001-Partially-revert-Clean-up-argparse-hacks.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 84a9d586544a0408d4654f57f83a93cb048070fb Mon Sep 17 00:00:00 2001
1+
From b6d495c10e79fb56ff64f8fb90c87894090f9cbe Mon Sep 17 00:00:00 2001
22
From: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
33
Date: Sat, 15 Feb 2025 20:11:06 +0100
44
Subject: [PATCH] Partially revert Clean up argparse hacks
@@ -8,7 +8,7 @@ Subject: [PATCH] Partially revert Clean up argparse hacks
88
1 file changed, 5 insertions(+), 3 deletions(-)
99

1010
diff --git a/mypy/typeshed/stdlib/argparse.pyi b/mypy/typeshed/stdlib/argparse.pyi
11-
index b9fa31139..3c3ba116a 100644
11+
index ae99eb036..c87b8f4fc 100644
1212
--- a/mypy/typeshed/stdlib/argparse.pyi
1313
+++ b/mypy/typeshed/stdlib/argparse.pyi
1414
@@ -2,7 +2,7 @@ import sys
@@ -41,5 +41,5 @@ index b9fa31139..3c3ba116a 100644
4141
default: Any = ...,
4242
type: _ActionType = ...,
4343
--
44-
2.50.1
44+
2.52.0
4545

misc/typeshed_patches/0001-Remove-use-of-LiteralString-in-builtins-13743.patch

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 3229a6066cff3d80d6cb923322c2d42a300d0be3 Mon Sep 17 00:00:00 2001
1+
From ed11d7e0204868ef1a43c17ed950372b1d78f497 Mon Sep 17 00:00:00 2001
22
From: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
33
Date: Mon, 26 Sep 2022 12:55:07 -0700
44
Subject: [PATCH] Remove use of LiteralString in builtins (#13743)
@@ -8,18 +8,18 @@ Subject: [PATCH] Remove use of LiteralString in builtins (#13743)
88
1 file changed, 1 insertion(+), 99 deletions(-)
99

1010
diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi
11-
index 969d16876..044e264d2 100644
11+
index 693dd0b77..8acdeadff 100644
1212
--- a/mypy/typeshed/stdlib/builtins.pyi
1313
+++ b/mypy/typeshed/stdlib/builtins.pyi
14-
@@ -63,7 +63,6 @@ from typing import ( # noqa: Y022,UP035
14+
@@ -64,7 +64,6 @@ from typing import ( # noqa: Y022,UP035
1515
from typing_extensions import ( # noqa: Y023
1616
Concatenate,
1717
Literal,
1818
- LiteralString,
1919
ParamSpec,
2020
Self,
2121
TypeAlias,
22-
@@ -480,31 +479,16 @@ class str(Sequence[str]):
22+
@@ -482,31 +481,16 @@ class str(Sequence[str]):
2323
def __new__(cls, object: object = "") -> Self: ...
2424
@overload
2525
def __new__(cls, object: ReadableBuffer, encoding: str = "utf-8", errors: str = "strict") -> Self: ...
@@ -51,7 +51,7 @@ index 969d16876..044e264d2 100644
5151
def format(self, *args: object, **kwargs: object) -> str: ...
5252
def format_map(self, mapping: _FormatMapMapping, /) -> str: ...
5353
def index(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
54-
@@ -520,98 +504,34 @@ class str(Sequence[str]):
54+
@@ -522,98 +506,34 @@ class str(Sequence[str]):
5555
def isspace(self) -> bool: ...
5656
def istitle(self) -> bool: ...
5757
def isupper(self) -> bool: ...
@@ -150,7 +150,7 @@ index 969d16876..044e264d2 100644
150150
def zfill(self, width: SupportsIndex, /) -> str: ... # type: ignore[misc]
151151
@staticmethod
152152
@overload
153-
@@ -622,39 +542,21 @@ class str(Sequence[str]):
153+
@@ -624,39 +544,21 @@ class str(Sequence[str]):
154154
@staticmethod
155155
@overload
156156
def maketrans(x: str, y: str, z: str, /) -> dict[int, int | None]: ...
@@ -192,5 +192,5 @@ index 969d16876..044e264d2 100644
192192
def __getnewargs__(self) -> tuple[str]: ...
193193
def __format__(self, format_spec: str, /) -> str: ...
194194
--
195-
2.51.1
195+
2.52.0
196196

misc/typeshed_patches/0001-Revert-Remove-redundant-inheritances-from-Iterator.patch

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 7678bc3f80e4d3f04a0ff0ee3a7d51f49ae4c465 Mon Sep 17 00:00:00 2001
1+
From 69791281c2c5e919cea9a77c4a771f79d9e70384 Mon Sep 17 00:00:00 2001
22
From: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
33
Date: Sat, 21 Dec 2024 22:36:38 +0100
44
Subject: [PATCH] Revert Remove redundant inheritances from Iterator in
@@ -36,10 +36,10 @@ index d663f5d93..f43178e4d 100644
3636
@property
3737
def _exception(self) -> BaseException | None: ...
3838
diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi
39-
index 044e264d2..6d813f172 100644
39+
index 8acdeadff..5a3bb5908 100644
4040
--- a/mypy/typeshed/stdlib/builtins.pyi
4141
+++ b/mypy/typeshed/stdlib/builtins.pyi
42-
@@ -1210,7 +1210,7 @@ class frozenset(AbstractSet[_T_co]):
42+
@@ -1226,7 +1226,7 @@ class frozenset(AbstractSet[_T_co]):
4343
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
4444

4545
@disjoint_base
@@ -48,7 +48,7 @@ index 044e264d2..6d813f172 100644
4848
def __new__(cls, iterable: Iterable[_T], start: int = 0) -> Self: ...
4949
def __iter__(self) -> Self: ...
5050
def __next__(self) -> tuple[int, _T]: ...
51-
@@ -1404,7 +1404,7 @@ else:
51+
@@ -1413,7 +1413,7 @@ else:
5252
exit: _sitebuiltins.Quitter
5353

5454
@disjoint_base
@@ -57,7 +57,7 @@ index 044e264d2..6d813f172 100644
5757
@overload
5858
def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ...
5959
@overload
60-
@@ -1468,7 +1468,7 @@ license: _sitebuiltins._Printer
60+
@@ -1477,7 +1477,7 @@ license: _sitebuiltins._Printer
6161

6262
def locals() -> dict[str, Any]: ...
6363
@disjoint_base
@@ -66,7 +66,7 @@ index 044e264d2..6d813f172 100644
6666
# 3.14 adds `strict` argument.
6767
if sys.version_info >= (3, 14):
6868
@overload
69-
@@ -1775,7 +1775,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex
69+
@@ -1784,7 +1784,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex
7070
quit: _sitebuiltins.Quitter
7171

7272
@disjoint_base
@@ -75,7 +75,7 @@ index 044e264d2..6d813f172 100644
7575
@overload
7676
def __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T]: ... # type: ignore[misc]
7777
@overload
78-
@@ -1839,7 +1839,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
78+
@@ -1848,7 +1848,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
7979
@overload
8080
def vars(object: Any = ..., /) -> dict[str, Any]: ...
8181
@disjoint_base
@@ -107,7 +107,7 @@ index 2c8e7109c..4ed0ab1d8 100644
107107
restkey: _T | None
108108
restval: str | Any | None
109109
diff --git a/mypy/typeshed/stdlib/fileinput.pyi b/mypy/typeshed/stdlib/fileinput.pyi
110-
index 910d63814..eb942bc55 100644
110+
index 6778b7648..95164de2f 100644
111111
--- a/mypy/typeshed/stdlib/fileinput.pyi
112112
+++ b/mypy/typeshed/stdlib/fileinput.pyi
113113
@@ -1,8 +1,8 @@
@@ -118,7 +118,7 @@ index 910d63814..eb942bc55 100644
118118
from types import GenericAlias, TracebackType
119119
-from typing import IO, Any, AnyStr, Generic, Literal, Protocol, overload, type_check_only
120120
+from typing import IO, Any, AnyStr, Literal, Protocol, overload, type_check_only
121-
from typing_extensions import Self, TypeAlias
121+
from typing_extensions import Self, TypeAlias, deprecated
122122

123123
__all__ = [
124124
@@ -105,7 +105,7 @@ def fileno() -> int: ...
@@ -131,7 +131,7 @@ index 910d63814..eb942bc55 100644
131131
# encoding and errors are added
132132
@overload
133133
diff --git a/mypy/typeshed/stdlib/itertools.pyi b/mypy/typeshed/stdlib/itertools.pyi
134-
index fe4ccbdf8..73745fe92 100644
134+
index 8a924ad8b..5c2bf7f83 100644
135135
--- a/mypy/typeshed/stdlib/itertools.pyi
136136
+++ b/mypy/typeshed/stdlib/itertools.pyi
137137
@@ -28,7 +28,7 @@ _Predicate: TypeAlias = Callable[[_T], object]
@@ -166,7 +166,7 @@ index fe4ccbdf8..73745fe92 100644
166166
-class accumulate(Generic[_T]):
167167
+class accumulate(Iterator[_T]):
168168
@overload
169-
def __new__(cls, iterable: Iterable[_T], func: None = None, *, initial: _T | None = ...) -> Self: ...
169+
def __new__(cls, iterable: Iterable[_T], func: None = None, *, initial: _T | None = None) -> Self: ...
170170
@overload
171171
@@ -64,7 +64,7 @@ class accumulate(Generic[_T]):
172172
def __next__(self) -> _T: ...
@@ -239,7 +239,7 @@ index fe4ccbdf8..73745fe92 100644
239239
+class zip_longest(Iterator[_T_co]):
240240
# one iterable (fillvalue doesn't matter)
241241
@overload
242-
def __new__(cls, iter1: Iterable[_T1], /, *, fillvalue: object = ...) -> zip_longest[tuple[_T1]]: ...
242+
def __new__(cls, iter1: Iterable[_T1], /, *, fillvalue: object = None) -> zip_longest[tuple[_T1]]: ...
243243
@@ -202,7 +202,7 @@ class zip_longest(Generic[_T_co]):
244244
def __next__(self) -> _T_co: ...
245245

@@ -291,8 +291,8 @@ index fe4ccbdf8..73745fe92 100644
291291
- class batched(Generic[_T_co]):
292292
+ class batched(Iterator[tuple[_T_co, ...]], Generic[_T_co]):
293293
if sys.version_info >= (3, 13):
294-
def __new__(cls, iterable: Iterable[_T_co], n: int, *, strict: bool = False) -> Self: ...
295-
else:
294+
@overload
295+
def __new__(cls, iterable: Iterable[_T], n: Literal[1], *, strict: Literal[True]) -> batched[tuple[_T]]: ...
296296
diff --git a/mypy/typeshed/stdlib/multiprocessing/pool.pyi b/mypy/typeshed/stdlib/multiprocessing/pool.pyi
297297
index b79f9e773..f276372d0 100644
298298
--- a/mypy/typeshed/stdlib/multiprocessing/pool.pyi
@@ -313,10 +313,10 @@ index b79f9e773..f276372d0 100644
313313
def __iter__(self) -> Self: ...
314314
def next(self, timeout: float | None = None) -> _T: ...
315315
diff --git a/mypy/typeshed/stdlib/sqlite3/__init__.pyi b/mypy/typeshed/stdlib/sqlite3/__init__.pyi
316-
index 6b0f1ba94..882cd143c 100644
316+
index 04b978b1b..e4604144f 100644
317317
--- a/mypy/typeshed/stdlib/sqlite3/__init__.pyi
318318
+++ b/mypy/typeshed/stdlib/sqlite3/__init__.pyi
319-
@@ -407,7 +407,7 @@ class Connection:
319+
@@ -408,7 +408,7 @@ class Connection:
320320
) -> Literal[False]: ...
321321

322322
@disjoint_base
@@ -326,5 +326,5 @@ index 6b0f1ba94..882cd143c 100644
326326
@property
327327
def connection(self) -> Connection: ...
328328
--
329-
2.51.1
329+
2.52.0
330330

misc/typeshed_patches/0001-Revert-sum-literal-integer-change-13961.patch

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 16b0b50ec77e470f24145071acde5274a1de53a0 Mon Sep 17 00:00:00 2001
1+
From 0e30b762e8335f02e19977c055ac7b98e707991c Mon Sep 17 00:00:00 2001
22
From: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
33
Date: Sat, 29 Oct 2022 12:47:21 -0700
44
Subject: [PATCH] Revert sum literal integer change (#13961)
@@ -19,10 +19,10 @@ within mypy, I might pursue upstreaming this in typeshed.
1919
1 file changed, 1 insertion(+), 1 deletion(-)
2020

2121
diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi
22-
index 900c4c93f..d874edd8f 100644
22+
index 5a3bb5908..0f2196070 100644
2323
--- a/mypy/typeshed/stdlib/builtins.pyi
2424
+++ b/mypy/typeshed/stdlib/builtins.pyi
25-
@@ -1782,7 +1782,7 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
25+
@@ -1835,7 +1835,7 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
2626
# without creating many false-positive errors (see #7578).
2727
# Instead, we special-case the most common examples of this: bool and literal integers.
2828
@overload
@@ -32,5 +32,5 @@ index 900c4c93f..d874edd8f 100644
3232
def sum(iterable: Iterable[_SupportsSumNoDefaultT], /) -> _SupportsSumNoDefaultT | Literal[0]: ...
3333
@overload
3434
--
35-
2.49.0
35+
2.52.0
3636

0 commit comments

Comments
 (0)