Skip to content

Commit 1c48286

Browse files
cdce8phauntsaninjaAlexWaygood
authored
Sync typeshed (#19585)
Source commit: python/typeshed@e16c23d --------- Co-authored-by: Shantanu <[email protected]> Co-authored-by: AlexWaygood <[email protected]>
1 parent 5051a48 commit 1c48286

File tree

120 files changed

+1419
-974
lines changed

Some content is hidden

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

120 files changed

+1419
-974
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 05f351f6a37fe8b73c698c348bf6aa5108363049 Mon Sep 17 00:00:00 2001
1+
From 84a9d586544a0408d4654f57f83a93cb048070fb Mon Sep 17 00:00:00 2001
22
From: Marc Mueller <[email protected]>
33
Date: Sat, 15 Feb 2025 20:11:06 +0100
44
Subject: [PATCH] Partially revert Clean up argparse hacks
@@ -8,15 +8,15 @@ 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 95ad6c7da..79e6cfde1 100644
11+
index b9fa31139..3c3ba116a 100644
1212
--- a/mypy/typeshed/stdlib/argparse.pyi
1313
+++ b/mypy/typeshed/stdlib/argparse.pyi
1414
@@ -2,7 +2,7 @@ import sys
1515
from _typeshed import SupportsWrite, sentinel
1616
from collections.abc import Callable, Generator, Iterable, Sequence
1717
from re import Pattern
18-
-from typing import IO, Any, ClassVar, Final, Generic, NoReturn, Protocol, TypeVar, overload
19-
+from typing import IO, Any, ClassVar, Final, Generic, NewType, NoReturn, Protocol, TypeVar, overload
18+
-from typing import IO, Any, ClassVar, Final, Generic, NoReturn, Protocol, TypeVar, overload, type_check_only
19+
+from typing import IO, Any, ClassVar, Final, Generic, NewType, NoReturn, Protocol, TypeVar, overload, type_check_only
2020
from typing_extensions import Self, TypeAlias, deprecated
2121

2222
__all__ = [
@@ -41,5 +41,5 @@ index 95ad6c7da..79e6cfde1 100644
4141
default: Any = ...,
4242
type: _ActionType = ...,
4343
--
44-
2.49.0
44+
2.50.1
4545

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 363d69b366695fea117631d30c348e36b9a5a99d Mon Sep 17 00:00:00 2001
1+
From c217544146d36899d50e828d627652a0d8f63bb7 Mon Sep 17 00:00:00 2001
22
From: Marc Mueller <[email protected]>
33
Date: Sat, 21 Dec 2024 22:36:38 +0100
44
Subject: [PATCH] Revert Remove redundant inheritances from Iterator in
@@ -15,7 +15,7 @@ Subject: [PATCH] Revert Remove redundant inheritances from Iterator in
1515
7 files changed, 34 insertions(+), 34 deletions(-)
1616

1717
diff --git a/mypy/typeshed/stdlib/_asyncio.pyi b/mypy/typeshed/stdlib/_asyncio.pyi
18-
index 4544680cc..19a2d12d8 100644
18+
index ed56f33af..5253e967e 100644
1919
--- a/mypy/typeshed/stdlib/_asyncio.pyi
2020
+++ b/mypy/typeshed/stdlib/_asyncio.pyi
2121
@@ -1,6 +1,6 @@
@@ -36,10 +36,10 @@ index 4544680cc..19a2d12d8 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 ea77a730f..900c4c93f 100644
39+
index 0575be3c8..d9be595fe 100644
4040
--- a/mypy/typeshed/stdlib/builtins.pyi
4141
+++ b/mypy/typeshed/stdlib/builtins.pyi
42-
@@ -1170,7 +1170,7 @@ class frozenset(AbstractSet[_T_co]):
42+
@@ -1186,7 +1186,7 @@ class frozenset(AbstractSet[_T_co]):
4343
def __hash__(self) -> int: ...
4444
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
4545

@@ -48,7 +48,7 @@ index ea77a730f..900c4c93f 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-
@@ -1366,7 +1366,7 @@ else:
51+
@@ -1380,7 +1380,7 @@ else:
5252

5353
exit: _sitebuiltins.Quitter
5454

@@ -57,7 +57,7 @@ index ea77a730f..900c4c93f 100644
5757
@overload
5858
def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ...
5959
@overload
60-
@@ -1431,7 +1431,7 @@ license: _sitebuiltins._Printer
60+
@@ -1444,7 +1444,7 @@ license: _sitebuiltins._Printer
6161

6262
def locals() -> dict[str, Any]: ...
6363

@@ -66,7 +66,7 @@ index ea77a730f..900c4c93f 100644
6666
# 3.14 adds `strict` argument.
6767
if sys.version_info >= (3, 14):
6868
@overload
69-
@@ -1734,7 +1734,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex
69+
@@ -1750,7 +1750,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex
7070

7171
quit: _sitebuiltins.Quitter
7272

@@ -75,7 +75,7 @@ index ea77a730f..900c4c93f 100644
7575
@overload
7676
def __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T]: ... # type: ignore[misc]
7777
@overload
78-
@@ -1795,7 +1795,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
78+
@@ -1814,7 +1814,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
7979
@overload
8080
def vars(object: Any = ..., /) -> dict[str, Any]: ...
8181

@@ -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 948b39ea1..1d5f9cf00 100644
110+
index 910d63814..eb942bc55 100644
111111
--- a/mypy/typeshed/stdlib/fileinput.pyi
112112
+++ b/mypy/typeshed/stdlib/fileinput.pyi
113113
@@ -1,8 +1,8 @@
@@ -116,12 +116,12 @@ index 948b39ea1..1d5f9cf00 100644
116116
-from collections.abc import Callable, Iterable
117117
+from collections.abc import Callable, Iterable, Iterator
118118
from types import GenericAlias, TracebackType
119-
-from typing import IO, Any, AnyStr, Generic, Literal, Protocol, overload
120-
+from typing import IO, Any, AnyStr, Literal, Protocol, overload
119+
-from typing import IO, Any, AnyStr, Generic, Literal, Protocol, overload, type_check_only
120+
+from typing import IO, Any, AnyStr, Literal, Protocol, overload, type_check_only
121121
from typing_extensions import Self, TypeAlias
122122

123123
__all__ = [
124-
@@ -104,7 +104,7 @@ def fileno() -> int: ...
124+
@@ -105,7 +105,7 @@ def fileno() -> int: ...
125125
def isfirstline() -> bool: ...
126126
def isstdin() -> bool: ...
127127

@@ -307,10 +307,10 @@ index b79f9e773..f276372d0 100644
307307
def __iter__(self) -> Self: ...
308308
def next(self, timeout: float | None = None) -> _T: ...
309309
diff --git a/mypy/typeshed/stdlib/sqlite3/__init__.pyi b/mypy/typeshed/stdlib/sqlite3/__init__.pyi
310-
index 5d3c2330b..ab783dbde 100644
310+
index bcfea3a13..5a659deac 100644
311311
--- a/mypy/typeshed/stdlib/sqlite3/__init__.pyi
312312
+++ b/mypy/typeshed/stdlib/sqlite3/__init__.pyi
313-
@@ -399,7 +399,7 @@ class Connection:
313+
@@ -405,7 +405,7 @@ class Connection:
314314
self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None, /
315315
) -> Literal[False]: ...
316316

@@ -320,5 +320,5 @@ index 5d3c2330b..ab783dbde 100644
320320
@property
321321
def connection(self) -> Connection: ...
322322
--
323-
2.49.0
323+
2.50.1
324324

mypy/typeshed/stdlib/VERSIONS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ compileall: 3.0-
124124
compression: 3.14-
125125
concurrent: 3.2-
126126
concurrent.futures.interpreter: 3.14-
127+
concurrent.interpreters: 3.14-
127128
configparser: 3.0-
128129
contextlib: 3.0-
129130
contextvars: 3.7-

mypy/typeshed/stdlib/_compression.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
from _typeshed import Incomplete, WriteableBuffer
44
from collections.abc import Callable
55
from io import DEFAULT_BUFFER_SIZE, BufferedIOBase, RawIOBase
6-
from typing import Any, Protocol
6+
from typing import Any, Protocol, type_check_only
77

88
BUFFER_SIZE = DEFAULT_BUFFER_SIZE
99

10+
@type_check_only
1011
class _Reader(Protocol):
1112
def read(self, n: int, /) -> bytes: ...
1213
def seekable(self) -> bool: ...

mypy/typeshed/stdlib/_ctypes.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ class _SimpleCData(_CData, Generic[_T], metaclass=_PyCSimpleType):
103103
def __init__(self, value: _T = ...) -> None: ... # pyright: ignore[reportInvalidTypeVarUse]
104104
def __ctypes_from_outparam__(self, /) -> _T: ... # type: ignore[override]
105105

106+
@type_check_only
106107
class _CanCastTo(_CData): ...
108+
109+
@type_check_only
107110
class _PointerLike(_CanCastTo): ...
108111

109112
# This type is not exposed. It calls itself _ctypes.PyCPointerType.
@@ -114,7 +117,7 @@ class _PyCPointerType(_CTypeBaseType):
114117
def from_buffer_copy(self: type[_typeshed.Self], buffer: ReadableBuffer, offset: int = 0, /) -> _typeshed.Self: ...
115118
def from_param(self: type[_typeshed.Self], value: Any, /) -> _typeshed.Self | _CArgObject: ...
116119
def in_dll(self: type[_typeshed.Self], dll: CDLL, name: str, /) -> _typeshed.Self: ...
117-
def set_type(self, type: Any, /) -> None: ...
120+
def set_type(self, type: _CTypeBaseType, /) -> None: ...
118121
if sys.version_info < (3, 13):
119122
# Inherited from CType_Type starting on 3.13
120123
def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]

mypy/typeshed/stdlib/_gdbm.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
from _typeshed import ReadOnlyBuffer, StrOrBytesPath
33
from types import TracebackType
4-
from typing import TypeVar, overload
4+
from typing import TypeVar, overload, type_check_only
55
from typing_extensions import Self, TypeAlias
66

77
if sys.platform != "win32":
@@ -13,6 +13,7 @@ if sys.platform != "win32":
1313

1414
class error(OSError): ...
1515
# Actual typename gdbm, not exposed by the implementation
16+
@type_check_only
1617
class _gdbm:
1718
def firstkey(self) -> bytes | None: ...
1819
def nextkey(self, key: _KeyType) -> bytes | None: ...

mypy/typeshed/stdlib/_heapq.pyi

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import sys
2-
from typing import Any, Final, TypeVar
3-
4-
_T = TypeVar("_T") # list items must be comparable
2+
from _typeshed import SupportsRichComparisonT as _T # All type variable use in this module requires comparability.
3+
from typing import Final
54

65
__about__: Final[str]
76

8-
def heapify(heap: list[Any], /) -> None: ... # list items must be comparable
7+
def heapify(heap: list[_T], /) -> None: ...
98
def heappop(heap: list[_T], /) -> _T: ...
109
def heappush(heap: list[_T], item: _T, /) -> None: ...
1110
def heappushpop(heap: list[_T], item: _T, /) -> _T: ...
1211
def heapreplace(heap: list[_T], item: _T, /) -> _T: ...
1312

1413
if sys.version_info >= (3, 14):
15-
def heapify_max(heap: list[Any], /) -> None: ... # list items must be comparable
14+
def heapify_max(heap: list[_T], /) -> None: ...
1615
def heappop_max(heap: list[_T], /) -> _T: ...
1716
def heappush_max(heap: list[_T], item: _T, /) -> None: ...
1817
def heappushpop_max(heap: list[_T], item: _T, /) -> _T: ...

mypy/typeshed/stdlib/_interpreters.pyi

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import types
22
from collections.abc import Callable
3-
from typing import Any, Final, Literal, SupportsIndex
3+
from typing import Any, Final, Literal, SupportsIndex, TypeVar
44
from typing_extensions import TypeAlias
55

6+
_R = TypeVar("_R")
7+
68
_Configs: TypeAlias = Literal["default", "isolated", "legacy", "empty", ""]
79
_SharedDict: TypeAlias = dict[str, Any] # many objects can be shared
810

@@ -21,7 +23,7 @@ def get_current() -> tuple[int, int]: ...
2123
def get_main() -> tuple[int, int]: ...
2224
def is_running(id: SupportsIndex, *, restrict: bool = False) -> bool: ...
2325
def get_config(id: SupportsIndex, *, restrict: bool = False) -> types.SimpleNamespace: ...
24-
def whence(id: SupportsIndex) -> int: ...
26+
def whence(id: SupportsIndex) -> _Whence: ...
2527
def exec(
2628
id: SupportsIndex,
2729
code: str | types.CodeType | Callable[[], object],
@@ -31,12 +33,12 @@ def exec(
3133
) -> None | types.SimpleNamespace: ...
3234
def call(
3335
id: SupportsIndex,
34-
callable: Callable[..., object],
36+
callable: Callable[..., _R],
3537
args: tuple[object, ...] | None = None,
3638
kwargs: dict[str, object] | None = None,
3739
*,
3840
restrict: bool = False,
39-
) -> object: ...
41+
) -> tuple[_R, types.SimpleNamespace]: ...
4042
def run_string(
4143
id: SupportsIndex,
4244
script: str | types.CodeType | Callable[[], object],
@@ -53,6 +55,7 @@ def decref(id: SupportsIndex, *, restrict: bool = False) -> None: ...
5355
def is_shareable(obj: object) -> bool: ...
5456
def capture_exception(exc: BaseException | None = None) -> types.SimpleNamespace: ...
5557

58+
_Whence: TypeAlias = Literal[0, 1, 2, 3, 4, 5]
5659
WHENCE_UNKNOWN: Final = 0
5760
WHENCE_RUNTIME: Final = 1
5861
WHENCE_LEGACY_CAPI: Final = 2

mypy/typeshed/stdlib/_io.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class BytesIO(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore[misc]
8888
def readlines(self, size: int | None = None, /) -> list[bytes]: ...
8989
def seek(self, pos: int, whence: int = 0, /) -> int: ...
9090

91+
@type_check_only
9192
class _BufferedReaderStream(Protocol):
9293
def read(self, n: int = ..., /) -> bytes: ...
9394
# Optional: def readall(self) -> bytes: ...

mypy/typeshed/stdlib/_json.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ class make_scanner:
4848

4949
def encode_basestring(s: str, /) -> str: ...
5050
def encode_basestring_ascii(s: str, /) -> str: ...
51-
def scanstring(string: str, end: int, strict: bool = ...) -> tuple[str, int]: ...
51+
def scanstring(string: str, end: int, strict: bool = True) -> tuple[str, int]: ...

0 commit comments

Comments
 (0)