Skip to content

Commit 86c00d3

Browse files
committed
Merge branch 'master' into stubtest-private-typecheckonly
2 parents 565e42f + 69a0925 commit 86c00d3

193 files changed

Lines changed: 15095 additions & 5468 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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,20 @@ jobs:
106106
os: ubuntu-24.04-arm
107107
toxenv: py
108108
tox_extra_args: "-n 4 --mypy-num-workers=4 mypy/test/testcheck.py"
109+
dev_ast_serialize: true
109110
- name: Parallel tests with py314-ubuntu, mypyc-compiled
110111
python: '3.14'
111112
os: ubuntu-24.04-arm
112113
toxenv: py
113114
tox_extra_args: "-n 4 --mypy-num-workers=4 mypy/test/testcheck.py"
114115
test_mypyc: true
116+
dev_ast_serialize: true
115117
- name: Parallel tests with py314-windows-64, interpreted
116118
python: '3.14'
117119
os: windows-latest
118120
toxenv: py
119121
tox_extra_args: "-n 2 --mypy-num-workers=2 mypy/test/testcheck.py -k 'incremental or modules or classes'"
122+
dev_ast_serialize: true
120123

121124
- name: Type check our own code (py310-ubuntu)
122125
python: '3.10'
@@ -139,6 +142,7 @@ jobs:
139142
timeout-minutes: 60
140143
env:
141144
TOX_SKIP_MISSING_INTERPRETERS: False
145+
VIRTUALENV_SYSTEM_SITE_PACKAGES: ${{ matrix.dev_ast_serialize && 1 || 0 }}
142146
# Rich (pip) -- Disable color for windows + pytest
143147
FORCE_COLOR: ${{ !(startsWith(matrix.os, 'windows-') && startsWith(matrix.toxenv, 'py')) && 1 || 0 }}
144148
# Tox
@@ -213,6 +217,11 @@ jobs:
213217
pip install -r test-requirements.txt
214218
CC=clang MYPYC_OPT_LEVEL=0 MYPY_USE_MYPYC=1 pip install -e .
215219
220+
# To speed-up process until ast_serialize is on PyPI.
221+
- name: Install pinned ast-serialize
222+
if: ${{ matrix.dev_ast_serialize }}
223+
run: pip install ast-serialize@git+https://github.com/mypyc/ast_serialize.git@052c5bfa3b2a5bf07c0b163ccbe2c5ccbfae9ac5
224+
216225
- name: Setup tox environment
217226
run: |
218227
tox run -e ${{ matrix.toxenv }} --notest

CHANGELOG.md

Lines changed: 4291 additions & 4226 deletions
Large diffs are not rendered by default.

docs/source/command_line.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,18 @@ of the above sections.
631631
# Type of "x" is "str" here.
632632
...
633633
634+
Function arguments are special, changing their type within function body
635+
is allowed even if they are annotated, but that annotation is used to infer
636+
types of r.h.s. of all subsequent assignments. Such middle-ground semantics
637+
provides good balance for majority of common use cases. For example:
638+
639+
.. code-block:: python
640+
641+
def process(values: list[float]) -> None:
642+
if not values:
643+
values = [0, 0, 0]
644+
reveal_type(values) # Revealed type is list[float]
645+
634646
Note: We are planning to turn this flag on by default in a future mypy
635647
release, along with :option:`--local-partial-types <mypy --local-partial-types>`.
636648
The feature is still experimental, and the semantics may still change.

docs/source/common_issues.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ error:
148148
The second line is now fine, since the ignore comment causes the name
149149
``frobnicate`` to get an implicit ``Any`` type.
150150

151+
The type ignore comment must be at the start of the comments on a line.
152+
This type ignore will not take effect:
153+
154+
.. code-block:: python
155+
156+
import frobnicate #example other comment # type: ignore
157+
frobnicate.start()
158+
151159
.. note::
152160

153161
You can use the form ``# type: ignore[<code>]`` to only ignore

docs/source/config_file.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,18 @@ section of the command line docs.
748748
# Type of "x" is "str" here.
749749
...
750750
751+
Function arguments are special, changing their type within function body
752+
is allowed even if they are annotated, but that annotation is used to infer
753+
types of r.h.s. of all subsequent assignments. Such middle-ground semantics
754+
provides good balance for majority of common use cases. For example:
755+
756+
.. code-block:: python
757+
758+
def process(values: list[float]) -> None:
759+
if not values:
760+
values = [0, 0, 0]
761+
reveal_type(values) # Revealed type is list[float]
762+
751763
Note: We are planning to turn this flag on by default in a future mypy
752764
release, along with :confval:`local_partial_types`.
753765

docs/source/stubs.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ For example:
126126
"""Some docstring"""
127127
pass
128128
129-
# Error: Incompatible default for argument "foo" (default has
130-
# type "ellipsis", argument has type "list[str]")
129+
# Error: Incompatible default for parameter "foo" (default has
130+
# type "ellipsis", parameter has type "list[str]")
131131
def not_ok(self, foo: list[str] = ...) -> None:
132132
print(foo)

misc/sync-typeshed.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ def main() -> None:
143143
action="store_true",
144144
help="Whether to make a PR with the changes (default to no)",
145145
)
146+
parser.add_argument("--no-branch", action="store_true", help="Skip creating a new branch")
146147
args = parser.parse_args()
147148

148149
check_state()
@@ -158,7 +159,8 @@ def main() -> None:
158159
shutil.copytree(typeshed_patches, tmp_patches)
159160

160161
branch_name = "mypybot/sync-typeshed"
161-
subprocess.run(["git", "checkout", "-B", branch_name, "origin/master"], check=True)
162+
if not args.no_branch:
163+
subprocess.run(["git", "checkout", "-B", branch_name, "origin/master"], check=True)
162164

163165
# Copy the stashed patches back
164166
shutil.rmtree(typeshed_patches, ignore_errors=True)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
From 5c922a2484f2e18c7f901e62bb499b6414cf1090 Mon Sep 17 00:00:00 2001
2+
From: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
3+
Date: Wed, 18 Feb 2026 13:11:02 +0100
4+
Subject: [PATCH] Adjust stubs to fix mypy lookup error due to circular
5+
dependencies in stubs
6+
7+
---
8+
mypy/typeshed/stdlib/time.pyi | 6 +++---
9+
1 file changed, 3 insertions(+), 3 deletions(-)
10+
11+
diff --git a/mypy/typeshed/stdlib/time.pyi b/mypy/typeshed/stdlib/time.pyi
12+
index 64a009318..d0853792b 100644
13+
--- a/mypy/typeshed/stdlib/time.pyi
14+
+++ b/mypy/typeshed/stdlib/time.pyi
15+
@@ -1,16 +1,16 @@
16+
import sys
17+
from _typeshed import structseq
18+
-from typing import Any, Final, Literal, Protocol, SupportsFloat, SupportsIndex, final, type_check_only
19+
+from typing import Any, Final, Literal, Protocol, SupportsFloat, SupportsIndex, Union, final, type_check_only
20+
from typing_extensions import TypeAlias
21+
22+
_TimeTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int, int]
23+
24+
if sys.version_info >= (3, 15):
25+
# anticipate on https://github.com/python/cpython/pull/139224
26+
- _SupportsFloatOrIndex: TypeAlias = SupportsFloat | SupportsIndex
27+
+ _SupportsFloatOrIndex: TypeAlias = Union[SupportsFloat, SupportsIndex]
28+
else:
29+
# before, time functions only accept (subclass of) float, *not* SupportsFloat
30+
- _SupportsFloatOrIndex: TypeAlias = float | SupportsIndex
31+
+ _SupportsFloatOrIndex: TypeAlias = Union[float, SupportsIndex]
32+
33+
altzone: int
34+
daylight: int
35+
--
36+
2.53.0
37+

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
From ed11d7e0204868ef1a43c17ed950372b1d78f497 Mon Sep 17 00:00:00 2001
1+
From b3021cdc4b4c2cf547c5bc2d1d21a5a00ffea001 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)
55

66
---
7-
mypy/typeshed/stdlib/builtins.pyi | 100 +-----------------------------
8-
1 file changed, 1 insertion(+), 99 deletions(-)
7+
mypy/typeshed/stdlib/builtins.pyi | 98 -------------------------------
8+
1 file changed, 98 deletions(-)
99

1010
diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi
11-
index 693dd0b77..8acdeadff 100644
11+
index efc51fe25..8600a372b 100644
1212
--- a/mypy/typeshed/stdlib/builtins.pyi
1313
+++ b/mypy/typeshed/stdlib/builtins.pyi
1414
@@ -64,7 +64,6 @@ from typing import ( # noqa: Y022,UP035
@@ -163,10 +163,9 @@ index 693dd0b77..8acdeadff 100644
163163
def __eq__(self, value: object, /) -> bool: ...
164164
def __ge__(self, value: str, /) -> bool: ...
165165
- @overload
166-
- def __getitem__(self: LiteralString, key: SupportsIndex | slice, /) -> LiteralString: ...
166+
- def __getitem__(self: LiteralString, key: SupportsIndex | slice[SupportsIndex | None], /) -> LiteralString: ...
167167
- @overload
168-
- def __getitem__(self, key: SupportsIndex | slice, /) -> str: ... # type: ignore[misc]
169-
+ def __getitem__(self, key: SupportsIndex | slice, /) -> str: ...
168+
def __getitem__(self, key: SupportsIndex | slice[SupportsIndex | None], /) -> str: ... # type: ignore[misc]
170169
def __gt__(self, value: str, /) -> bool: ...
171170
def __hash__(self) -> int: ...
172171
- @overload
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
From 274a77fe74d961e9885036ed31e5ed46f8d91daa Mon Sep 17 00:00:00 2001
2+
From: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
3+
Date: Mon, 23 Feb 2026 12:00:18 +0100
4+
Subject: [PATCH] Revert Use contravariant type variable in Container
5+
6+
---
7+
mypy/typeshed/stdlib/typing.pyi | 9 +++------
8+
1 file changed, 3 insertions(+), 6 deletions(-)
9+
10+
diff --git a/mypy/typeshed/stdlib/typing.pyi b/mypy/typeshed/stdlib/typing.pyi
11+
index 83e114aac..e9f67877c 100644
12+
--- a/mypy/typeshed/stdlib/typing.pyi
13+
+++ b/mypy/typeshed/stdlib/typing.pyi
14+
@@ -640,17 +640,14 @@ class AsyncGenerator(AsyncIterator[_YieldT_co], Protocol[_YieldT_co, _SendT_cont
15+
) -> Coroutine[Any, Any, _YieldT_co]: ...
16+
def aclose(self) -> Coroutine[Any, Any, None]: ...
17+
18+
-_ContainerT_contra = TypeVar("_ContainerT_contra", contravariant=True, default=Any)
19+
-
20+
@runtime_checkable
21+
-class Container(Protocol[_ContainerT_contra]):
22+
+class Container(Protocol[_T_co]):
23+
# This is generic more on vibes than anything else
24+
@abstractmethod
25+
- def __contains__(self, x: _ContainerT_contra, /) -> bool: ...
26+
+ def __contains__(self, x: object, /) -> bool: ...
27+
28+
@runtime_checkable
29+
-class Collection(Iterable[_T_co], Container[Any], Protocol[_T_co]):
30+
- # Note: need to use Container[Any] instead of Container[_T_co] to ensure covariance.
31+
+class Collection(Iterable[_T_co], Container[_T_co], Protocol[_T_co]):
32+
# Implement Sized (but don't have it as a base class).
33+
@abstractmethod
34+
def __len__(self) -> int: ...
35+
--
36+
2.53.0
37+

0 commit comments

Comments
 (0)