Skip to content

Commit 4215dfd

Browse files
cdce8phauntsaninja
andauthored
Sync typeshed (#20729)
Source commit: python/typeshed@637ece0 --------- Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
1 parent 94bf64b commit 4215dfd

38 files changed

+365
-133
lines changed
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+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
From ae45edc46f2ca9c939e317648b44ed3372487798 Mon Sep 17 00:00:00 2001
2+
From: Shantanu Jain <hauntsaninja@gmail.com>
3+
Date: Sun, 22 Feb 2026 20:37:48 -0800
4+
Subject: [PATCH] Temporarily revert contextlib deprecation
5+
6+
---
7+
mypy/typeshed/stdlib/contextlib.pyi | 15 +--------------
8+
1 file changed, 1 insertion(+), 14 deletions(-)
9+
10+
diff --git a/mypy/typeshed/stdlib/contextlib.pyi b/mypy/typeshed/stdlib/contextlib.pyi
11+
index 8d5902c46..221102ee2 100644
12+
--- a/mypy/typeshed/stdlib/contextlib.pyi
13+
+++ b/mypy/typeshed/stdlib/contextlib.pyi
14+
@@ -5,7 +5,7 @@ from abc import ABC, abstractmethod
15+
from collections.abc import AsyncGenerator, AsyncIterator, Awaitable, Callable, Generator, Iterator
16+
from types import TracebackType
17+
from typing import Any, Generic, Protocol, TypeVar, overload, runtime_checkable, type_check_only
18+
-from typing_extensions import ParamSpec, Self, TypeAlias, deprecated
19+
+from typing_extensions import ParamSpec, Self, TypeAlias
20+
21+
__all__ = [
22+
"contextmanager",
23+
@@ -86,12 +86,6 @@ class _GeneratorContextManager(
24+
self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
25+
) -> bool | None: ...
26+
27+
-@overload
28+
-def contextmanager(func: Callable[_P, Generator[_T_co, None, object]]) -> Callable[_P, _GeneratorContextManager[_T_co]]: ...
29+
-@overload
30+
-@deprecated(
31+
- "Annotating the return type as `-> Iterator[Foo]` with `@contextmanager` is deprecated. Use `-> Generator[Foo]` instead."
32+
-)
33+
def contextmanager(func: Callable[_P, Iterator[_T_co]]) -> Callable[_P, _GeneratorContextManager[_T_co]]: ...
34+
35+
if sys.version_info >= (3, 10):
36+
@@ -118,13 +112,6 @@ else:
37+
self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
38+
) -> bool | None: ...
39+
40+
-@overload
41+
-def asynccontextmanager(func: Callable[_P, AsyncGenerator[_T_co]]) -> Callable[_P, _AsyncGeneratorContextManager[_T_co]]: ...
42+
-@overload
43+
-@deprecated(
44+
- "Annotating the return type as `-> AsyncIterator[Foo]` with `@asynccontextmanager` is deprecated. "
45+
- "Use `-> AsyncGenerator[Foo]` instead."
46+
-)
47+
def asynccontextmanager(func: Callable[_P, AsyncIterator[_T_co]]) -> Callable[_P, _AsyncGeneratorContextManager[_T_co]]: ...
48+
@type_check_only
49+
class _SupportsClose(Protocol):
50+
--
51+
2.53.0
52+

mypy/typeshed/stdlib/VERSIONS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ py_compile: 3.0-
253253
pyclbr: 3.0-
254254
pydoc: 3.0-
255255
pydoc_data: 3.0-
256+
pydoc_data.module_docs: 3.13-
256257
pyexpat: 3.0-
257258
queue: 3.0-
258259
quopri: 3.0-

mypy/typeshed/stdlib/_collections_abc.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
from abc import abstractmethod
33
from types import MappingProxyType
4-
from typing import ( # noqa: Y022,Y038,UP035,Y057
4+
from typing import ( # noqa: Y022,Y038,UP035,Y057,RUF100
55
AbstractSet as Set,
66
AsyncGenerator as AsyncGenerator,
77
AsyncIterable as AsyncIterable,

mypy/typeshed/stdlib/_ctypes.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ from abc import abstractmethod
66
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
77
from ctypes import CDLL, ArgumentError as ArgumentError, c_void_p
88
from types import GenericAlias
9-
from typing import Any, ClassVar, Final, Generic, Literal, TypeVar, final, overload, type_check_only
9+
from typing import Any, ClassVar, Final, Generic, Literal, SupportsIndex, TypeVar, final, overload, type_check_only
1010
from typing_extensions import Self, TypeAlias
1111

1212
_T = TypeVar("_T")
@@ -134,7 +134,7 @@ class _Pointer(_PointerLike, _CData, Generic[_CT], metaclass=_PyCPointerType):
134134
@overload
135135
def __getitem__(self, key: int, /) -> Any: ...
136136
@overload
137-
def __getitem__(self, key: slice, /) -> list[Any]: ...
137+
def __getitem__(self, key: slice[SupportsIndex | None], /) -> list[Any]: ...
138138
def __setitem__(self, key: int, value: Any, /) -> None: ...
139139

140140
if sys.version_info < (3, 14):
@@ -338,11 +338,11 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType):
338338
@overload
339339
def __getitem__(self, key: int, /) -> Any: ...
340340
@overload
341-
def __getitem__(self, key: slice, /) -> list[Any]: ...
341+
def __getitem__(self, key: slice[SupportsIndex | None], /) -> list[Any]: ...
342342
@overload
343343
def __setitem__(self, key: int, value: Any, /) -> None: ...
344344
@overload
345-
def __setitem__(self, key: slice, value: Iterable[Any], /) -> None: ...
345+
def __setitem__(self, key: slice[SupportsIndex | None], value: Iterable[Any], /) -> None: ...
346346
def __iter__(self) -> Iterator[Any]: ...
347347
# Can't inherit from Sized because the metaclass conflict between
348348
# Sized and _CData prevents using _CDataMeta.

mypy/typeshed/stdlib/_operator.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,20 @@ def concat(a: Sequence[_T], b: Sequence[_T], /) -> Sequence[_T]: ...
8080
def contains(a: Container[object], b: object, /) -> bool: ...
8181
def countOf(a: Iterable[object], b: object, /) -> int: ...
8282
@overload
83-
def delitem(a: MutableSequence[Any], b: SupportsIndex, /) -> None: ...
83+
def delitem(a: MutableSequence[Any], b: int, /) -> None: ...
8484
@overload
85-
def delitem(a: MutableSequence[Any], b: slice, /) -> None: ...
85+
def delitem(a: MutableSequence[Any], b: slice[int | None], /) -> None: ...
8686
@overload
8787
def delitem(a: MutableMapping[_K, Any], b: _K, /) -> None: ...
8888
@overload
89-
def getitem(a: Sequence[_T], b: slice, /) -> Sequence[_T]: ...
89+
def getitem(a: Sequence[_T], b: slice[int | None], /) -> Sequence[_T]: ...
9090
@overload
9191
def getitem(a: SupportsGetItem[_K, _V], b: _K, /) -> _V: ...
9292
def indexOf(a: Iterable[_T], b: _T, /) -> int: ...
9393
@overload
94-
def setitem(a: MutableSequence[_T], b: SupportsIndex, c: _T, /) -> None: ...
94+
def setitem(a: MutableSequence[_T], b: int, c: _T, /) -> None: ...
9595
@overload
96-
def setitem(a: MutableSequence[_T], b: slice, c: Sequence[_T], /) -> None: ...
96+
def setitem(a: MutableSequence[_T], b: slice[int | None], c: Sequence[_T], /) -> None: ...
9797
@overload
9898
def setitem(a: MutableMapping[_K, _V], b: _K, c: _V, /) -> None: ...
9999
def length_hint(obj: object, default: int = 0, /) -> int: ...

mypy/typeshed/stdlib/_socket.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ if sys.platform != "linux":
587587

588588
has_ipv6: bool
589589

590-
if sys.platform != "darwin" and sys.platform != "linux":
590+
if sys.platform != "darwin":
591591
BDADDR_ANY: Final = "00:00:00:00:00:00"
592592
BDADDR_LOCAL: Final = "00:00:00:FF:FF:FF"
593593

@@ -660,16 +660,16 @@ if sys.platform == "darwin":
660660
PF_SYSTEM: Final[int]
661661
SYSPROTO_CONTROL: Final[int]
662662

663-
if sys.platform != "darwin" and sys.platform != "linux":
663+
if sys.platform != "darwin":
664664
AF_BLUETOOTH: Final[int]
665665

666-
if sys.platform != "win32" and sys.platform != "darwin" and sys.platform != "linux":
666+
if sys.platform != "win32" and sys.platform != "darwin":
667667
# Linux and some BSD support is explicit in the docs
668668
# Windows and macOS do not support in practice
669669
BTPROTO_HCI: Final[int]
670670
BTPROTO_L2CAP: Final[int]
671671
BTPROTO_SCO: Final[int] # not in FreeBSD
672-
if sys.platform != "darwin" and sys.platform != "linux":
672+
if sys.platform != "darwin":
673673
BTPROTO_RFCOMM: Final[int]
674674

675675
if sys.platform == "linux":

mypy/typeshed/stdlib/_thread.pyi

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from collections.abc import Callable
55
from threading import Thread
66
from types import TracebackType
77
from typing import Any, Final, NoReturn, final, overload
8-
from typing_extensions import TypeVarTuple, Unpack, disjoint_base
8+
from typing_extensions import TypeVarTuple, Unpack, deprecated, disjoint_base
99

1010
_Ts = TypeVarTuple("_Ts")
1111

@@ -38,9 +38,12 @@ if sys.version_info >= (3, 13):
3838
def acquire(self, blocking: bool = True, timeout: float = -1) -> bool: ...
3939
def release(self) -> None: ...
4040
def locked(self) -> bool: ...
41-
def acquire_lock(self, blocking: bool = True, timeout: float = -1) -> bool: ...
42-
def release_lock(self) -> None: ...
43-
def locked_lock(self) -> bool: ...
41+
@deprecated("Obsolete synonym. Use `acquire()` instead.")
42+
def acquire_lock(self, blocking: bool = True, timeout: float = -1) -> bool: ... # undocumented
43+
@deprecated("Obsolete synonym. Use `release()` instead.")
44+
def release_lock(self) -> None: ... # undocumented
45+
@deprecated("Obsolete synonym. Use `locked()` instead.")
46+
def locked_lock(self) -> bool: ... # undocumented
4447
def __enter__(self) -> bool: ...
4548
def __exit__(
4649
self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
@@ -53,9 +56,12 @@ else:
5356
def acquire(self, blocking: bool = True, timeout: float = -1) -> bool: ...
5457
def release(self) -> None: ...
5558
def locked(self) -> bool: ...
56-
def acquire_lock(self, blocking: bool = True, timeout: float = -1) -> bool: ...
57-
def release_lock(self) -> None: ...
58-
def locked_lock(self) -> bool: ...
59+
@deprecated("Obsolete synonym. Use `acquire()` instead.")
60+
def acquire_lock(self, blocking: bool = True, timeout: float = -1) -> bool: ... # undocumented
61+
@deprecated("Obsolete synonym. Use `release()` instead.")
62+
def release_lock(self) -> None: ... # undocumented
63+
@deprecated("Obsolete synonym. Use `locked()` instead.")
64+
def locked_lock(self) -> bool: ... # undocumented
5965
def __enter__(self) -> bool: ...
6066
def __exit__(
6167
self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
@@ -65,12 +71,12 @@ else:
6571
def start_new_thread(function: Callable[[Unpack[_Ts]], object], args: tuple[Unpack[_Ts]], /) -> int: ...
6672
@overload
6773
def start_new_thread(function: Callable[..., object], args: tuple[Any, ...], kwargs: dict[str, Any], /) -> int: ...
68-
69-
# Obsolete synonym for start_new_thread()
7074
@overload
71-
def start_new(function: Callable[[Unpack[_Ts]], object], args: tuple[Unpack[_Ts]], /) -> int: ...
75+
@deprecated("Obsolete synonym. Use `start_new_thread()` instead.")
76+
def start_new(function: Callable[[Unpack[_Ts]], object], args: tuple[Unpack[_Ts]], /) -> int: ... # undocumented
7277
@overload
73-
def start_new(function: Callable[..., object], args: tuple[Any, ...], kwargs: dict[str, Any], /) -> int: ...
78+
@deprecated("Obsolete synonym. Use `start_new_thread()` instead.")
79+
def start_new(function: Callable[..., object], args: tuple[Any, ...], kwargs: dict[str, Any], /) -> int: ... # undocumented
7480

7581
if sys.version_info >= (3, 10):
7682
def interrupt_main(signum: signal.Signals = signal.SIGINT, /) -> None: ...
@@ -79,9 +85,11 @@ else:
7985
def interrupt_main() -> None: ...
8086

8187
def exit() -> NoReturn: ...
82-
def exit_thread() -> NoReturn: ... # Obsolete synonym for exit()
88+
@deprecated("Obsolete synonym. Use `exit()` instead.")
89+
def exit_thread() -> NoReturn: ... # undocumented
8390
def allocate_lock() -> LockType: ...
84-
def allocate() -> LockType: ... # Obsolete synonym for allocate_lock()
91+
@deprecated("Obsolete synonym. Use `allocate_lock()` instead.")
92+
def allocate() -> LockType: ... # undocumented
8593
def get_ident() -> int: ...
8694
def stack_size(size: int = 0, /) -> int: ...
8795

0 commit comments

Comments
 (0)