Skip to content

Commit f709fc1

Browse files
cdce8phauntsaninjailevkivskyiAlexWaygood
authored
Sync typeshed (#21799)
Source commit: python/typeshed@7ee1807 --------- Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Co-authored-by: Ivan Levkivskyi <levkivskyi@gmail.com> Co-authored-by: hauntsaninja <hauntsaninja@gmail.com> Co-authored-by: AlexWaygood <alex.waygood@gmail.com>
1 parent 630b101 commit f709fc1

71 files changed

Lines changed: 294 additions & 245 deletions

Some content is hidden

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

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 3fa6658041d3ccd7f2a4bd725e21fa9768bf6ebc Mon Sep 17 00:00:00 2001
1+
From 3715a29572ebccffe78c508da15e99ab10dc15d3 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,16 +8,16 @@ 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 22d330a08..fa22f842d 100644
11+
index 36ea1981a..6ee01a82d 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, TypeAlias, TypeVar, overload, type_check_only
19-
+from typing import IO, Any, ClassVar, Final, Generic, NewType, NoReturn, Protocol, TypeAlias, TypeVar, overload, type_check_only
20-
from typing_extensions import Self, deprecated
18+
-from typing import IO, Any, ClassVar, Final, Generic, Protocol, TypeAlias, TypeVar, overload, type_check_only
19+
+from typing import IO, Any, ClassVar, Final, Generic, NewType, Protocol, TypeAlias, TypeVar, overload, type_check_only
20+
from typing_extensions import Never, Self, deprecated
2121

2222
__all__ = [
2323
@@ -36,7 +36,9 @@ ONE_OR_MORE: Final = "+"
@@ -41,5 +41,5 @@ index 22d330a08..fa22f842d 100644
4141
default: Any = ...,
4242
type: _ActionType = ...,
4343
--
44-
2.54.0
44+
2.55.0
4545

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From b5d1e4c76d8139e1a20f9178e8123f3ee39084d2 Mon Sep 17 00:00:00 2001
1+
From aedaebba6e477469af6bc21ffb60ff6fc5def01e 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 242093e1e..92bb4e5f4 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 e63b74214..9ea382dd6 100644
39+
index ec72c308e..d0963d5b7 100644
4040
--- a/mypy/typeshed/stdlib/builtins.pyi
4141
+++ b/mypy/typeshed/stdlib/builtins.pyi
42-
@@ -1368,7 +1368,7 @@ class frozenset(AbstractSet[_T_co]):
42+
@@ -1376,7 +1376,7 @@ class frozenset(AbstractSet[_T_co]):
4343
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
4444

4545
@disjoint_base
@@ -48,7 +48,7 @@ index e63b74214..9ea382dd6 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-
@@ -1634,7 +1634,7 @@ else:
51+
@@ -1642,7 +1642,7 @@ else:
5252
exit: _sitebuiltins.Quitter
5353

5454
@disjoint_base
@@ -57,7 +57,7 @@ index e63b74214..9ea382dd6 100644
5757
@overload
5858
def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ...
5959
@overload
60-
@@ -1705,7 +1705,7 @@ license: _sitebuiltins._Printer
60+
@@ -1713,7 +1713,7 @@ license: _sitebuiltins._Printer
6161
def locals() -> dict[str, Any]: ...
6262

6363
@disjoint_base
@@ -66,16 +66,16 @@ index e63b74214..9ea382dd6 100644
6666
# 3.14 adds `strict` argument.
6767
if sys.version_info >= (3, 14):
6868
@overload
69-
@@ -2021,7 +2021,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex
70-
quit: _sitebuiltins.Quitter
69+
@@ -2033,7 +2033,7 @@ class _SupportsReversed(Protocol[_T_co]):
70+
def __reversed__(self) -> _T_co: ...
7171

7272
@disjoint_base
73-
-class reversed(Generic[_T]):
74-
+class reversed(Iterator[_T]):
73+
-class reversed(Generic[_T_co]):
74+
+class reversed(Iterator[_T_co]):
7575
@overload
76-
def __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T]: ... # type: ignore[misc]
76+
def __new__(cls, sequence: _SupportsReversed[_T], /) -> _T: ... # type: ignore[misc]
7777
@overload
78-
@@ -2101,7 +2101,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
78+
@@ -2113,7 +2113,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
7979
def vars(object: Any = ..., /) -> dict[str, Any]: ...
8080

8181
@disjoint_base

misc/typeshed_patches/0001-Revert-dict.__or__-typeshed-change.patch

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 92a0169fa37f3ff1c41beb98ae0f61e3b3ff19dc Mon Sep 17 00:00:00 2001
1+
From f164b6f2926819cab52cca1e83b62f597d0aa82b Mon Sep 17 00:00:00 2001
22
From: Ivan Levkivskyi <levkivskyi@gmail.com>
33
Date: Wed, 8 Apr 2026 00:01:44 +0100
44
Subject: [PATCH] Revert dict.__or__ typeshed change
@@ -8,10 +8,10 @@ Subject: [PATCH] Revert dict.__or__ typeshed change
88
1 file changed, 20 insertions(+)
99

1010
diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi
11-
index 9db6f4fc7..7ec0e2d7c 100644
11+
index d0963d5b7..532ba324d 100644
1212
--- a/mypy/typeshed/stdlib/builtins.pyi
1313
+++ b/mypy/typeshed/stdlib/builtins.pyi
14-
@@ -1228,14 +1228,27 @@ class dict(MutableMapping[_KT, _VT]):
14+
@@ -1235,15 +1235,28 @@ class dict(MutableMapping[_KT, _VT]):
1515
__hash__: ClassVar[None] # type: ignore[assignment]
1616
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
1717
if sys.version_info >= (3, 15):
@@ -28,6 +28,7 @@ index 9db6f4fc7..7ec0e2d7c 100644
2828
+ def __ror__(self, value: frozendict[_KT, _VT], /) -> frozendict[_KT, _VT]: ...
2929
+ @overload
3030
def __ror__(self, value: frozendict[_T1, _T2], /) -> frozendict[_KT | _T1, _VT | _T2]: ...
31+
3132
else:
3233
+ @overload
3334
+ def __or__(self, value: dict[_KT, _VT], /) -> dict[_KT, _VT]: ...
@@ -39,7 +40,7 @@ index 9db6f4fc7..7ec0e2d7c 100644
3940
def __ror__(self, value: dict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ...
4041

4142
# dict.__ior__ should be kept roughly in line with MutableMapping.update()
42-
@@ -1290,11 +1303,18 @@ if sys.version_info >= (3, 15):
43+
@@ -1297,11 +1310,18 @@ if sys.version_info >= (3, 15):
4344
def __iter__(self) -> Iterator[_KT]: ...
4445
def __hash__(self) -> int: ...
4546
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
@@ -59,5 +60,5 @@ index 9db6f4fc7..7ec0e2d7c 100644
5960

6061
@disjoint_base
6162
--
62-
2.54.0
63+
2.55.0
6364

mypy/typeshed/stdlib/__main__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
def __getattr__(name: str): ... # incomplete module
1+
def __getattr__(name: str, /): ... # incomplete module

mypy/typeshed/stdlib/_ctypes.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ class _UnionType(_CTypeBaseType):
249249
# At runtime, various attributes are created on a Union subclass based
250250
# on its _fields_. This method doesn't exist, but represents those
251251
# dynamically created attributes.
252-
def __getattr__(self, name: str) -> _CField[Any, Any, Any]: ...
252+
def __getattr__(self, name: str, /) -> _CField[Any, Any, Any]: ...
253253
if sys.version_info < (3, 13):
254254
# Inherited from CType_Type starting on 3.13
255255
def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
@@ -263,8 +263,8 @@ class Union(_CData, metaclass=_UnionType):
263263
_align_: ClassVar[int]
264264

265265
def __init__(self, *args: Any, **kw: Any) -> None: ...
266-
def __getattr__(self, name: str) -> Any: ...
267-
def __setattr__(self, name: str, value: Any) -> None: ...
266+
def __getattr__(self, name: str, /) -> Any: ...
267+
def __setattr__(self, name: str, value: Any, /) -> None: ...
268268

269269
# This class is not exposed. It calls itself _ctypes.PyCStructType.
270270
@type_check_only
@@ -277,7 +277,7 @@ class _PyCStructType(_CTypeBaseType):
277277
# At runtime, various attributes are created on a Structure subclass based
278278
# on its _fields_. This method doesn't exist, but represents those
279279
# dynamically created attributes.
280-
def __getattr__(self, name: str) -> _CField[Any, Any, Any]: ...
280+
def __getattr__(self, name: str, /) -> _CField[Any, Any, Any]: ...
281281
if sys.version_info < (3, 13):
282282
# Inherited from CType_Type starting on 3.13
283283
def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
@@ -295,7 +295,7 @@ class Structure(_CData, metaclass=_PyCStructType):
295295
_layout_: ClassVar[Literal["ms", "gcc-sysv"]]
296296

297297
def __init__(self, *args: Any, **kw: Any) -> None: ...
298-
def __getattr__(self, name: str) -> Any: ...
298+
def __getattr__(self, name: str, /) -> Any: ...
299299
def __setattr__(self, name: str, value: Any) -> None: ...
300300

301301
# This class is not exposed. It calls itself _ctypes.PyCArrayType.

mypy/typeshed/stdlib/_sitebuiltins.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import sys
22
from collections.abc import Iterable
3-
from typing import ClassVar, Literal, NoReturn
3+
from typing import ClassVar, Literal
4+
from typing_extensions import Never
45

56
class Quitter:
67
name: str
78
eof: str
89
def __init__(self, name: str, eof: str) -> None: ...
9-
def __call__(self, code: sys._ExitCode = None) -> NoReturn: ...
10+
def __call__(self, code: sys._ExitCode = None) -> Never: ...
1011

1112
class _Printer:
1213
MAXLINES: ClassVar[Literal[23]]

mypy/typeshed/stdlib/_thread.pyi

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

1010
_Ts = TypeVarTuple("_Ts")
1111

@@ -82,9 +82,9 @@ def start_new(function: Callable[[Unpack[_Ts]], object], args: tuple[Unpack[_Ts]
8282
def start_new(function: Callable[..., object], args: tuple[Any, ...], kwargs: dict[str, Any], /) -> int: ... # undocumented
8383

8484
def interrupt_main(signum: signal.Signals = signal.SIGINT, /) -> None: ...
85-
def exit() -> NoReturn: ...
85+
def exit() -> Never: ...
8686
@deprecated("Obsolete synonym. Use `exit()` instead.")
87-
def exit_thread() -> NoReturn: ... # undocumented
87+
def exit_thread() -> Never: ... # undocumented
8888
def allocate_lock() -> LockType: ...
8989
@deprecated("Obsolete synonym. Use `allocate_lock()` instead.")
9090
def allocate() -> LockType: ... # undocumented

mypy/typeshed/stdlib/_typeshed/__init__.pyi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ Unused: TypeAlias = object # stable
5858
# for more information.
5959
MaybeNone: TypeAlias = Any # stable
6060

61+
# typeshed-internal type aliases to facilitate transition from
62+
# `float` to either `float | int` or `float` (and similar for `complex`).
63+
# When you encounter one of these type aliases, you are encouraged to
64+
# replace them with the correct type. Please don't use them outside typeshed.
65+
# See https://github.com/python/typeshed/issues/16059 for details.
66+
FloatInt: TypeAlias = float | int
67+
ComplexInt: TypeAlias = complex | float | int
68+
6169
# Used to mark arguments that default to a sentinel value. This prevents
6270
# stubtest from complaining about the default value not matching.
6371
#

mypy/typeshed/stdlib/_winapi.pyi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import sys
22
from _typeshed import ReadableBuffer
33
from collections.abc import Sequence
4-
from typing import Any, Final, Literal, NoReturn, final, overload
4+
from typing import Any, Final, Literal, final, overload
5+
from typing_extensions import Never
56

67
if sys.platform == "win32":
78
ABOVE_NORMAL_PRIORITY_CLASS: Final = 0x8000
@@ -238,7 +239,7 @@ if sys.platform == "win32":
238239
options: int = 0,
239240
/,
240241
) -> int: ...
241-
def ExitProcess(ExitCode: int, /) -> NoReturn: ...
242+
def ExitProcess(ExitCode: int, /) -> Never: ...
242243
def GetACP() -> int: ...
243244
if sys.version_info >= (3, 15):
244245
def DeregisterEventSource(handle: int, /) -> None: ...
@@ -312,3 +313,6 @@ if sys.platform == "win32":
312313
if sys.version_info >= (3, 12):
313314
def CopyFile2(existing_file_name: str, new_file_name: str, flags: int, progress_routine: int | None = None) -> int: ...
314315
def NeedCurrentDirectoryForExePath(exe_name: str, /) -> bool: ...
316+
317+
if sys.version_info >= (3, 15):
318+
def GetTickCount64() -> int: ...

mypy/typeshed/stdlib/argparse.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import sys
22
from _typeshed import SupportsWrite, sentinel
33
from collections.abc import Callable, Generator, Iterable, Sequence
44
from re import Pattern
5-
from typing import IO, Any, ClassVar, Final, Generic, NewType, NoReturn, Protocol, TypeAlias, TypeVar, overload, type_check_only
6-
from typing_extensions import Self, deprecated
5+
from typing import IO, Any, ClassVar, Final, Generic, NewType, Protocol, TypeAlias, TypeVar, overload, type_check_only
6+
from typing_extensions import Never, Self, deprecated
77

88
__all__ = [
99
"ArgumentParser",
@@ -105,7 +105,7 @@ class _ActionsContainer:
105105
conflict_handler: str = ...,
106106
) -> _ArgumentGroup: ...
107107
@overload
108-
@deprecated("The `prefix_chars` parameter deprecated since Python 3.14.")
108+
@deprecated("The `prefix_chars` parameter is deprecated.")
109109
def add_argument_group(
110110
self,
111111
title: str | None = None,
@@ -125,7 +125,7 @@ class _ActionsContainer:
125125
def _pop_action_class(self, kwargs: Any, default: type[Action] | None = None) -> type[Action]: ...
126126
def _get_handler(self) -> Callable[[Action, Iterable[tuple[str, Action]]], Any]: ...
127127
def _check_conflict(self, action: Action) -> None: ...
128-
def _handle_conflict_error(self, action: Action, conflicting_actions: Iterable[tuple[str, Action]]) -> NoReturn: ...
128+
def _handle_conflict_error(self, action: Action, conflicting_actions: Iterable[tuple[str, Action]]) -> Never: ...
129129
def _handle_conflict_resolve(self, action: Action, conflicting_actions: Iterable[tuple[str, Action]]) -> None: ...
130130

131131
@type_check_only
@@ -266,8 +266,8 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
266266
def parse_known_args(self, *, namespace: _N) -> tuple[_N, list[str]]: ...
267267

268268
def convert_arg_line_to_args(self, arg_line: str) -> list[str]: ...
269-
def exit(self, status: int = 0, message: str | None = None) -> NoReturn: ...
270-
def error(self, message: str) -> NoReturn: ...
269+
def exit(self, status: int = 0, message: str | None = None) -> Never: ...
270+
def error(self, message: str) -> Never: ...
271271

272272
@overload
273273
def parse_intermixed_args(self, args: Iterable[str] | None = None, namespace: None = None) -> Namespace: ...
@@ -532,7 +532,7 @@ class Namespace(_AttributeHolder):
532532
def __eq__(self, other: object) -> bool: ...
533533
__hash__: ClassVar[None] # type: ignore[assignment]
534534

535-
@deprecated("Deprecated since Python 3.14. Open files after parsing arguments instead.")
535+
@deprecated("Deprecated; may leave files open. Open files after parsing arguments instead.")
536536
class FileType:
537537
# undocumented
538538
_mode: str
@@ -558,7 +558,7 @@ class _ArgumentGroup(_ActionsContainer):
558558
conflict_handler: str = ...,
559559
) -> None: ...
560560
@overload
561-
@deprecated("Undocumented `prefix_chars` parameter is deprecated since Python 3.14.")
561+
@deprecated("Undocumented `prefix_chars` parameter is deprecated.")
562562
def __init__(
563563
self,
564564
container: _ActionsContainer,

0 commit comments

Comments
 (0)