From 5bf6e2798c6dc1d15c3ef1d22a8cac8e1cd74792 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sun, 2 Aug 2026 11:59:21 +0200 Subject: [PATCH 01/12] Update typeshed patch --- ...ially-revert-Clean-up-argparse-hacks.patch | 12 +++++----- ...redundant-inheritances-from-Iterator.patch | 22 +++++++++---------- ...1-Revert-dict.__or__-typeshed-change.patch | 11 +++++----- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/misc/typeshed_patches/0001-Partially-revert-Clean-up-argparse-hacks.patch b/misc/typeshed_patches/0001-Partially-revert-Clean-up-argparse-hacks.patch index bd7cbae517543..3d716eda66eaa 100644 --- a/misc/typeshed_patches/0001-Partially-revert-Clean-up-argparse-hacks.patch +++ b/misc/typeshed_patches/0001-Partially-revert-Clean-up-argparse-hacks.patch @@ -1,4 +1,4 @@ -From 3fa6658041d3ccd7f2a4bd725e21fa9768bf6ebc Mon Sep 17 00:00:00 2001 +From 3715a29572ebccffe78c508da15e99ab10dc15d3 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 15 Feb 2025 20:11:06 +0100 Subject: [PATCH] Partially revert Clean up argparse hacks @@ -8,16 +8,16 @@ Subject: [PATCH] Partially revert Clean up argparse hacks 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mypy/typeshed/stdlib/argparse.pyi b/mypy/typeshed/stdlib/argparse.pyi -index 22d330a08..fa22f842d 100644 +index 36ea1981a..6ee01a82d 100644 --- a/mypy/typeshed/stdlib/argparse.pyi +++ b/mypy/typeshed/stdlib/argparse.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import SupportsWrite, sentinel from collections.abc import Callable, Generator, Iterable, Sequence from re import Pattern --from typing import IO, Any, ClassVar, Final, Generic, NoReturn, Protocol, TypeAlias, TypeVar, overload, type_check_only -+from typing import IO, Any, ClassVar, Final, Generic, NewType, NoReturn, Protocol, TypeAlias, TypeVar, overload, type_check_only - from typing_extensions import Self, deprecated +-from typing import IO, Any, ClassVar, Final, Generic, Protocol, TypeAlias, TypeVar, overload, type_check_only ++from typing import IO, Any, ClassVar, Final, Generic, NewType, Protocol, TypeAlias, TypeVar, overload, type_check_only + from typing_extensions import Never, Self, deprecated __all__ = [ @@ -36,7 +36,9 @@ ONE_OR_MORE: Final = "+" @@ -41,5 +41,5 @@ index 22d330a08..fa22f842d 100644 default: Any = ..., type: _ActionType = ..., -- -2.54.0 +2.55.0 diff --git a/misc/typeshed_patches/0001-Revert-Remove-redundant-inheritances-from-Iterator.patch b/misc/typeshed_patches/0001-Revert-Remove-redundant-inheritances-from-Iterator.patch index 4673723087efb..e4369f3062440 100644 --- a/misc/typeshed_patches/0001-Revert-Remove-redundant-inheritances-from-Iterator.patch +++ b/misc/typeshed_patches/0001-Revert-Remove-redundant-inheritances-from-Iterator.patch @@ -1,4 +1,4 @@ -From b5d1e4c76d8139e1a20f9178e8123f3ee39084d2 Mon Sep 17 00:00:00 2001 +From aedaebba6e477469af6bc21ffb60ff6fc5def01e Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 21 Dec 2024 22:36:38 +0100 Subject: [PATCH] Revert Remove redundant inheritances from Iterator in @@ -36,10 +36,10 @@ index 242093e1e..92bb4e5f4 100644 @property def _exception(self) -> BaseException | None: ... diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi -index e63b74214..9ea382dd6 100644 +index ec72c308e..d0963d5b7 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi -@@ -1368,7 +1368,7 @@ class frozenset(AbstractSet[_T_co]): +@@ -1376,7 +1376,7 @@ class frozenset(AbstractSet[_T_co]): def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... @disjoint_base @@ -48,7 +48,7 @@ index e63b74214..9ea382dd6 100644 def __new__(cls, iterable: Iterable[_T], start: int = 0) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> tuple[int, _T]: ... -@@ -1634,7 +1634,7 @@ else: +@@ -1642,7 +1642,7 @@ else: exit: _sitebuiltins.Quitter @disjoint_base @@ -57,7 +57,7 @@ index e63b74214..9ea382dd6 100644 @overload def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ... @overload -@@ -1705,7 +1705,7 @@ license: _sitebuiltins._Printer +@@ -1713,7 +1713,7 @@ license: _sitebuiltins._Printer def locals() -> dict[str, Any]: ... @disjoint_base @@ -66,16 +66,16 @@ index e63b74214..9ea382dd6 100644 # 3.14 adds `strict` argument. if sys.version_info >= (3, 14): @overload -@@ -2021,7 +2021,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex - quit: _sitebuiltins.Quitter +@@ -2033,7 +2033,7 @@ class _SupportsReversed(Protocol[_T_co]): + def __reversed__(self) -> _T_co: ... @disjoint_base --class reversed(Generic[_T]): -+class reversed(Iterator[_T]): +-class reversed(Generic[_T_co]): ++class reversed(Iterator[_T_co]): @overload - def __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T]: ... # type: ignore[misc] + def __new__(cls, sequence: _SupportsReversed[_T], /) -> _T: ... # type: ignore[misc] @overload -@@ -2101,7 +2101,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ... +@@ -2113,7 +2113,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ... def vars(object: Any = ..., /) -> dict[str, Any]: ... @disjoint_base diff --git a/misc/typeshed_patches/0001-Revert-dict.__or__-typeshed-change.patch b/misc/typeshed_patches/0001-Revert-dict.__or__-typeshed-change.patch index f144e989fb683..a91f9fa22fcb9 100644 --- a/misc/typeshed_patches/0001-Revert-dict.__or__-typeshed-change.patch +++ b/misc/typeshed_patches/0001-Revert-dict.__or__-typeshed-change.patch @@ -1,4 +1,4 @@ -From 92a0169fa37f3ff1c41beb98ae0f61e3b3ff19dc Mon Sep 17 00:00:00 2001 +From f164b6f2926819cab52cca1e83b62f597d0aa82b Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Wed, 8 Apr 2026 00:01:44 +0100 Subject: [PATCH] Revert dict.__or__ typeshed change @@ -8,10 +8,10 @@ Subject: [PATCH] Revert dict.__or__ typeshed change 1 file changed, 20 insertions(+) diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi -index 9db6f4fc7..7ec0e2d7c 100644 +index d0963d5b7..532ba324d 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi -@@ -1228,14 +1228,27 @@ class dict(MutableMapping[_KT, _VT]): +@@ -1235,15 +1235,28 @@ class dict(MutableMapping[_KT, _VT]): __hash__: ClassVar[None] # type: ignore[assignment] def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... if sys.version_info >= (3, 15): @@ -28,6 +28,7 @@ index 9db6f4fc7..7ec0e2d7c 100644 + def __ror__(self, value: frozendict[_KT, _VT], /) -> frozendict[_KT, _VT]: ... + @overload def __ror__(self, value: frozendict[_T1, _T2], /) -> frozendict[_KT | _T1, _VT | _T2]: ... + else: + @overload + def __or__(self, value: dict[_KT, _VT], /) -> dict[_KT, _VT]: ... @@ -39,7 +40,7 @@ index 9db6f4fc7..7ec0e2d7c 100644 def __ror__(self, value: dict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ... # dict.__ior__ should be kept roughly in line with MutableMapping.update() -@@ -1290,11 +1303,18 @@ if sys.version_info >= (3, 15): +@@ -1297,11 +1310,18 @@ if sys.version_info >= (3, 15): def __iter__(self) -> Iterator[_KT]: ... def __hash__(self) -> int: ... def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... @@ -59,5 +60,5 @@ index 9db6f4fc7..7ec0e2d7c 100644 @disjoint_base -- -2.54.0 +2.55.0 From 029839f2fa0e1e8ba9517c4766db9f20da1d34d9 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 3 Aug 2026 01:33:10 +0200 Subject: [PATCH 02/12] Sync typeshed Source commit: https://github.com/python/typeshed/commit/7ee1807de401359ff16cab195aeb9b2a6f2fd8b8 --- mypy/typeshed/stdlib/__future__.pyi | 2 +- mypy/typeshed/stdlib/__main__.pyi | 2 +- mypy/typeshed/stdlib/_asyncio.pyi | 4 +- mypy/typeshed/stdlib/_ctypes.pyi | 17 +- mypy/typeshed/stdlib/_operator.pyi | 58 ++++-- mypy/typeshed/stdlib/_sitebuiltins.pyi | 5 +- mypy/typeshed/stdlib/_thread.pyi | 8 +- mypy/typeshed/stdlib/_typeshed/__init__.pyi | 8 + mypy/typeshed/stdlib/_winapi.pyi | 8 +- mypy/typeshed/stdlib/argparse.pyi | 22 +-- mypy/typeshed/stdlib/asyncio/coroutines.pyi | 8 +- mypy/typeshed/stdlib/asyncio/events.pyi | 12 +- mypy/typeshed/stdlib/asyncio/protocols.pyi | 8 +- mypy/typeshed/stdlib/asyncio/trsock.pyi | 14 +- .../stdlib/asyncio/windows_events.pyi | 11 +- mypy/typeshed/stdlib/builtins.pyi | 183 ++++++++++++++---- mypy/typeshed/stdlib/codecs.pyi | 2 +- mypy/typeshed/stdlib/collections/__init__.pyi | 7 +- .../stdlib/concurrent/futures/process.pyi | 7 +- mypy/typeshed/stdlib/contextlib.pyi | 15 +- mypy/typeshed/stdlib/csv.pyi | 4 +- mypy/typeshed/stdlib/ctypes/__init__.pyi | 4 +- mypy/typeshed/stdlib/datetime.pyi | 6 +- mypy/typeshed/stdlib/decimal.pyi | 2 +- mypy/typeshed/stdlib/dis.pyi | 4 +- mypy/typeshed/stdlib/fileinput.pyi | 6 +- mypy/typeshed/stdlib/http/cookiejar.pyi | 4 +- mypy/typeshed/stdlib/http/server.pyi | 2 +- mypy/typeshed/stdlib/imaplib.pyi | 20 +- mypy/typeshed/stdlib/importlib/readers.pyi | 8 +- .../stdlib/importlib/resources/__init__.pyi | 2 +- .../stdlib/importlib/resources/abc.pyi | 2 +- .../stdlib/importlib/resources/simple.pyi | 6 +- mypy/typeshed/stdlib/inspect.pyi | 4 +- mypy/typeshed/stdlib/itertools.pyi | 40 ++-- mypy/typeshed/stdlib/lib2to3/pgen2/pgen.pyi | 7 +- mypy/typeshed/stdlib/lib2to3/pytree.pyi | 4 +- mypy/typeshed/stdlib/lib2to3/refactor.pyi | 5 +- mypy/typeshed/stdlib/locale.pyi | 2 +- mypy/typeshed/stdlib/logging/__init__.pyi | 2 +- mypy/typeshed/stdlib/math/__init__.pyi | 2 +- mypy/typeshed/stdlib/mmap.pyi | 6 +- mypy/typeshed/stdlib/multiprocessing/pool.pyi | 4 +- mypy/typeshed/stdlib/nturl2path.pyi | 4 +- mypy/typeshed/stdlib/optparse.pyi | 8 +- mypy/typeshed/stdlib/os/__init__.pyi | 25 ++- mypy/typeshed/stdlib/pathlib/__init__.pyi | 4 +- mypy/typeshed/stdlib/pkgutil.pyi | 4 +- mypy/typeshed/stdlib/platform.pyi | 2 +- mypy/typeshed/stdlib/poplib.pyi | 8 +- mypy/typeshed/stdlib/pty.pyi | 4 +- mypy/typeshed/stdlib/pydoc.pyi | 8 +- mypy/typeshed/stdlib/random.pyi | 8 +- mypy/typeshed/stdlib/re.pyi | 5 +- mypy/typeshed/stdlib/shutil.pyi | 6 +- mypy/typeshed/stdlib/sqlite3/__init__.pyi | 2 +- mypy/typeshed/stdlib/sunau.pyi | 6 +- mypy/typeshed/stdlib/symtable.pyi | 2 +- mypy/typeshed/stdlib/sys/__init__.pyi | 8 +- mypy/typeshed/stdlib/sysconfig.pyi | 4 +- mypy/typeshed/stdlib/tarfile.pyi | 4 +- mypy/typeshed/stdlib/time.pyi | 6 +- mypy/typeshed/stdlib/tkinter/__init__.pyi | 12 +- mypy/typeshed/stdlib/typing.pyi | 11 +- mypy/typeshed/stdlib/typing_extensions.pyi | 2 +- mypy/typeshed/stdlib/unittest/case.pyi | 5 +- mypy/typeshed/stdlib/unittest/loader.pyi | 6 +- mypy/typeshed/stdlib/unittest/main.pyi | 2 +- mypy/typeshed/stdlib/urllib/request.pyi | 6 +- mypy/typeshed/stdlib/uuid.pyi | 6 +- mypy/typeshed/stdlib/wave.pyi | 20 +- mypy/typeshed/stdlib/webbrowser.pyi | 2 +- mypy/typeshed/stdlib/wsgiref/validate.pyi | 7 +- mypy/typeshed/stdlib/xml/dom/expatbuilder.pyi | 7 +- mypy/typeshed/stdlib/xml/dom/minidom.pyi | 28 +-- mypy/typeshed/stdlib/xml/dom/pulldom.pyi | 8 +- mypy/typeshed/stdlib/xml/dom/xmlbuilder.pyi | 13 +- mypy/typeshed/stdlib/xml/sax/_exceptions.pyi | 4 +- mypy/typeshed/stdlib/xml/sax/handler.pyi | 11 +- mypy/typeshed/stdlib/xml/sax/saxutils.pyi | 7 +- 80 files changed, 512 insertions(+), 310 deletions(-) diff --git a/mypy/typeshed/stdlib/__future__.pyi b/mypy/typeshed/stdlib/__future__.pyi index a90cf1eddab76..aa445d22bd20d 100644 --- a/mypy/typeshed/stdlib/__future__.pyi +++ b/mypy/typeshed/stdlib/__future__.pyi @@ -1,4 +1,4 @@ -from typing_extensions import TypeAlias +from typing import TypeAlias _VersionInfo: TypeAlias = tuple[int, int, int, str, int] diff --git a/mypy/typeshed/stdlib/__main__.pyi b/mypy/typeshed/stdlib/__main__.pyi index 5b0f74feb261b..3536a6f021c53 100644 --- a/mypy/typeshed/stdlib/__main__.pyi +++ b/mypy/typeshed/stdlib/__main__.pyi @@ -1 +1 @@ -def __getattr__(name: str): ... # incomplete module +def __getattr__(name: str, /): ... # incomplete module diff --git a/mypy/typeshed/stdlib/_asyncio.pyi b/mypy/typeshed/stdlib/_asyncio.pyi index 92bb4e5f41706..242093e1ec799 100644 --- a/mypy/typeshed/stdlib/_asyncio.pyi +++ b/mypy/typeshed/stdlib/_asyncio.pyi @@ -1,6 +1,6 @@ import sys from asyncio.events import AbstractEventLoop -from collections.abc import Awaitable, Callable, Coroutine, Generator, Iterable +from collections.abc import Awaitable, Callable, Coroutine, Generator from contextvars import Context from types import FrameType, GenericAlias from typing import Any, Literal, TextIO, TypeAlias, TypeVar @@ -11,7 +11,7 @@ _T_co = TypeVar("_T_co", covariant=True) _TaskYieldType: TypeAlias = Future[object] | None @disjoint_base -class Future(Awaitable[_T], Iterable[_T]): +class Future(Awaitable[_T]): _state: str @property def _exception(self) -> BaseException | None: ... diff --git a/mypy/typeshed/stdlib/_ctypes.pyi b/mypy/typeshed/stdlib/_ctypes.pyi index 1efb119263ef1..36365cea3aa82 100644 --- a/mypy/typeshed/stdlib/_ctypes.pyi +++ b/mypy/typeshed/stdlib/_ctypes.pyi @@ -249,7 +249,7 @@ class _UnionType(_CTypeBaseType): # At runtime, various attributes are created on a Union subclass based # on its _fields_. This method doesn't exist, but represents those # dynamically created attributes. - def __getattr__(self, name: str) -> _CField[Any, Any, Any]: ... + def __getattr__(self, name: str, /) -> _CField[Any, Any, Any]: ... if sys.version_info < (3, 13): # Inherited from CType_Type starting on 3.13 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): _align_: ClassVar[int] def __init__(self, *args: Any, **kw: Any) -> None: ... - def __getattr__(self, name: str) -> Any: ... - def __setattr__(self, name: str, value: Any) -> None: ... + def __getattr__(self, name: str, /) -> Any: ... + def __setattr__(self, name: str, value: Any, /) -> None: ... # This class is not exposed. It calls itself _ctypes.PyCStructType. @type_check_only @@ -277,7 +277,7 @@ class _PyCStructType(_CTypeBaseType): # At runtime, various attributes are created on a Structure subclass based # on its _fields_. This method doesn't exist, but represents those # dynamically created attributes. - def __getattr__(self, name: str) -> _CField[Any, Any, Any]: ... + def __getattr__(self, name: str, /) -> _CField[Any, Any, Any]: ... if sys.version_info < (3, 13): # Inherited from CType_Type starting on 3.13 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): _layout_: ClassVar[Literal["ms", "gcc-sysv"]] def __init__(self, *args: Any, **kw: Any) -> None: ... - def __getattr__(self, name: str) -> Any: ... + def __getattr__(self, name: str, /) -> Any: ... def __setattr__(self, name: str, value: Any) -> None: ... # This class is not exposed. It calls itself _ctypes.PyCArrayType. @@ -324,7 +324,12 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType): @_type_.setter def _type_(self, value: type[_CT]) -> None: ... - raw: bytes # Note: only available if _CT == c_char + # Note: only available if _CT == c_char + @property + def raw(self) -> bytes: ... + @raw.setter + def raw(self, value: ReadableBuffer) -> None: ... + value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise # TODO: These methods cannot be annotated correctly at the moment. # All of these "Any"s stand for the array's element type, but it's not possible to use _CT diff --git a/mypy/typeshed/stdlib/_operator.pyi b/mypy/typeshed/stdlib/_operator.pyi index 29a6d70572028..04dae79dcd52d 100644 --- a/mypy/typeshed/stdlib/_operator.pyi +++ b/mypy/typeshed/stdlib/_operator.pyi @@ -1,5 +1,15 @@ import sys -from _typeshed import SupportsGetItem +from _typeshed import ( + SupportsAdd, + SupportsGetItem, + SupportsMod, + SupportsMul, + SupportsRAdd, + SupportsRMod, + SupportsRMul, + SupportsRSub, + SupportsSub, +) from collections.abc import Callable, Container, Iterable, MutableMapping, MutableSequence, Sequence from operator import attrgetter as attrgetter, itemgetter as itemgetter, methodcaller as methodcaller from typing import Any, AnyStr, ParamSpec, Protocol, SupportsAbs, SupportsIndex, TypeAlias, TypeVar, overload, type_check_only @@ -8,6 +18,7 @@ from typing_extensions import TypeIs _R = TypeVar("_R") _T = TypeVar("_T") _T_co = TypeVar("_T_co", covariant=True) +_T_contra = TypeVar("_T_contra", contravariant=True) _K = TypeVar("_K") _V = TypeVar("_V") _P = ParamSpec("_P") @@ -58,24 +69,43 @@ def truth(a: object, /) -> bool: ... def is_(a: object, b: object, /) -> bool: ... def is_not(a: object, b: object, /) -> bool: ... def abs(a: SupportsAbs[_T], /) -> _T: ... -def add(a: Any, b: Any, /) -> Any: ... -def and_(a: Any, b: Any, /) -> Any: ... -def floordiv(a: Any, b: Any, /) -> Any: ... + +@overload +def add(a: SupportsAdd[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ... +@overload +def add(a: _T_contra, b: SupportsRAdd[_T_contra, _T_co], /) -> _T_co: ... + +def and_(a, b, /): ... +def floordiv(a, b, /): ... def index(a: SupportsIndex, /) -> int: ... def inv(a: _SupportsInversion[_T_co], /) -> _T_co: ... def invert(a: _SupportsInversion[_T_co], /) -> _T_co: ... -def lshift(a: Any, b: Any, /) -> Any: ... -def mod(a: Any, b: Any, /) -> Any: ... -def mul(a: Any, b: Any, /) -> Any: ... -def matmul(a: Any, b: Any, /) -> Any: ... +def lshift(a, b, /): ... + +@overload +def mod(a: SupportsMod[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ... +@overload +def mod(a: _T_contra, b: SupportsRMod[_T_contra, _T_co], /) -> _T_co: ... + +@overload +def mul(a: SupportsMul[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ... +@overload +def mul(a: _T_contra, b: SupportsRMul[_T_contra, _T_co], /) -> _T_co: ... + +def matmul(a, b, /): ... def neg(a: _SupportsNeg[_T_co], /) -> _T_co: ... -def or_(a: Any, b: Any, /) -> Any: ... +def or_(a, b, /): ... def pos(a: _SupportsPos[_T_co], /) -> _T_co: ... -def pow(a: Any, b: Any, /) -> Any: ... -def rshift(a: Any, b: Any, /) -> Any: ... -def sub(a: Any, b: Any, /) -> Any: ... -def truediv(a: Any, b: Any, /) -> Any: ... -def xor(a: Any, b: Any, /) -> Any: ... +def pow(a, b, /): ... +def rshift(a, b, /): ... + +@overload +def sub(a: SupportsSub[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ... +@overload +def sub(a: _T_contra, b: SupportsRSub[_T_contra, _T_co], /) -> _T_co: ... + +def truediv(a, b, /): ... +def xor(a, b, /): ... def concat(a: Sequence[_T], b: Sequence[_T], /) -> Sequence[_T]: ... def contains(a: Container[object], b: object, /) -> bool: ... def countOf(a: Iterable[object], b: object, /) -> int: ... diff --git a/mypy/typeshed/stdlib/_sitebuiltins.pyi b/mypy/typeshed/stdlib/_sitebuiltins.pyi index eb6c811294216..99abd02386b27 100644 --- a/mypy/typeshed/stdlib/_sitebuiltins.pyi +++ b/mypy/typeshed/stdlib/_sitebuiltins.pyi @@ -1,12 +1,13 @@ import sys from collections.abc import Iterable -from typing import ClassVar, Literal, NoReturn +from typing import ClassVar, Literal +from typing_extensions import Never class Quitter: name: str eof: str def __init__(self, name: str, eof: str) -> None: ... - def __call__(self, code: sys._ExitCode = None) -> NoReturn: ... + def __call__(self, code: sys._ExitCode = None) -> Never: ... class _Printer: MAXLINES: ClassVar[Literal[23]] diff --git a/mypy/typeshed/stdlib/_thread.pyi b/mypy/typeshed/stdlib/_thread.pyi index e2d257c9ec0ba..57622e936a3b5 100644 --- a/mypy/typeshed/stdlib/_thread.pyi +++ b/mypy/typeshed/stdlib/_thread.pyi @@ -4,8 +4,8 @@ from _typeshed import structseq from collections.abc import Callable from threading import Thread from types import TracebackType -from typing import Any, Final, NoReturn, final, overload -from typing_extensions import TypeVarTuple, Unpack, deprecated, disjoint_base +from typing import Any, Final, final, overload +from typing_extensions import Never, TypeVarTuple, Unpack, deprecated, disjoint_base _Ts = TypeVarTuple("_Ts") @@ -82,9 +82,9 @@ def start_new(function: Callable[[Unpack[_Ts]], object], args: tuple[Unpack[_Ts] def start_new(function: Callable[..., object], args: tuple[Any, ...], kwargs: dict[str, Any], /) -> int: ... # undocumented def interrupt_main(signum: signal.Signals = signal.SIGINT, /) -> None: ... -def exit() -> NoReturn: ... +def exit() -> Never: ... @deprecated("Obsolete synonym. Use `exit()` instead.") -def exit_thread() -> NoReturn: ... # undocumented +def exit_thread() -> Never: ... # undocumented def allocate_lock() -> LockType: ... @deprecated("Obsolete synonym. Use `allocate_lock()` instead.") def allocate() -> LockType: ... # undocumented diff --git a/mypy/typeshed/stdlib/_typeshed/__init__.pyi b/mypy/typeshed/stdlib/_typeshed/__init__.pyi index 2f65d8aab9c51..5b2d7f7c549f8 100644 --- a/mypy/typeshed/stdlib/_typeshed/__init__.pyi +++ b/mypy/typeshed/stdlib/_typeshed/__init__.pyi @@ -58,6 +58,14 @@ Unused: TypeAlias = object # stable # for more information. MaybeNone: TypeAlias = Any # stable +# typeshed-internal type aliases to facilitate transition from +# `float` to either `float | int` or `float` (and similar for `complex`). +# When you encounter one of these type aliases, you are encouraged to +# replace them with the correct type. Please don't use them outside typeshed. +# See https://github.com/python/typeshed/issues/16059 for details. +FloatInt: TypeAlias = float | int +ComplexInt: TypeAlias = complex | float | int + # Used to mark arguments that default to a sentinel value. This prevents # stubtest from complaining about the default value not matching. # diff --git a/mypy/typeshed/stdlib/_winapi.pyi b/mypy/typeshed/stdlib/_winapi.pyi index 7fd918d9b1e99..a9ad4f19a62ec 100644 --- a/mypy/typeshed/stdlib/_winapi.pyi +++ b/mypy/typeshed/stdlib/_winapi.pyi @@ -1,7 +1,8 @@ import sys from _typeshed import ReadableBuffer from collections.abc import Sequence -from typing import Any, Final, Literal, NoReturn, final, overload +from typing import Any, Final, Literal, final, overload +from typing_extensions import Never if sys.platform == "win32": ABOVE_NORMAL_PRIORITY_CLASS: Final = 0x8000 @@ -238,7 +239,7 @@ if sys.platform == "win32": options: int = 0, /, ) -> int: ... - def ExitProcess(ExitCode: int, /) -> NoReturn: ... + def ExitProcess(ExitCode: int, /) -> Never: ... def GetACP() -> int: ... if sys.version_info >= (3, 15): def DeregisterEventSource(handle: int, /) -> None: ... @@ -312,3 +313,6 @@ if sys.platform == "win32": if sys.version_info >= (3, 12): def CopyFile2(existing_file_name: str, new_file_name: str, flags: int, progress_routine: int | None = None) -> int: ... def NeedCurrentDirectoryForExePath(exe_name: str, /) -> bool: ... + + if sys.version_info >= (3, 15): + def GetTickCount64() -> int: ... diff --git a/mypy/typeshed/stdlib/argparse.pyi b/mypy/typeshed/stdlib/argparse.pyi index fa22f842de028..36ea1981af3f5 100644 --- a/mypy/typeshed/stdlib/argparse.pyi +++ b/mypy/typeshed/stdlib/argparse.pyi @@ -2,8 +2,8 @@ import sys from _typeshed import SupportsWrite, sentinel from collections.abc import Callable, Generator, Iterable, Sequence from re import Pattern -from typing import IO, Any, ClassVar, Final, Generic, NewType, NoReturn, Protocol, TypeAlias, TypeVar, overload, type_check_only -from typing_extensions import Self, deprecated +from typing import IO, Any, ClassVar, Final, Generic, Protocol, TypeAlias, TypeVar, overload, type_check_only +from typing_extensions import Never, Self, deprecated __all__ = [ "ArgumentParser", @@ -36,9 +36,7 @@ ONE_OR_MORE: Final = "+" OPTIONAL: Final = "?" PARSER: Final = "A..." REMAINDER: Final = "..." -_SUPPRESS_T = NewType("_SUPPRESS_T", str) -SUPPRESS: _SUPPRESS_T | str # not using Literal because argparse sometimes compares SUPPRESS with is -# the | str is there so that foo = argparse.SUPPRESS; foo = "test" checks out in mypy +SUPPRESS: Final = "==SUPPRESS==" ZERO_OR_MORE: Final = "*" _UNRECOGNIZED_ARGS_ATTR: Final = "_unrecognized_args" # undocumented @@ -81,7 +79,7 @@ class _ActionsContainer: # more precisely, Literal["?", "*", "+", "...", "A...", "==SUPPRESS=="], # but using this would make it hard to annotate callers that don't use a # literal argument and for subclasses to override this method. - nargs: int | str | _SUPPRESS_T | None = None, + nargs: int | str | None = None, const: Any = ..., default: Any = ..., type: _ActionType = ..., @@ -105,7 +103,7 @@ class _ActionsContainer: conflict_handler: str = ..., ) -> _ArgumentGroup: ... @overload - @deprecated("The `prefix_chars` parameter deprecated since Python 3.14.") + @deprecated("The `prefix_chars` parameter is deprecated.") def add_argument_group( self, title: str | None = None, @@ -125,7 +123,7 @@ class _ActionsContainer: def _pop_action_class(self, kwargs: Any, default: type[Action] | None = None) -> type[Action]: ... def _get_handler(self) -> Callable[[Action, Iterable[tuple[str, Action]]], Any]: ... def _check_conflict(self, action: Action) -> None: ... - def _handle_conflict_error(self, action: Action, conflicting_actions: Iterable[tuple[str, Action]]) -> NoReturn: ... + def _handle_conflict_error(self, action: Action, conflicting_actions: Iterable[tuple[str, Action]]) -> Never: ... def _handle_conflict_resolve(self, action: Action, conflicting_actions: Iterable[tuple[str, Action]]) -> None: ... @type_check_only @@ -266,8 +264,8 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): def parse_known_args(self, *, namespace: _N) -> tuple[_N, list[str]]: ... def convert_arg_line_to_args(self, arg_line: str) -> list[str]: ... - def exit(self, status: int = 0, message: str | None = None) -> NoReturn: ... - def error(self, message: str) -> NoReturn: ... + def exit(self, status: int = 0, message: str | None = None) -> Never: ... + def error(self, message: str) -> Never: ... @overload def parse_intermixed_args(self, args: Iterable[str] | None = None, namespace: None = None) -> Namespace: ... @@ -532,7 +530,7 @@ class Namespace(_AttributeHolder): def __eq__(self, other: object) -> bool: ... __hash__: ClassVar[None] # type: ignore[assignment] -@deprecated("Deprecated since Python 3.14. Open files after parsing arguments instead.") +@deprecated("Deprecated; may leave files open. Open files after parsing arguments instead.") class FileType: # undocumented _mode: str @@ -558,7 +556,7 @@ class _ArgumentGroup(_ActionsContainer): conflict_handler: str = ..., ) -> None: ... @overload - @deprecated("Undocumented `prefix_chars` parameter is deprecated since Python 3.14.") + @deprecated("Undocumented `prefix_chars` parameter is deprecated.") def __init__( self, container: _ActionsContainer, diff --git a/mypy/typeshed/stdlib/asyncio/coroutines.pyi b/mypy/typeshed/stdlib/asyncio/coroutines.pyi index 7599c692949bd..8fafa2e75716a 100644 --- a/mypy/typeshed/stdlib/asyncio/coroutines.pyi +++ b/mypy/typeshed/stdlib/asyncio/coroutines.pyi @@ -21,16 +21,16 @@ def iscoroutine(obj: object) -> TypeIs[Coroutine[Any, Any, Any]]: ... if sys.version_info >= (3, 11): @overload - @deprecated("Deprecated since Python 3.14. Use `inspect.iscoroutinefunction()` instead.") + @deprecated("Deprecated; will be removed in Python 3.16. Use `inspect.iscoroutinefunction()` instead.") def iscoroutinefunction(func: Callable[..., Coroutine[Any, Any, Any]]) -> bool: ... @overload - @deprecated("Deprecated since Python 3.14. Use `inspect.iscoroutinefunction()` instead.") + @deprecated("Deprecated; will be removed in Python 3.16. Use `inspect.iscoroutinefunction()` instead.") def iscoroutinefunction(func: Callable[_P, Awaitable[_T]]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, _T]]]: ... @overload - @deprecated("Deprecated since Python 3.14. Use `inspect.iscoroutinefunction()` instead.") + @deprecated("Deprecated; will be removed in Python 3.16. Use `inspect.iscoroutinefunction()` instead.") def iscoroutinefunction(func: Callable[_P, object]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, Any]]]: ... @overload - @deprecated("Deprecated since Python 3.14. Use `inspect.iscoroutinefunction()` instead.") + @deprecated("Deprecated; will be removed in Python 3.16. Use `inspect.iscoroutinefunction()` instead.") def iscoroutinefunction(func: object) -> TypeGuard[Callable[..., Coroutine[Any, Any, Any]]]: ... else: # Sometimes needed in Python < 3.11 due to the fact that it supports @coroutine diff --git a/mypy/typeshed/stdlib/asyncio/events.pyi b/mypy/typeshed/stdlib/asyncio/events.pyi index 89da5dece9070..db826ff1c2e56 100644 --- a/mypy/typeshed/stdlib/asyncio/events.pyi +++ b/mypy/typeshed/stdlib/asyncio/events.pyi @@ -633,10 +633,10 @@ else: def new_event_loop(self) -> AbstractEventLoop: ... # Child processes handling (Unix only). @abstractmethod - @deprecated("Deprecated since Python 3.12; removed in Python 3.14.") + @deprecated("Deprecated; removed in Python 3.14.") def get_child_watcher(self) -> AbstractChildWatcher: ... @abstractmethod - @deprecated("Deprecated since Python 3.12; removed in Python 3.14.") + @deprecated("Deprecated; removed in Python 3.14.") def set_child_watcher(self, watcher: AbstractChildWatcher) -> None: ... AbstractEventLoopPolicy = _AbstractEventLoopPolicy @@ -657,15 +657,15 @@ if sys.version_info >= (3, 14): def _get_event_loop_policy() -> _AbstractEventLoopPolicy: ... def _set_event_loop_policy(policy: _AbstractEventLoopPolicy | None) -> None: ... -@deprecated("Deprecated since Python 3.14; will be removed in Python 3.16.") +@deprecated("Deprecated; will be removed in Python 3.16.") def get_event_loop_policy() -> _AbstractEventLoopPolicy: ... -@deprecated("Deprecated since Python 3.14; will be removed in Python 3.16.") +@deprecated("Deprecated; will be removed in Python 3.16.") def set_event_loop_policy(policy: _AbstractEventLoopPolicy | None) -> None: ... def set_event_loop(loop: AbstractEventLoop | None) -> None: ... def new_event_loop() -> AbstractEventLoop: ... if sys.version_info < (3, 14): - @deprecated("Deprecated since Python 3.12; removed in Python 3.14.") + @deprecated("Deprecated; removed in Python 3.14.") def get_child_watcher() -> AbstractChildWatcher: ... - @deprecated("Deprecated since Python 3.12; removed in Python 3.14.") + @deprecated("Deprecated; removed in Python 3.14.") def set_child_watcher(watcher: AbstractChildWatcher) -> None: ... diff --git a/mypy/typeshed/stdlib/asyncio/protocols.pyi b/mypy/typeshed/stdlib/asyncio/protocols.pyi index 3a8965f03e29c..f63b9e084382b 100644 --- a/mypy/typeshed/stdlib/asyncio/protocols.pyi +++ b/mypy/typeshed/stdlib/asyncio/protocols.pyi @@ -27,11 +27,9 @@ class BufferedProtocol(BaseProtocol): class DatagramProtocol(BaseProtocol): __slots__ = () def connection_made(self, transport: transports.DatagramTransport) -> None: ... # type: ignore[override] - # addr can be a tuple[int, int] for some unusual protocols like socket.AF_NETLINK. - # Use tuple[str | Any, int] to not cause typechecking issues on most usual cases. - # This could be improved by using tuple[AnyOf[str, int], int] if the AnyOf feature is accepted. - # See https://github.com/python/typing/issues/566 - def datagram_received(self, data: bytes, addr: tuple[str | Any, int]) -> None: ... + # addr is a tuple[str, int] for IPv4 or tuple[str, int, int, int] for IPv6. + # It can also be a tuple[int, int] for unusual protocols like socket.AF_NETLINK. + def datagram_received(self, data: bytes, addr: tuple[Any, ...]) -> None: ... def error_received(self, exc: Exception) -> None: ... class SubprocessProtocol(BaseProtocol): diff --git a/mypy/typeshed/stdlib/asyncio/trsock.pyi b/mypy/typeshed/stdlib/asyncio/trsock.pyi index f621240d668a2..d2e972fee49c4 100644 --- a/mypy/typeshed/stdlib/asyncio/trsock.pyi +++ b/mypy/typeshed/stdlib/asyncio/trsock.pyi @@ -4,8 +4,8 @@ from _typeshed import ReadableBuffer from builtins import type as Type # alias to avoid name clashes with property named "type" from collections.abc import Iterable from types import TracebackType -from typing import Any, BinaryIO, NoReturn, TypeAlias, overload -from typing_extensions import deprecated +from typing import Any, BinaryIO, TypeAlias, overload +from typing_extensions import Never, deprecated # These are based in socket, maybe move them out into _typeshed.pyi or such _Address: TypeAlias = socket._Address @@ -22,7 +22,7 @@ class TransportSocket: def type(self) -> int: ... @property def proto(self) -> int: ... - def __getstate__(self) -> NoReturn: ... + def __getstate__(self) -> Never: ... def fileno(self) -> int: ... def dup(self) -> socket.socket: ... def get_inheritable(self) -> bool: ... @@ -40,7 +40,7 @@ class TransportSocket: def getpeername(self) -> _RetAddress: ... def getsockname(self) -> _RetAddress: ... - def getsockbyname(self) -> NoReturn: ... # This method doesn't exist on socket, yet is passed through? + def getsockbyname(self) -> Never: ... # This method doesn't exist on socket, yet is passed through? def settimeout(self, value: float | None) -> None: ... def gettimeout(self) -> float | None: ... def setblocking(self, flag: bool) -> None: ... @@ -60,7 +60,7 @@ class TransportSocket: def ioctl(self, control: int, option: int | tuple[int, int, int] | bool) -> None: ... else: @deprecated("Removed in Python 3.11") - def ioctl(self, control: int, option: int | tuple[int, int, int] | bool) -> NoReturn: ... + def ioctl(self, control: int, option: int | tuple[int, int, int] | bool) -> Never: ... @deprecated("Removed in Python 3.11") def listen(self, backlog: int = ..., /) -> None: ... @@ -82,7 +82,7 @@ class TransportSocket: @deprecated("Removed in Python 3.11.") def sendmsg_afalg( self, msg: Iterable[ReadableBuffer] = ..., *, op: int, iv: Any = ..., assoclen: int = ..., flags: int = 0 - ) -> NoReturn: ... + ) -> Never: ... @deprecated("Removed in Python 3.11.") def sendmsg( @@ -113,7 +113,7 @@ class TransportSocket: def share(self, process_id: int) -> bytes: ... else: @deprecated("Removed in Python 3.11.") - def share(self, process_id: int) -> NoReturn: ... + def share(self, process_id: int) -> Never: ... @deprecated("Removed in Python 3.11.") def recv_into(self, buffer: _WriteBuffer, nbytes: int = 0, flags: int = 0) -> int: ... diff --git a/mypy/typeshed/stdlib/asyncio/windows_events.pyi b/mypy/typeshed/stdlib/asyncio/windows_events.pyi index a32381bfb3e63..a2428e425f2f5 100644 --- a/mypy/typeshed/stdlib/asyncio/windows_events.pyi +++ b/mypy/typeshed/stdlib/asyncio/windows_events.pyi @@ -2,7 +2,8 @@ import socket import sys from _typeshed import Incomplete, ReadableBuffer, WriteableBuffer from collections.abc import Callable -from typing import IO, Any, ClassVar, Final, NoReturn +from typing import IO, Any, ClassVar, Final +from typing_extensions import Never from . import events, futures, proactor_events, selector_events, streams, windows_utils @@ -105,13 +106,13 @@ if sys.platform == "win32": else: class WindowsSelectorEventLoopPolicy(events.BaseDefaultEventLoopPolicy): _loop_factory: ClassVar[type[SelectorEventLoop]] - def get_child_watcher(self) -> NoReturn: ... - def set_child_watcher(self, watcher: Any) -> NoReturn: ... + def get_child_watcher(self) -> Never: ... + def set_child_watcher(self, watcher: Any) -> Never: ... class WindowsProactorEventLoopPolicy(events.BaseDefaultEventLoopPolicy): _loop_factory: ClassVar[type[ProactorEventLoop]] - def get_child_watcher(self) -> NoReturn: ... - def set_child_watcher(self, watcher: Any) -> NoReturn: ... + def get_child_watcher(self) -> Never: ... + def set_child_watcher(self, watcher: Any) -> Never: ... if sys.version_info >= (3, 14): _DefaultEventLoopPolicy = _WindowsProactorEventLoopPolicy diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi index 8497f9e2e1037..3c549d97316c7 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi @@ -30,7 +30,7 @@ from _typeshed import ( SupportsRichComparisonT, SupportsWrite, ) -from collections.abc import Awaitable, Callable, Iterable, Iterator, MutableSet, Reversible, Set as AbstractSet, Sized +from collections.abc import Awaitable, Callable, Iterable, Iterator, MutableSet, Set as AbstractSet, Sized from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper from os import PathLike from types import CellType, CodeType, EllipsisType, GenericAlias, NotImplementedType, TracebackType, UnionType @@ -65,7 +65,7 @@ from typing import ( # noqa: Y022,UP035 ) # we can't import `Literal` from typing or mypy crashes: see #11247 -from typing_extensions import Literal, Self, TypeIs, TypeVarTuple, deprecated, disjoint_base # noqa: Y023, UP035 +from typing_extensions import Literal, LiteralString, Self, TypeIs, TypeVarTuple, deprecated, disjoint_base # noqa: Y023, UP035 if sys.version_info >= (3, 14): from _typeshed import AnnotateFunc @@ -281,6 +281,7 @@ class int: *, signed: bool = False, ) -> Self: ... + else: def to_bytes(self, length: SupportsIndex, byteorder: Literal["little", "big"], *, signed: bool = False) -> bytes: ... @classmethod @@ -344,6 +345,7 @@ class int: def __floor__(self) -> int: ... if sys.version_info >= (3, 14): def __round__(self, ndigits: SupportsIndex | None = None, /) -> int: ... + else: def __round__(self, ndigits: SupportsIndex = ..., /) -> int: ... @@ -489,8 +491,20 @@ class str(Sequence[str]): def __new__(cls, object: object = "") -> Self: ... @overload def __new__(cls, object: ReadableBuffer, encoding: str = "utf-8", errors: str = "strict") -> Self: ... + + @overload + def capitalize(self: LiteralString) -> LiteralString: ... + @overload def capitalize(self) -> str: ... # type: ignore[misc] + + @overload + def casefold(self: LiteralString) -> LiteralString: ... + @overload def casefold(self) -> str: ... # type: ignore[misc] + + @overload + def center(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ... + @overload def center(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc] def count(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ... @@ -498,9 +512,17 @@ class str(Sequence[str]): def endswith( self, suffix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, / ) -> bool: ... + + @overload + def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ... + @overload def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc] def find(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ... + + @overload + def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ... + @overload def format(self, *args: object, **kwargs: object) -> str: ... def format_map(self, mapping: _FormatMapMapping, /) -> str: ... @@ -517,38 +539,119 @@ class str(Sequence[str]): def isspace(self) -> bool: ... def istitle(self) -> bool: ... def isupper(self) -> bool: ... + + @overload + def join(self: LiteralString, iterable: Iterable[LiteralString], /) -> LiteralString: ... + @overload def join(self, iterable: Iterable[str], /) -> str: ... # type: ignore[misc] + + @overload + def ljust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ... + @overload def ljust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc] + + @overload + def lower(self: LiteralString) -> LiteralString: ... + @overload def lower(self) -> str: ... # type: ignore[misc] + + @overload + def lstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ... + @overload def lstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc] + + @overload + def partition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ... + @overload def partition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc] if sys.version_info >= (3, 13): + @overload + def replace( + self: LiteralString, old: LiteralString, new: LiteralString, /, count: SupportsIndex = -1 + ) -> LiteralString: ... + @overload def replace(self, old: str, new: str, /, count: SupportsIndex = -1) -> str: ... # type: ignore[misc] else: + @overload + def replace( + self: LiteralString, old: LiteralString, new: LiteralString, count: SupportsIndex = -1, / + ) -> LiteralString: ... + @overload def replace(self, old: str, new: str, count: SupportsIndex = -1, /) -> str: ... # type: ignore[misc] + @overload + def removeprefix(self: LiteralString, prefix: LiteralString, /) -> LiteralString: ... + @overload def removeprefix(self, prefix: str, /) -> str: ... # type: ignore[misc] + + @overload + def removesuffix(self: LiteralString, suffix: LiteralString, /) -> LiteralString: ... + @overload def removesuffix(self, suffix: str, /) -> str: ... # type: ignore[misc] def rfind(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ... def rindex(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ... + + @overload + def rjust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ... + @overload def rjust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc] + + @overload + def rpartition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ... + @overload def rpartition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc] + + @overload + def rsplit(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ... + @overload def rsplit(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc] + + @overload + def rstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ... + @overload def rstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc] + + @overload + def split(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ... + @overload def split(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc] + + @overload + def splitlines(self: LiteralString, keepends: bool = False) -> list[LiteralString]: ... + @overload def splitlines(self, keepends: bool = False) -> list[str]: ... # type: ignore[misc] def startswith( self, prefix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, / ) -> bool: ... + + @overload + def strip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ... + @overload def strip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc] + + @overload + def swapcase(self: LiteralString) -> LiteralString: ... + @overload def swapcase(self) -> str: ... # type: ignore[misc] + + @overload + def title(self: LiteralString) -> LiteralString: ... + @overload def title(self) -> str: ... # type: ignore[misc] def translate(self, table: _TranslateTable, /) -> str: ... + + @overload + def upper(self: LiteralString) -> LiteralString: ... + @overload def upper(self) -> str: ... # type: ignore[misc] + + @overload + def zfill(self: LiteralString, width: SupportsIndex, /) -> LiteralString: ... + @overload def zfill(self, width: SupportsIndex, /) -> str: ... # type: ignore[misc] if sys.version_info >= (3, 15): @@ -576,25 +679,49 @@ class str(Sequence[str]): @staticmethod @overload def maketrans(x: str, y: str, z: str, /) -> dict[int, int | None]: ... + + @overload + def __add__(self: LiteralString, value: LiteralString, /) -> LiteralString: ... + @overload def __add__(self, value: str, /) -> str: ... # type: ignore[misc] # Incompatible with Sequence.__contains__ def __contains__(self, key: str, /) -> bool: ... # type: ignore[override] def __eq__(self, value: object, /) -> bool: ... def __ge__(self, value: str, /) -> bool: ... + + @overload + def __getitem__(self: LiteralString, key: SupportsIndex | slice[SupportsIndex | None], /) -> LiteralString: ... + @overload def __getitem__(self, key: SupportsIndex | slice[SupportsIndex | None], /) -> str: ... # type: ignore[misc] def __gt__(self, value: str, /) -> bool: ... def __hash__(self) -> int: ... + + @overload + def __iter__(self: LiteralString) -> Iterator[LiteralString]: ... + @overload def __iter__(self) -> Iterator[str]: ... # type: ignore[misc] def __le__(self, value: str, /) -> bool: ... def __len__(self) -> int: ... def __lt__(self, value: str, /) -> bool: ... + + @overload + def __mod__(self: LiteralString, value: LiteralString | tuple[LiteralString, ...], /) -> LiteralString: ... + @overload def __mod__(self, value: Any, /) -> str: ... + + @overload + def __mul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ... + @overload def __mul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc] def __ne__(self, value: object, /) -> bool: ... + + @overload + def __rmul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ... + @overload def __rmul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc] def __getnewargs__(self) -> tuple[str]: ... @@ -645,6 +772,7 @@ class bytes(Sequence[int]): def partition(self, sep: ReadableBuffer, /) -> tuple[bytes, bytes, bytes]: ... if sys.version_info >= (3, 15): def replace(self, old: ReadableBuffer, new: ReadableBuffer, /, count: SupportsIndex = -1) -> bytes: ... + else: def replace(self, old: ReadableBuffer, new: ReadableBuffer, count: SupportsIndex = -1, /) -> bytes: ... @@ -765,6 +893,7 @@ class bytearray(MutableSequence[int]): def removesuffix(self, suffix: ReadableBuffer, /) -> bytearray: ... if sys.version_info >= (3, 15): def replace(self, old: ReadableBuffer, new: ReadableBuffer, /, count: SupportsIndex = -1) -> bytearray: ... + else: def replace(self, old: ReadableBuffer, new: ReadableBuffer, count: SupportsIndex = -1, /) -> bytearray: ... @@ -917,6 +1046,7 @@ class memoryview(Sequence[_I]): if sys.version_info >= (3, 14): def index(self, value: object, start: SupportsIndex = 0, stop: SupportsIndex = sys.maxsize, /) -> int: ... def count(self, value: object, /) -> int: ... + else: # These are inherited from the Sequence ABC, but don't actually exist on memoryview. # See https://github.com/python/cpython/issues/125420 @@ -1003,6 +1133,7 @@ class slice(Generic[_StartT_co, _StopT_co, _StepT_co]): def __eq__(self, value: object, /) -> bool: ... if sys.version_info >= (3, 12): def __hash__(self) -> int: ... + else: __hash__: ClassVar[None] # type: ignore[assignment] @@ -1077,6 +1208,7 @@ class function: closure: tuple[CellType, ...] | None = None, kwdefaults: dict[str, object] | None = None, ) -> Self: ... + else: def __new__( cls, @@ -1228,27 +1360,15 @@ class dict(MutableMapping[_KT, _VT]): __hash__: ClassVar[None] # type: ignore[assignment] def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... if sys.version_info >= (3, 15): - @overload - def __or__(self, value: dict[_KT, _VT] | frozendict[_KT, _VT], /) -> dict[_KT, _VT]: ... - @overload def __or__(self, value: dict[_T1, _T2] | frozendict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ... - @overload - def __ror__(self, value: dict[_KT, _VT], /) -> dict[_KT, _VT]: ... @overload def __ror__(self, value: dict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ... @overload - def __ror__(self, value: frozendict[_KT, _VT], /) -> frozendict[_KT, _VT]: ... - @overload def __ror__(self, value: frozendict[_T1, _T2], /) -> frozendict[_KT | _T1, _VT | _T2]: ... + else: - @overload - def __or__(self, value: dict[_KT, _VT], /) -> dict[_KT, _VT]: ... - @overload def __or__(self, value: dict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ... - @overload - def __ror__(self, value: dict[_KT, _VT], /) -> dict[_KT, _VT]: ... - @overload def __ror__(self, value: dict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ... # dict.__ior__ should be kept roughly in line with MutableMapping.update() @@ -1302,18 +1422,11 @@ if sys.version_info >= (3, 15): def __iter__(self) -> Iterator[_KT]: ... def __hash__(self) -> int: ... def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... - @overload - def __or__(self, value: dict[_KT, _VT] | frozendict[_KT, _VT], /) -> frozendict[_KT, _VT]: ... - @overload def __or__(self, value: dict[_T1, _T2] | frozendict[_T1, _T2], /) -> frozendict[_KT | _T1, _VT | _T2]: ... - @overload - def __ror__(self, value: dict[_KT, _VT], /) -> dict[_KT, _VT]: ... @overload def __ror__(self, value: dict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ... @overload - def __ror__(self, value: frozendict[_KT, _VT], /) -> frozendict[_KT, _VT]: ... - @overload def __ror__(self, value: frozendict[_T1, _T2], /) -> frozendict[_KT | _T1, _VT | _T2]: ... @disjoint_base @@ -1388,7 +1501,7 @@ class frozenset(AbstractSet[_T_co]): def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... @disjoint_base -class enumerate(Iterator[tuple[int, _T]]): +class enumerate(Generic[_T]): def __new__(cls, iterable: Iterable[_T], start: int = 0) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> tuple[int, _T]: ... @@ -1654,7 +1767,7 @@ else: exit: _sitebuiltins.Quitter @disjoint_base -class filter(Iterator[_T]): +class filter(Generic[_T]): @overload def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ... @overload @@ -1725,7 +1838,7 @@ license: _sitebuiltins._Printer def locals() -> dict[str, Any]: ... @disjoint_base -class map(Iterator[_S]): +class map(Generic[_S]): # 3.14 adds `strict` argument. if sys.version_info >= (3, 14): @overload @@ -1999,7 +2112,7 @@ _SupportsSomeKindOfPow = ( # noqa: Y026 # TODO: Use TypeAlias once mypy bugs a ) # TODO: `pow(int, int, Literal[0])` fails at runtime, -# but adding a `NoReturn` overload isn't a good solution for expressing that (see #8566). +# but adding a `Never` overload isn't a good solution for expressing that (see #8566). @overload def pow(base: int, exp: int, mod: int) -> int: ... @overload @@ -2040,15 +2153,19 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex quit: _sitebuiltins.Quitter +@type_check_only +class _SupportsReversed(Protocol[_T_co]): + def __reversed__(self) -> _T_co: ... + @disjoint_base -class reversed(Iterator[_T]): +class reversed(Generic[_T_co]): @overload - def __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T]: ... # type: ignore[misc] + def __new__(cls, sequence: _SupportsReversed[_T], /) -> _T: ... # type: ignore[misc] @overload - def __new__(cls, sequence: SupportsLenAndGetItem[_T], /) -> Iterator[_T]: ... # type: ignore[misc] + def __new__(cls, sequence: SupportsLenAndGetItem[_T_co], /) -> Self: ... def __iter__(self) -> Self: ... - def __next__(self) -> _T: ... + def __next__(self) -> _T_co: ... def __length_hint__(self) -> int: ... def repr(obj: object, /) -> str: ... @@ -2107,7 +2224,7 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit # without creating many false-positive errors (see #7578). # Instead, we special-case the most common examples of this: bool and literal integers. @overload -def sum(iterable: Iterable[bool], /, start: int = 0) -> int: ... +def sum(iterable: Iterable[bool | _LiteralInteger], /, start: int = 0) -> int: ... @overload def sum(iterable: Iterable[_SupportsSumNoDefaultT], /) -> _SupportsSumNoDefaultT | Literal[0]: ... @overload @@ -2121,7 +2238,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ... def vars(object: Any = ..., /) -> dict[str, Any]: ... @disjoint_base -class zip(Iterator[_T_co]): +class zip(Generic[_T_co]): @overload def __new__(cls, *, strict: bool = False) -> zip[Any]: ... @overload @@ -2201,7 +2318,7 @@ class BaseException: __suppress_context__: bool __traceback__: TracebackType | None def __init__(self, *args: object) -> None: ... - def __new__(cls, *args: Any, **kwds: Any) -> Self: ... + def __new__(cls, /, *args: Any, **kwds: Any) -> Self: ... def __setstate__(self, state: dict[str, Any] | None, /) -> None: ... def with_traceback(self, tb: TracebackType | None, /) -> Self: ... # Necessary for security-focused static analyzers (e.g, pysa) diff --git a/mypy/typeshed/stdlib/codecs.pyi b/mypy/typeshed/stdlib/codecs.pyi index b341d0f813c41..ee1ab25bac47b 100644 --- a/mypy/typeshed/stdlib/codecs.pyi +++ b/mypy/typeshed/stdlib/codecs.pyi @@ -193,7 +193,7 @@ def getincrementaldecoder(encoding: str) -> _IncrementalDecoder: ... def getreader(encoding: str) -> _StreamReader: ... def getwriter(encoding: str) -> _StreamWriter: ... -@deprecated("Deprecated since Python 3.14. Use `open()` instead.") +@deprecated("Deprecated. Use `open()` instead.") def open( filename: str, mode: str = "r", encoding: str | None = None, errors: str = "strict", buffering: int = -1 ) -> StreamReaderWriter: ... diff --git a/mypy/typeshed/stdlib/collections/__init__.pyi b/mypy/typeshed/stdlib/collections/__init__.pyi index 39b8a3c9ab6a5..bea145e424dd2 100644 --- a/mypy/typeshed/stdlib/collections/__init__.pyi +++ b/mypy/typeshed/stdlib/collections/__init__.pyi @@ -14,8 +14,8 @@ from collections.abc import ( ValuesView, ) from types import GenericAlias -from typing import Any, ClassVar, Generic, NoReturn, SupportsIndex, TypeVar, final, overload, type_check_only -from typing_extensions import Self, disjoint_base +from typing import Any, ClassVar, Generic, SupportsIndex, TypeVar, final, overload, type_check_only +from typing_extensions import Never, Self, disjoint_base if sys.version_info >= (3, 15): from builtins import frozendict @@ -277,6 +277,7 @@ class deque(MutableSequence[_T]): def __iadd__(self, value: Iterable[_T], /) -> Self: ... def __add__(self, value: Self, /) -> Self: ... def __mul__(self, value: int, /) -> Self: ... + def __rmul__(self, value: int, /) -> Self: ... def __imul__(self, value: int, /) -> Self: ... def __lt__(self, value: deque[_T], /) -> bool: ... def __le__(self, value: deque[_T], /) -> bool: ... @@ -299,7 +300,7 @@ class Counter(dict[_T, int], Generic[_T]): def elements(self) -> Iterator[_T]: ... def most_common(self, n: int | None = None) -> list[tuple[_T, int]]: ... @classmethod - def fromkeys(cls, iterable: Any, v: int | None = None) -> NoReturn: ... # type: ignore[override] + def fromkeys(cls, iterable: Any, v: int | None = None) -> Never: ... # type: ignore[override] @overload def subtract(self, iterable: None = None, /) -> None: ... diff --git a/mypy/typeshed/stdlib/concurrent/futures/process.pyi b/mypy/typeshed/stdlib/concurrent/futures/process.pyi index 282bafa0b611c..6c7037cc0bbc0 100644 --- a/mypy/typeshed/stdlib/concurrent/futures/process.pyi +++ b/mypy/typeshed/stdlib/concurrent/futures/process.pyi @@ -146,7 +146,12 @@ class _ExecutorManagerThread(Thread): def wait_result_broken_or_wakeup(self) -> tuple[Any, bool, str]: ... def process_result_item(self, result_item: int | _ResultItem) -> None: ... def is_shutting_down(self) -> bool: ... - def terminate_broken(self, cause: str) -> None: ... + + if sys.version_info >= (3, 15): + def terminate_broken(self, cause: str, bpe_message: str | None = None) -> None: ... + else: + def terminate_broken(self, cause: str) -> None: ... + def flag_executor_shutting_down(self) -> None: ... def shutdown_workers(self) -> None: ... def join_executor_internals(self) -> None: ... diff --git a/mypy/typeshed/stdlib/contextlib.pyi b/mypy/typeshed/stdlib/contextlib.pyi index ee577621c720d..dd601675265cc 100644 --- a/mypy/typeshed/stdlib/contextlib.pyi +++ b/mypy/typeshed/stdlib/contextlib.pyi @@ -5,7 +5,7 @@ from abc import ABC, abstractmethod from collections.abc import AsyncGenerator, AsyncIterator, Awaitable, Callable, Generator, Iterator from types import TracebackType from typing import Any, Generic, ParamSpec, Protocol, TypeAlias, TypeVar, overload, runtime_checkable, type_check_only -from typing_extensions import Self +from typing_extensions import Self, deprecated __all__ = [ "aclosing", @@ -84,6 +84,12 @@ class _GeneratorContextManager( self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> bool | None: ... +@overload +def contextmanager(func: Callable[_P, Generator[_T_co, None, object]]) -> Callable[_P, _GeneratorContextManager[_T_co]]: ... +@overload +@deprecated( + "Annotating the return type as `-> Iterator[Foo]` with `@contextmanager` is deprecated. Use `-> Generator[Foo]` instead." +) def contextmanager(func: Callable[_P, Iterator[_T_co]]) -> Callable[_P, _GeneratorContextManager[_T_co]]: ... _AF = TypeVar("_AF", bound=Callable[..., Awaitable[Any]]) @@ -101,6 +107,13 @@ class _AsyncGeneratorContextManager( self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> bool | None: ... +@overload +def asynccontextmanager(func: Callable[_P, AsyncGenerator[_T_co]]) -> Callable[_P, _AsyncGeneratorContextManager[_T_co]]: ... +@overload +@deprecated( + "Annotating the return type as `-> AsyncIterator[Foo]` with `@asynccontextmanager` is deprecated. " + "Use `-> AsyncGenerator[Foo]` instead." +) def asynccontextmanager(func: Callable[_P, AsyncIterator[_T_co]]) -> Callable[_P, _AsyncGeneratorContextManager[_T_co]]: ... @type_check_only diff --git a/mypy/typeshed/stdlib/csv.pyi b/mypy/typeshed/stdlib/csv.pyi index f3b4286a6b495..f8ab5f000a043 100644 --- a/mypy/typeshed/stdlib/csv.pyi +++ b/mypy/typeshed/stdlib/csv.pyi @@ -21,7 +21,7 @@ if sys.version_info >= (3, 12): from _csv import QUOTE_NOTNULL as QUOTE_NOTNULL, QUOTE_STRINGS as QUOTE_STRINGS from _csv import Reader, Writer from _typeshed import SupportsWrite -from collections.abc import Collection, Iterable, Iterator, Mapping, Sequence +from collections.abc import Collection, Iterable, Mapping, Sequence from types import GenericAlias from typing import Any, Generic, Literal, TypeVar, overload from typing_extensions import Self @@ -69,7 +69,7 @@ class excel(Dialect): ... class excel_tab(excel): ... class unix_dialect(Dialect): ... -class DictReader(Iterator[dict[_T | Any, str | Any]], Generic[_T]): +class DictReader(Generic[_T]): fieldnames: Sequence[_T] | None restkey: _T | None restval: str | Any | None diff --git a/mypy/typeshed/stdlib/ctypes/__init__.pyi b/mypy/typeshed/stdlib/ctypes/__init__.pyi index 7eee1b760063f..7760ddf9d8cbd 100644 --- a/mypy/typeshed/stdlib/ctypes/__init__.pyi +++ b/mypy/typeshed/stdlib/ctypes/__init__.pyi @@ -168,10 +168,10 @@ c_buffer = create_string_buffer def create_unicode_buffer(init: int | str, size: int | None = None) -> Array[c_wchar]: ... if sys.version_info < (3, 15): - @deprecated("Deprecated since Python 3.13; will be removed in Python 3.15.") + @deprecated("Deprecated; will be removed in Python 3.15.") def SetPointerType(pointer: type[_Pointer[Any]], cls: _CTypeBaseType) -> None: ... -@deprecated("Soft deprecated since Python 3.13. Use multiplication instead.") +@deprecated("Soft deprecated. Use multiplication instead.") def ARRAY(typ: _CT, len: int) -> Array[_CT]: ... if sys.platform == "win32": diff --git a/mypy/typeshed/stdlib/datetime.pyi b/mypy/typeshed/stdlib/datetime.pyi index 95c62a9c1b712..0a21f72b09de4 100644 --- a/mypy/typeshed/stdlib/datetime.pyi +++ b/mypy/typeshed/stdlib/datetime.pyi @@ -1,8 +1,8 @@ import sys from abc import abstractmethod from time import struct_time -from typing import ClassVar, Final, NoReturn, SupportsIndex, TypeAlias, final, overload, type_check_only -from typing_extensions import CapsuleType, Self, deprecated, disjoint_base +from typing import ClassVar, Final, SupportsIndex, TypeAlias, final, overload, type_check_only +from typing_extensions import CapsuleType, Never, Self, deprecated, disjoint_base if sys.version_info >= (3, 11): __all__ = ("date", "datetime", "time", "timedelta", "timezone", "tzinfo", "MINYEAR", "MAXYEAR", "UTC") @@ -114,7 +114,7 @@ class date: def __radd__(self, value: timedelta, /) -> Self: ... @overload - def __sub__(self, value: datetime, /) -> NoReturn: ... + def __sub__(self, value: datetime, /) -> Never: ... @overload def __sub__(self, value: Self, /) -> timedelta: ... @overload diff --git a/mypy/typeshed/stdlib/decimal.pyi b/mypy/typeshed/stdlib/decimal.pyi index f16fa8aaae31f..f116603cf0f25 100644 --- a/mypy/typeshed/stdlib/decimal.pyi +++ b/mypy/typeshed/stdlib/decimal.pyi @@ -184,7 +184,7 @@ class Context: # even settable attributes like `prec` and `rounding`, # but that's inexpressible in the stub. # Type checkers either ignore it or misinterpret it - # if you add a `def __delattr__(self, name: str, /) -> NoReturn` method to the stub + # if you add a `def __delattr__(self, name: str, /) -> Never` method to the stub prec: int rounding: str Emin: int diff --git a/mypy/typeshed/stdlib/dis.pyi b/mypy/typeshed/stdlib/dis.pyi index 0ad928934671b..984f932e33115 100644 --- a/mypy/typeshed/stdlib/dis.pyi +++ b/mypy/typeshed/stdlib/dis.pyi @@ -2,7 +2,7 @@ import sys import types from collections.abc import Callable, Iterator from opcode import * # `dis` re-exports it as a part of public API -from typing import IO, Any, Final, NamedTuple, overload +from typing import IO, Any, Final, NamedTuple, TypeAlias, overload from typing_extensions import Self, deprecated, disjoint_base __all__ = [ @@ -41,7 +41,7 @@ else: # Strictly this should not have to include Callable, but mypy doesn't use FunctionType # for functions (python/mypy#3171) -_HaveCodeType = types.MethodType | types.FunctionType | types.CodeType | type | Callable[..., Any] +_HaveCodeType: TypeAlias = types.MethodType | types.FunctionType | types.CodeType | type | Callable[..., Any] if sys.version_info >= (3, 11): class Positions(NamedTuple): diff --git a/mypy/typeshed/stdlib/fileinput.pyi b/mypy/typeshed/stdlib/fileinput.pyi index db9c228f5f28e..37783254c70fa 100644 --- a/mypy/typeshed/stdlib/fileinput.pyi +++ b/mypy/typeshed/stdlib/fileinput.pyi @@ -1,8 +1,8 @@ import sys from _typeshed import AnyStr_co, StrOrBytesPath -from collections.abc import Callable, Iterable, Iterator +from collections.abc import Callable, Iterable from types import GenericAlias, TracebackType -from typing import IO, Any, AnyStr, Literal, Protocol, TypeAlias, overload, type_check_only +from typing import IO, Any, AnyStr, Generic, Literal, Protocol, TypeAlias, overload, type_check_only from typing_extensions import Self, deprecated __all__ = [ @@ -74,7 +74,7 @@ def fileno() -> int: ... def isfirstline() -> bool: ... def isstdin() -> bool: ... -class FileInput(Iterator[AnyStr]): +class FileInput(Generic[AnyStr]): # encoding and errors are added @overload def __init__( diff --git a/mypy/typeshed/stdlib/http/cookiejar.pyi b/mypy/typeshed/stdlib/http/cookiejar.pyi index 2cbe432c55866..1bd2fbcbd75df 100644 --- a/mypy/typeshed/stdlib/http/cookiejar.pyi +++ b/mypy/typeshed/stdlib/http/cookiejar.pyi @@ -129,7 +129,7 @@ class Cookie: domain_initial_dot: bool def __init__( self, - version: int | None, + version: int | str | None, name: str, value: str | None, # undocumented port: str | None, @@ -140,7 +140,7 @@ class Cookie: path: str, path_specified: bool, secure: bool, - expires: int | None, + expires: float | str | None, discard: bool, comment: str | None, comment_url: str | None, diff --git a/mypy/typeshed/stdlib/http/server.pyi b/mypy/typeshed/stdlib/http/server.pyi index 88cd2469cf115..6bab228f2ce7e 100644 --- a/mypy/typeshed/stdlib/http/server.pyi +++ b/mypy/typeshed/stdlib/http/server.pyi @@ -128,7 +128,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): def executable(path: StrPath) -> bool: ... # undocumented if sys.version_info < (3, 15): - @deprecated("Deprecated since Python 3.13; will be removed in Python 3.15.") + @deprecated("Deprecated and unsafe; will be removed in Python 3.15.") class CGIHTTPRequestHandler(SimpleHTTPRequestHandler): cgi_directories: list[str] have_fork: bool # undocumented diff --git a/mypy/typeshed/stdlib/imaplib.pyi b/mypy/typeshed/stdlib/imaplib.pyi index fd14e45ed725f..2ed47b18b19c9 100644 --- a/mypy/typeshed/stdlib/imaplib.pyi +++ b/mypy/typeshed/stdlib/imaplib.pyi @@ -84,11 +84,20 @@ class IMAP4: if sys.version_info >= (3, 14): def idle(self, duration: float | None = None) -> Idler: ... - def list(self, directory: str = '""', pattern: str = "*") -> tuple[str, _AnyResponseData]: ... + if sys.version_info >= (3, 15): + def list(self, directory: str = "", pattern: str = "*") -> tuple[str, _AnyResponseData]: ... + else: + def list(self, directory: str = '""', pattern: str = "*") -> tuple[str, _AnyResponseData]: ... + def login(self, user: str, password: str) -> tuple[Literal["OK"], _list[bytes]]: ... def login_cram_md5(self, user: str, password: str) -> _CommandResults: ... def logout(self) -> tuple[str, _AnyResponseData]: ... - def lsub(self, directory: str = '""', pattern: str = "*") -> _CommandResults: ... + + if sys.version_info >= (3, 15): + def lsub(self, directory: str = "", pattern: str = "*") -> _CommandResults: ... + else: + def lsub(self, directory: str = '""', pattern: str = "*") -> _CommandResults: ... + def myrights(self, mailbox: str) -> _CommandResults: ... def namespace(self) -> _CommandResults: ... def noop(self) -> tuple[str, _list[bytes]]: ... @@ -98,7 +107,12 @@ class IMAP4: def search(self, charset: str | None, *criteria: str) -> _CommandResults: ... def select(self, mailbox: str = "INBOX", readonly: bool = False) -> tuple[str, _list[bytes | None]]: ... def setacl(self, mailbox: str, who: str, what: str) -> _CommandResults: ... - def setannotation(self, *args: str) -> _CommandResults: ... + + if sys.version_info >= (3, 15): + def setannotation(self, mailbox: str | bytes, *args: str) -> _CommandResults: ... + else: + def setannotation(self, *args: str) -> _CommandResults: ... + def setquota(self, root: str, limits: str) -> _CommandResults: ... def sort(self, sort_criteria: str, charset: str, *search_criteria: str) -> _CommandResults: ... def starttls(self, ssl_context: Any | None = None) -> tuple[Literal["OK"], _list[None]]: ... diff --git a/mypy/typeshed/stdlib/importlib/readers.pyi b/mypy/typeshed/stdlib/importlib/readers.pyi index 50f06ea5434d5..c02f29d0a7227 100644 --- a/mypy/typeshed/stdlib/importlib/readers.pyi +++ b/mypy/typeshed/stdlib/importlib/readers.pyi @@ -9,7 +9,7 @@ from _typeshed import StrPath from collections.abc import Iterable, Iterator from importlib._bootstrap_external import FileLoader from io import BufferedReader -from typing import Literal, NoReturn, TypeVar +from typing import Literal, TypeVar from typing_extensions import Never from zipimport import zipimporter @@ -43,8 +43,8 @@ class ZipReader(abc.TraversableResources): class MultiplexedPath(abc.Traversable): def __init__(self, *paths: abc.Traversable) -> None: ... def iterdir(self) -> Iterator[abc.Traversable]: ... - def read_bytes(self) -> NoReturn: ... - def read_text(self, *args: Never, **kwargs: Never) -> NoReturn: ... # type: ignore[override] + def read_bytes(self) -> Never: ... + def read_text(self, *args: Never, **kwargs: Never) -> Never: ... # type: ignore[override] def is_dir(self) -> Literal[True]: ... def is_file(self) -> Literal[False]: ... @@ -58,7 +58,7 @@ class MultiplexedPath(abc.Traversable): if sys.version_info < (3, 12): __truediv__ = joinpath - def open(self, *args: Never, **kwargs: Never) -> NoReturn: ... # type: ignore[override] + def open(self, *args: Never, **kwargs: Never) -> Never: ... # type: ignore[override] @property def name(self) -> str: ... diff --git a/mypy/typeshed/stdlib/importlib/resources/__init__.pyi b/mypy/typeshed/stdlib/importlib/resources/__init__.pyi index 5e58ddf310c93..4d3072ffe854b 100644 --- a/mypy/typeshed/stdlib/importlib/resources/__init__.pyi +++ b/mypy/typeshed/stdlib/importlib/resources/__init__.pyi @@ -62,7 +62,7 @@ else: def read_text(package: Package, resource: Resource, encoding: str = "utf-8", errors: str = "strict") -> str: ... def path(package: Package, resource: Resource) -> AbstractContextManager[Path, Literal[False]]: ... def is_resource(package: Package, name: str) -> bool: ... - @deprecated("Deprecated since Python 3.11. Use `files(anchor).iterdir()`.") + @deprecated("Deprecated; limited resource support. Use `files(anchor).iterdir()`.") def contents(package: Package) -> Iterator[str]: ... if sys.version_info >= (3, 11): diff --git a/mypy/typeshed/stdlib/importlib/resources/abc.pyi b/mypy/typeshed/stdlib/importlib/resources/abc.pyi index 20a4b1fc5dfef..fd604997ff4a0 100644 --- a/mypy/typeshed/stdlib/importlib/resources/abc.pyi +++ b/mypy/typeshed/stdlib/importlib/resources/abc.pyi @@ -7,7 +7,7 @@ from typing import IO, Any, Literal, Protocol, overload, runtime_checkable from typing_extensions import deprecated if sys.version_info >= (3, 11): - @deprecated("Deprecated since Python 3.12. Use `importlib.resources.abc.TraversableResources` instead.") + @deprecated("Deprecated. Use `importlib.resources.abc.TraversableResources` instead.") class ResourceReader(metaclass=ABCMeta): @abstractmethod def open_resource(self, resource: str) -> IO[bytes]: ... diff --git a/mypy/typeshed/stdlib/importlib/resources/simple.pyi b/mypy/typeshed/stdlib/importlib/resources/simple.pyi index ef9882056a9c2..933a6ff164dfe 100644 --- a/mypy/typeshed/stdlib/importlib/resources/simple.pyi +++ b/mypy/typeshed/stdlib/importlib/resources/simple.pyi @@ -3,7 +3,7 @@ import sys from _typeshed import StrPath from collections.abc import Iterator from io import TextIOWrapper -from typing import IO, Any, BinaryIO, Literal, NoReturn, overload +from typing import IO, Any, BinaryIO, Literal, overload from typing_extensions import Never if sys.version_info >= (3, 11): @@ -43,7 +43,7 @@ if sys.version_info >= (3, 11): @overload def open(self, mode: str) -> IO[Any]: ... - def joinpath(self, name: Never) -> NoReturn: ... # type: ignore[override] + def joinpath(self, name: Never) -> Never: ... # type: ignore[override] class ResourceContainer(Traversable, metaclass=abc.ABCMeta): reader: SimpleReader @@ -51,7 +51,7 @@ if sys.version_info >= (3, 11): def is_dir(self) -> Literal[True]: ... def is_file(self) -> Literal[False]: ... def iterdir(self) -> Iterator[ResourceHandle | ResourceContainer]: ... - def open(self, *args: Never, **kwargs: Never) -> NoReturn: ... # type: ignore[override] + def open(self, *args: Never, **kwargs: Never) -> Never: ... # type: ignore[override] if sys.version_info < (3, 12): def joinpath(self, *descendants: StrPath) -> Traversable: ... diff --git a/mypy/typeshed/stdlib/inspect.pyi b/mypy/typeshed/stdlib/inspect.pyi index 1bd2b9dee325b..c3110ce28d8ea 100644 --- a/mypy/typeshed/stdlib/inspect.pyi +++ b/mypy/typeshed/stdlib/inspect.pyi @@ -195,8 +195,8 @@ if sys.version_info >= (3, 14): modulesbyfile: dict[str, Any] -_GetMembersPredicateTypeGuard = Callable[[Any], TypeGuard[_T]] -_GetMembersPredicateTypeIs = Callable[[Any], TypeIs[_T]] +_GetMembersPredicateTypeGuard: TypeAlias = Callable[[Any], TypeGuard[_T]] +_GetMembersPredicateTypeIs: TypeAlias = Callable[[Any], TypeIs[_T]] _GetMembersPredicate: TypeAlias = Callable[[Any], bool] _GetMembersReturn: TypeAlias = list[tuple[str, _T]] diff --git a/mypy/typeshed/stdlib/itertools.pyi b/mypy/typeshed/stdlib/itertools.pyi index fd7daf11e8086..d26a4e1da21e4 100644 --- a/mypy/typeshed/stdlib/itertools.pyi +++ b/mypy/typeshed/stdlib/itertools.pyi @@ -23,12 +23,12 @@ _T10 = TypeVar("_T10") _Step: TypeAlias = SupportsFloat | SupportsInt | SupportsIndex | SupportsComplex -_Predicate = Callable[[_T], object] +_Predicate: TypeAlias = Callable[[_T], object] # Technically count can take anything that implements a number protocol and has an add method # but we can't enforce the add method @disjoint_base -class count(Iterator[_N]): +class count(Generic[_N]): @overload def __new__(cls) -> count[int]: ... @overload @@ -40,13 +40,13 @@ class count(Iterator[_N]): def __iter__(self) -> Self: ... @disjoint_base -class cycle(Iterator[_T]): +class cycle(Generic[_T]): def __new__(cls, iterable: Iterable[_T], /) -> Self: ... def __next__(self) -> _T: ... def __iter__(self) -> Self: ... @disjoint_base -class repeat(Iterator[_T]): +class repeat(Generic[_T]): @overload def __new__(cls, object: _T) -> Self: ... @overload @@ -57,7 +57,7 @@ class repeat(Iterator[_T]): def __length_hint__(self) -> int: ... @disjoint_base -class accumulate(Iterator[_T]): +class accumulate(Generic[_T]): @overload def __new__(cls, iterable: Iterable[_T], func: None = None, *, initial: _T | None = None) -> Self: ... @overload @@ -67,7 +67,7 @@ class accumulate(Iterator[_T]): def __next__(self) -> _T: ... @disjoint_base -class chain(Iterator[_T]): +class chain(Generic[_T]): def __new__(cls, *iterables: Iterable[_T]) -> Self: ... def __next__(self) -> _T: ... def __iter__(self) -> Self: ... @@ -77,25 +77,25 @@ class chain(Iterator[_T]): def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... @disjoint_base -class compress(Iterator[_T]): +class compress(Generic[_T]): def __new__(cls, data: Iterable[_T], selectors: Iterable[Any]) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> _T: ... @disjoint_base -class dropwhile(Iterator[_T]): +class dropwhile(Generic[_T]): def __new__(cls, predicate: _Predicate[_T], iterable: Iterable[_T], /) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> _T: ... @disjoint_base -class filterfalse(Iterator[_T]): +class filterfalse(Generic[_T]): def __new__(cls, function: _Predicate[_T] | None, iterable: Iterable[_T], /) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> _T: ... @disjoint_base -class groupby(Iterator[tuple[_T_co, Iterator[_S_co]]], Generic[_T_co, _S_co]): +class groupby(Generic[_T_co, _S_co]): @overload def __new__(cls, iterable: Iterable[_T1], key: None = None) -> groupby[_T1, _T1]: ... @overload @@ -105,7 +105,7 @@ class groupby(Iterator[tuple[_T_co, Iterator[_S_co]]], Generic[_T_co, _S_co]): def __next__(self) -> tuple[_T_co, Iterator[_S_co]]: ... @disjoint_base -class islice(Iterator[_T]): +class islice(Generic[_T]): @overload def __new__(cls, iterable: Iterable[_T], stop: int | None, /) -> Self: ... @overload @@ -115,13 +115,13 @@ class islice(Iterator[_T]): def __next__(self) -> _T: ... @disjoint_base -class starmap(Iterator[_T_co]): +class starmap(Generic[_T_co]): def __new__(cls, function: Callable[..., _T], iterable: Iterable[Iterable[Any]], /) -> starmap[_T]: ... def __iter__(self) -> Self: ... def __next__(self) -> _T_co: ... @disjoint_base -class takewhile(Iterator[_T]): +class takewhile(Generic[_T]): def __new__(cls, predicate: _Predicate[_T], iterable: Iterable[_T], /) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> _T: ... @@ -129,7 +129,7 @@ class takewhile(Iterator[_T]): def tee(iterable: Iterable[_T], n: int = 2, /) -> tuple[Iterator[_T], ...]: ... @disjoint_base -class zip_longest(Iterator[_T_co]): +class zip_longest(Generic[_T_co]): # one iterable (fillvalue doesn't matter) @overload def __new__(cls, iter1: Iterable[_T1], /, *, fillvalue: object = None) -> zip_longest[tuple[_T1]]: ... @@ -209,7 +209,7 @@ class zip_longest(Iterator[_T_co]): def __next__(self) -> _T_co: ... @disjoint_base -class product(Iterator[_T_co]): +class product(Generic[_T_co]): @overload def __new__(cls, iter1: Iterable[_T1], /) -> product[tuple[_T1]]: ... @overload @@ -296,7 +296,7 @@ class product(Iterator[_T_co]): def __next__(self) -> _T_co: ... @disjoint_base -class permutations(Iterator[_T_co]): +class permutations(Generic[_T_co]): @overload def __new__(cls, iterable: Iterable[_T], r: Literal[2]) -> permutations[tuple[_T, _T]]: ... @overload @@ -312,7 +312,7 @@ class permutations(Iterator[_T_co]): def __next__(self) -> _T_co: ... @disjoint_base -class combinations(Iterator[_T_co]): +class combinations(Generic[_T_co]): @overload def __new__(cls, iterable: Iterable[_T], r: Literal[2]) -> combinations[tuple[_T, _T]]: ... @overload @@ -328,7 +328,7 @@ class combinations(Iterator[_T_co]): def __next__(self) -> _T_co: ... @disjoint_base -class combinations_with_replacement(Iterator[_T_co]): +class combinations_with_replacement(Generic[_T_co]): @overload def __new__(cls, iterable: Iterable[_T], r: Literal[2]) -> combinations_with_replacement[tuple[_T, _T]]: ... @overload @@ -344,14 +344,14 @@ class combinations_with_replacement(Iterator[_T_co]): def __next__(self) -> _T_co: ... @disjoint_base -class pairwise(Iterator[_T_co]): +class pairwise(Generic[_T_co]): def __new__(cls, iterable: Iterable[_T], /) -> pairwise[tuple[_T, _T]]: ... def __iter__(self) -> Self: ... def __next__(self) -> _T_co: ... if sys.version_info >= (3, 12): @disjoint_base - class batched(Iterator[_T_co], Generic[_T_co]): + class batched(Generic[_T_co]): if sys.version_info >= (3, 13): @overload def __new__(cls, iterable: Iterable[_T], n: Literal[1], *, strict: Literal[True]) -> batched[tuple[_T]]: ... diff --git a/mypy/typeshed/stdlib/lib2to3/pgen2/pgen.pyi b/mypy/typeshed/stdlib/lib2to3/pgen2/pgen.pyi index 4b951e1489e15..e0e2b8593a343 100644 --- a/mypy/typeshed/stdlib/lib2to3/pgen2/pgen.pyi +++ b/mypy/typeshed/stdlib/lib2to3/pgen2/pgen.pyi @@ -1,6 +1,7 @@ from _typeshed import Incomplete, StrPath from collections.abc import Iterable, Iterator -from typing import IO, ClassVar, NoReturn, overload +from typing import IO, ClassVar, overload +from typing_extensions import Never from . import grammar from .tokenize import _TokenInfo @@ -31,9 +32,9 @@ class ParserGenerator: def gettoken(self) -> None: ... @overload - def raise_error(self, msg: object) -> NoReturn: ... + def raise_error(self, msg: object) -> Never: ... @overload - def raise_error(self, msg: str, *args: object) -> NoReturn: ... + def raise_error(self, msg: str, *args: object) -> Never: ... class NFAState: arcs: list[tuple[str | None, NFAState]] diff --git a/mypy/typeshed/stdlib/lib2to3/pytree.pyi b/mypy/typeshed/stdlib/lib2to3/pytree.pyi index 045f7882721a1..f634f5065c0e5 100644 --- a/mypy/typeshed/stdlib/lib2to3/pytree.pyi +++ b/mypy/typeshed/stdlib/lib2to3/pytree.pyi @@ -1,4 +1,4 @@ -from _typeshed import Incomplete, SupportsGetItem, SupportsLenAndGetItem, Unused +from _typeshed import SupportsGetItem, SupportsLenAndGetItem, Unused from abc import abstractmethod from collections.abc import Iterable, Iterator, MutableSequence from typing import ClassVar, Final, TypeAlias @@ -48,7 +48,7 @@ class Base: class Node(Base): fixers_applied: MutableSequence[BaseFix] | None # Is Unbound until set in refactor.RefactoringTool - future_features: frozenset[Incomplete] + future_features: frozenset[str] # Is Unbound until set in pgen2.parse.Parser.pop used_names: set[str] def __init__( diff --git a/mypy/typeshed/stdlib/lib2to3/refactor.pyi b/mypy/typeshed/stdlib/lib2to3/refactor.pyi index dfec28b758b5d..b365d64a1de1a 100644 --- a/mypy/typeshed/stdlib/lib2to3/refactor.pyi +++ b/mypy/typeshed/stdlib/lib2to3/refactor.pyi @@ -3,7 +3,8 @@ from collections.abc import Container, Generator, Iterable, Mapping from logging import Logger, _ExcInfoType from multiprocessing import JoinableQueue from multiprocessing.synchronize import Lock -from typing import Any, ClassVar, Final, NoReturn, overload +from typing import Any, ClassVar, Final, overload +from typing_extensions import Never from .btm_matcher import BottomMatcher from .fixer_base import BaseFix @@ -39,7 +40,7 @@ class RefactoringTool: self, fixer_names: Iterable[str], options: Mapping[str, object] | None = None, explicit: Container[str] | None = None ) -> None: ... def get_fixers(self) -> tuple[list[BaseFix], list[BaseFix]]: ... - def log_error(self, msg: str, *args: Iterable[str], **kwargs: _ExcInfoType) -> NoReturn: ... + def log_error(self, msg: str, *args: Iterable[str], **kwargs: _ExcInfoType) -> Never: ... @overload def log_message(self, msg: object) -> None: ... diff --git a/mypy/typeshed/stdlib/locale.pyi b/mypy/typeshed/stdlib/locale.pyi index 1be68ec516344..d234a08d779cf 100644 --- a/mypy/typeshed/stdlib/locale.pyi +++ b/mypy/typeshed/stdlib/locale.pyi @@ -138,7 +138,7 @@ def getpreferredencoding(do_setlocale: bool = True) -> _str: ... def normalize(localename: _str) -> _str: ... if sys.version_info < (3, 13): - @deprecated("Deprecated since Python 3.11; removed in Python 3.13. Use `locale.setlocale(locale.LC_ALL, '')` instead.") + @deprecated("Deprecated; removed in Python 3.13. Use `locale.setlocale(locale.LC_ALL, '')` instead.") def resetlocale(category: int = ...) -> None: ... if sys.version_info < (3, 12): diff --git a/mypy/typeshed/stdlib/logging/__init__.pyi b/mypy/typeshed/stdlib/logging/__init__.pyi index 8e90a68d9453c..39bd64694a1e1 100644 --- a/mypy/typeshed/stdlib/logging/__init__.pyi +++ b/mypy/typeshed/stdlib/logging/__init__.pyi @@ -245,7 +245,7 @@ NOTSET: Final = 0 class Handler(Filterer): level: int # undocumented formatter: Formatter | None # undocumented - lock: threading.Lock | None # undocumented + lock: threading.RLock | None # undocumented name: str | None # undocumented def __init__(self, level: _Level = 0) -> None: ... def get_name(self) -> str: ... # undocumented diff --git a/mypy/typeshed/stdlib/math/__init__.pyi b/mypy/typeshed/stdlib/math/__init__.pyi index 4839bf7e90df1..b11324c4ae9ac 100644 --- a/mypy/typeshed/stdlib/math/__init__.pyi +++ b/mypy/typeshed/stdlib/math/__init__.pyi @@ -90,7 +90,7 @@ def isqrt(n: SupportsIndex, /) -> int: ... def lcm(*integers: SupportsIndex) -> int: ... def ldexp(x: _SupportsFloatOrIndex, i: int, /) -> float: ... def lgamma(x: _SupportsFloatOrIndex, /) -> float: ... -def log(x: _SupportsFloatOrIndex, base: _SupportsFloatOrIndex = ...) -> float: ... +def log(x: _SupportsFloatOrIndex, base: _SupportsFloatOrIndex = ..., /) -> float: ... def log10(x: _SupportsFloatOrIndex, /) -> float: ... def log1p(x: _SupportsFloatOrIndex, /) -> float: ... def log2(x: _SupportsFloatOrIndex, /) -> float: ... diff --git a/mypy/typeshed/stdlib/mmap.pyi b/mypy/typeshed/stdlib/mmap.pyi index 587b91d86c084..7aedd6711b01a 100644 --- a/mypy/typeshed/stdlib/mmap.pyi +++ b/mypy/typeshed/stdlib/mmap.pyi @@ -2,8 +2,8 @@ import os import sys from _typeshed import ReadableBuffer, Unused from collections.abc import Iterator -from typing import Final, Literal, NoReturn, SupportsIndex, overload -from typing_extensions import Self, disjoint_base +from typing import Final, Literal, SupportsIndex, overload +from typing_extensions import Never, Self, disjoint_base ACCESS_DEFAULT: Final = 0 ACCESS_READ: Final = 1 @@ -113,7 +113,7 @@ class mmap: @overload def __getitem__(self, key: slice[SupportsIndex | None], /) -> bytes: ... - def __delitem__(self, key: SupportsIndex | slice[SupportsIndex | None], /) -> NoReturn: ... + def __delitem__(self, key: SupportsIndex | slice[SupportsIndex | None], /) -> Never: ... @overload def __setitem__(self, key: SupportsIndex, value: int, /) -> None: ... diff --git a/mypy/typeshed/stdlib/multiprocessing/pool.pyi b/mypy/typeshed/stdlib/multiprocessing/pool.pyi index 203c5887ca7ee..5642e50d0e768 100644 --- a/mypy/typeshed/stdlib/multiprocessing/pool.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/pool.pyi @@ -1,4 +1,4 @@ -from collections.abc import Callable, Iterable, Iterator, Mapping +from collections.abc import Callable, Iterable, Mapping from multiprocessing.context import DefaultContext, Process as _Process from types import GenericAlias, TracebackType from typing import Any, Final, Generic, TypeVar @@ -32,7 +32,7 @@ class MapResult(ApplyResult[list[_T]]): error_callback: Callable[[BaseException], object] | None, ) -> None: ... -class IMapIterator(Iterator[_T]): +class IMapIterator(Generic[_T]): def __init__(self, pool: Pool) -> None: ... def __iter__(self) -> Self: ... def next(self, timeout: float | None = None) -> _T: ... diff --git a/mypy/typeshed/stdlib/nturl2path.pyi b/mypy/typeshed/stdlib/nturl2path.pyi index 98686ed65420f..3871f263f4e37 100644 --- a/mypy/typeshed/stdlib/nturl2path.pyi +++ b/mypy/typeshed/stdlib/nturl2path.pyi @@ -1,6 +1,6 @@ from typing_extensions import deprecated -@deprecated("The `nturl2path` module is deprecated since Python 3.14.") +@deprecated("Deprecated; use `urllib.request` file-URL helpers instead.") def url2pathname(url: str) -> str: ... -@deprecated("The `nturl2path` module is deprecated since Python 3.14.") +@deprecated("Deprecated; use `urllib.request` file-URL helpers instead.") def pathname2url(p: str) -> str: ... diff --git a/mypy/typeshed/stdlib/optparse.pyi b/mypy/typeshed/stdlib/optparse.pyi index 9e5536610272e..35dfc54a9d498 100644 --- a/mypy/typeshed/stdlib/optparse.pyi +++ b/mypy/typeshed/stdlib/optparse.pyi @@ -2,8 +2,8 @@ import builtins from _typeshed import MaybeNone, SupportsWrite from abc import abstractmethod from collections.abc import Callable, Iterable, Mapping, Sequence -from typing import Any, ClassVar, Final, Literal, NoReturn, overload -from typing_extensions import Self +from typing import Any, ClassVar, Final, Literal, overload +from typing_extensions import Never, Self __all__ = [ "Option", @@ -291,8 +291,8 @@ class OptionParser(OptionContainer): def check_values(self, values: Values, args: list[str]) -> tuple[Values, list[str]]: ... def disable_interspersed_args(self) -> None: ... def enable_interspersed_args(self) -> None: ... - def error(self, msg: str) -> NoReturn: ... - def exit(self, status: int = 0, msg: str | None = None) -> NoReturn: ... + def error(self, msg: str) -> Never: ... + def exit(self, status: int = 0, msg: str | None = None) -> Never: ... def expand_prog_name(self, s: str) -> str: ... def format_epilog(self, formatter: HelpFormatter) -> str: ... def format_help(self, formatter: HelpFormatter | None = None) -> str: ... diff --git a/mypy/typeshed/stdlib/os/__init__.pyi b/mypy/typeshed/stdlib/os/__init__.pyi index 00c155956fb01..5f99c35132ed8 100644 --- a/mypy/typeshed/stdlib/os/__init__.pyi +++ b/mypy/typeshed/stdlib/os/__init__.pyi @@ -33,7 +33,6 @@ from typing import ( Final, Generic, Literal, - NoReturn, Protocol, TypeAlias, TypeVar, @@ -42,7 +41,7 @@ from typing import ( runtime_checkable, type_check_only, ) -from typing_extensions import LiteralString, Self, Unpack, deprecated +from typing_extensions import LiteralString, Never, Self, Unpack, deprecated from . import path as _path @@ -1471,19 +1470,17 @@ if sys.platform != "win32": follow_symlinks: bool = True, ) -> None: ... -def abort() -> NoReturn: ... +def abort() -> Never: ... # These are defined as execl(file, *args) but the first *arg is mandatory. -def execl(file: StrOrBytesPath, *args: Unpack[tuple[StrOrBytesPath, Unpack[tuple[StrOrBytesPath, ...]]]]) -> NoReturn: ... -def execlp(file: StrOrBytesPath, *args: Unpack[tuple[StrOrBytesPath, Unpack[tuple[StrOrBytesPath, ...]]]]) -> NoReturn: ... +def execl(file: StrOrBytesPath, *args: Unpack[tuple[StrOrBytesPath, Unpack[tuple[StrOrBytesPath, ...]]]]) -> Never: ... +def execlp(file: StrOrBytesPath, *args: Unpack[tuple[StrOrBytesPath, Unpack[tuple[StrOrBytesPath, ...]]]]) -> Never: ... # These are: execle(file, *args, env) but env is pulled from the last element of the args. -def execle( - file: StrOrBytesPath, *args: Unpack[tuple[StrOrBytesPath, Unpack[tuple[StrOrBytesPath, ...]], _ExecEnv]] -) -> NoReturn: ... +def execle(file: StrOrBytesPath, *args: Unpack[tuple[StrOrBytesPath, Unpack[tuple[StrOrBytesPath, ...]], _ExecEnv]]) -> Never: ... def execlpe( file: StrOrBytesPath, *args: Unpack[tuple[StrOrBytesPath, Unpack[tuple[StrOrBytesPath, ...]], _ExecEnv]] -) -> NoReturn: ... +) -> Never: ... # The docs say `args: tuple or list of strings` # The implementation enforces tuple or list so we can't use Sequence. @@ -1506,11 +1503,11 @@ _ExecVArgs: TypeAlias = ( # we limit to str | bytes. _ExecEnv: TypeAlias = Mapping[bytes, bytes | str] | Mapping[str, bytes | str] -def execv(path: StrOrBytesPath, argv: _ExecVArgs, /) -> NoReturn: ... -def execve(path: FileDescriptorOrPath, argv: _ExecVArgs, env: _ExecEnv) -> NoReturn: ... -def execvp(file: StrOrBytesPath, args: _ExecVArgs) -> NoReturn: ... -def execvpe(file: StrOrBytesPath, args: _ExecVArgs, env: _ExecEnv) -> NoReturn: ... -def _exit(status: int) -> NoReturn: ... +def execv(path: StrOrBytesPath, argv: _ExecVArgs, /) -> Never: ... +def execve(path: FileDescriptorOrPath, argv: _ExecVArgs, env: _ExecEnv) -> Never: ... +def execvp(file: StrOrBytesPath, args: _ExecVArgs) -> Never: ... +def execvpe(file: StrOrBytesPath, args: _ExecVArgs, env: _ExecEnv) -> Never: ... +def _exit(status: int) -> Never: ... def kill(pid: int, signal: int, /) -> None: ... if sys.platform != "win32": diff --git a/mypy/typeshed/stdlib/pathlib/__init__.pyi b/mypy/typeshed/stdlib/pathlib/__init__.pyi index ca0d41f649583..fa011e6097a4a 100644 --- a/mypy/typeshed/stdlib/pathlib/__init__.pyi +++ b/mypy/typeshed/stdlib/pathlib/__init__.pyi @@ -94,7 +94,7 @@ class PurePath(PathLike[str]): def __rtruediv__(self, key: StrPath) -> Self: ... def __bytes__(self) -> bytes: ... def as_posix(self) -> str: ... - @deprecated("Deprecated since Python 3.14; will be removed in Python 3.19. Use `Path.as_uri()` instead.") + @deprecated("Deprecated; will be removed in Python 3.19. Use `Path.as_uri()` instead.") def as_uri(self) -> str: ... def is_absolute(self) -> bool: ... if sys.version_info < (3, 15): @@ -112,7 +112,7 @@ class PurePath(PathLike[str]): @overload def is_relative_to(self, other: StrPath, /) -> bool: ... @overload - @deprecated("Passing additional arguments is deprecated since Python 3.12; removed in Python 3.14.") + @deprecated("Passing additional arguments is deprecated; removed in Python 3.14.") def is_relative_to(self, other: StrPath, /, *_deprecated: StrPath) -> bool: ... if sys.version_info >= (3, 12): diff --git a/mypy/typeshed/stdlib/pkgutil.pyi b/mypy/typeshed/stdlib/pkgutil.pyi index 365792bed9528..6fdb01e728f44 100644 --- a/mypy/typeshed/stdlib/pkgutil.pyi +++ b/mypy/typeshed/stdlib/pkgutil.pyi @@ -39,9 +39,9 @@ if sys.version_info < (3, 12): def __init__(self, fullname: str, file: IO[str], filename: StrOrBytesPath, etc: tuple[str, str, int]) -> None: ... if sys.version_info < (3, 14): - @deprecated("Deprecated since Python 3.12; removed in Python 3.14. Use `importlib.util.find_spec()` instead.") + @deprecated("Deprecated; removed in Python 3.14. Use `importlib.util.find_spec()` instead.") def find_loader(fullname: str) -> LoaderProtocol | None: ... - @deprecated("Deprecated since Python 3.12; removed in Python 3.14. Use `importlib.util.find_spec()` instead.") + @deprecated("Deprecated; removed in Python 3.14. Use `importlib.util.find_spec()` instead.") def get_loader(module_or_name: str) -> LoaderProtocol | None: ... def get_importer(path_item: StrOrBytesPath) -> PathEntryFinderProtocol | None: ... diff --git a/mypy/typeshed/stdlib/platform.pyi b/mypy/typeshed/stdlib/platform.pyi index 07100d3bd592d..b262186a68e41 100644 --- a/mypy/typeshed/stdlib/platform.pyi +++ b/mypy/typeshed/stdlib/platform.pyi @@ -11,7 +11,7 @@ def mac_ver( ) -> tuple[str, tuple[str, str, str], str]: ... if sys.version_info < (3, 15): - @deprecated("Deprecated since Python 3.13; will be removed in Python 3.15.") + @deprecated("Deprecated; will be removed in Python 3.15.") def java_ver( release: str = "", vendor: str = "", diff --git a/mypy/typeshed/stdlib/poplib.pyi b/mypy/typeshed/stdlib/poplib.pyi index d4555a6b5ec0c..59d95c0882f10 100644 --- a/mypy/typeshed/stdlib/poplib.pyi +++ b/mypy/typeshed/stdlib/poplib.pyi @@ -4,8 +4,8 @@ import sys from _typeshed import StrOrBytesPath from builtins import list as _list # conflicts with a method named "list" from re import Pattern -from typing import Any, BinaryIO, Final, NoReturn, TypeAlias, overload -from typing_extensions import deprecated +from typing import Any, BinaryIO, Final, TypeAlias, overload +from typing_extensions import Never, deprecated __all__ = ["POP3", "error_proto", "POP3_SSL"] @@ -59,7 +59,7 @@ class POP3_SSL(POP3): def __init__( self, host: str, port: int = 995, *, timeout: float = ..., context: ssl.SSLContext | None = None ) -> None: ... - def stls(self, context: Any = None) -> NoReturn: ... + def stls(self, context: Any = None) -> Never: ... else: @overload def __init__( @@ -90,4 +90,4 @@ class POP3_SSL(POP3): certfile: StrOrBytesPath | None # "context" is actually the last argument, # but that breaks LSP and it doesn't really matter because all the arguments are ignored - def stls(self, context: Any = None, keyfile: Any = None, certfile: Any = None) -> NoReturn: ... + def stls(self, context: Any = None, keyfile: Any = None, certfile: Any = None) -> Never: ... diff --git a/mypy/typeshed/stdlib/pty.pyi b/mypy/typeshed/stdlib/pty.pyi index e74c02ab1e1e6..2bb48d782de64 100644 --- a/mypy/typeshed/stdlib/pty.pyi +++ b/mypy/typeshed/stdlib/pty.pyi @@ -15,9 +15,9 @@ if sys.platform != "win32": def openpty() -> tuple[int, int]: ... if sys.version_info < (3, 14): - @deprecated("Deprecated since Python 3.12; removed in Python 3.14. Use `openpty()` instead.") + @deprecated("Deprecated; removed in Python 3.14. Use `openpty()` instead.") def master_open() -> tuple[int, str]: ... - @deprecated("Deprecated since Python 3.12; removed in Python 3.14. Use `openpty()` instead.") + @deprecated("Deprecated; removed in Python 3.14. Use `openpty()` instead.") def slave_open(tty_name: str) -> int: ... def fork() -> tuple[int, int]: ... diff --git a/mypy/typeshed/stdlib/pydoc.pyi b/mypy/typeshed/stdlib/pydoc.pyi index 2e423dd3d425e..34b2e656f4352 100644 --- a/mypy/typeshed/stdlib/pydoc.pyi +++ b/mypy/typeshed/stdlib/pydoc.pyi @@ -5,8 +5,8 @@ from builtins import list as _list # "list" conflicts with method name from collections.abc import Callable, Container, Mapping, MutableMapping from reprlib import Repr from types import MethodType, ModuleType, TracebackType -from typing import IO, Any, AnyStr, Final, NoReturn, Protocol, TypeGuard, TypeVar, overload, type_check_only -from typing_extensions import deprecated +from typing import IO, Any, AnyStr, Final, Protocol, TypeGuard, TypeVar, overload, type_check_only +from typing_extensions import Never, deprecated __all__ = ["help"] @@ -32,7 +32,7 @@ def stripid(text: str) -> str: ... def allmethods(cl: type) -> MutableMapping[str, MethodType]: ... def visiblename(name: str, all: Container[str] | None = None, obj: object = None) -> bool: ... def classify_class_attrs(object: object) -> list[tuple[str, str, type, str]]: ... -@deprecated("Deprecated since Python 3.13.") +@deprecated("Deprecated.") def ispackage(path: StrPath) -> bool: ... # undocumented def source_synopsis(file: IO[AnyStr]) -> AnyStr | None: ... def synopsis(filename: str, cache: MutableMapping[str, tuple[int, str]] = {}) -> str | None: ... @@ -60,7 +60,7 @@ class Doc: STDLIB_DIR: str def document(self, object: object, name: str | None = None, *args: Any) -> str: ... - def fail(self, object: object, name: str | None = None, *args: Any) -> NoReturn: ... + def fail(self, object: object, name: str | None = None, *args: Any) -> Never: ... @abstractmethod def docmodule(self, object: object, name: str | None = None, *args: Any) -> str: ... @abstractmethod diff --git a/mypy/typeshed/stdlib/random.pyi b/mypy/typeshed/stdlib/random.pyi index 80fd2c7628a52..c70c8364684cb 100644 --- a/mypy/typeshed/stdlib/random.pyi +++ b/mypy/typeshed/stdlib/random.pyi @@ -3,8 +3,8 @@ import sys from _typeshed import SupportsLenAndGetItem from collections.abc import Callable, Iterable, MutableSequence, Sequence, Set as AbstractSet from fractions import Fraction -from typing import Any, ClassVar, NoReturn, TypeVar, overload -from typing_extensions import deprecated +from typing import Any, ClassVar, TypeVar, overload +from typing_extensions import Never, deprecated __all__ = [ "Random", @@ -104,8 +104,8 @@ class Random(_random.Random): # SystemRandom is not implemented for all OS's; good on Windows & Linux class SystemRandom(Random): def getrandbits(self, k: int) -> int: ... # k can be passed by keyword - def getstate(self, *args: Any, **kwds: Any) -> NoReturn: ... - def setstate(self, *args: Any, **kwds: Any) -> NoReturn: ... + def getstate(self, *args: Any, **kwds: Any) -> Never: ... + def setstate(self, *args: Any, **kwds: Any) -> Never: ... _inst: Random seed = _inst.seed diff --git a/mypy/typeshed/stdlib/re.pyi b/mypy/typeshed/stdlib/re.pyi index 0183d7a813318..f0a892c797e9d 100644 --- a/mypy/typeshed/stdlib/re.pyi +++ b/mypy/typeshed/stdlib/re.pyi @@ -169,7 +169,7 @@ class Pattern(Generic[AnyStr]): @overload def split(self, string: AnyStr, maxsplit: int = 0) -> list[AnyStr | MaybeNone]: ... - # return type depends on the number of groups in the pattern + # return type is either list[str/bytes] or list[tuple[str/bytes, ...]] @overload def findall(self: Pattern[str], string: str, pos: int = 0, endpos: int = sys.maxsize) -> list[Any]: ... @overload @@ -302,6 +302,7 @@ def split( pattern: bytes | Pattern[bytes], string: ReadableBuffer, maxsplit: int = 0, flags: _FlagsType = 0 ) -> list[bytes | MaybeNone]: ... +# return type is either list[str/bytes] or list[tuple[str/bytes, ...]] @overload def findall(pattern: str | Pattern[str], string: str, flags: _FlagsType = 0) -> list[Any]: ... @overload @@ -342,5 +343,5 @@ def escape(pattern: AnyStr) -> AnyStr: ... def purge() -> None: ... if sys.version_info < (3, 13): - @deprecated("Deprecated since Python 3.11; removed in Python 3.13. Use `re.compile()` instead.") + @deprecated("Deprecated; removed in Python 3.13. Use `re.compile()` instead.") def template(pattern: AnyStr | Pattern[AnyStr], flags: _FlagsType = 0) -> Pattern[AnyStr]: ... # undocumented diff --git a/mypy/typeshed/stdlib/shutil.pyi b/mypy/typeshed/stdlib/shutil.pyi index badb0bae220dc..5919106f3ed9a 100644 --- a/mypy/typeshed/stdlib/shutil.pyi +++ b/mypy/typeshed/stdlib/shutil.pyi @@ -3,8 +3,8 @@ import sys from _typeshed import BytesPath, ExcInfo, FileDescriptorOrPath, MaybeNone, StrOrBytesPath, StrPath, SupportsRead, SupportsWrite from collections.abc import Callable, Iterable, Sequence from tarfile import _TarfileFilter -from typing import Any, AnyStr, NamedTuple, NoReturn, Protocol, TypeAlias, TypeVar, overload, type_check_only -from typing_extensions import deprecated +from typing import Any, AnyStr, NamedTuple, Protocol, TypeAlias, TypeVar, overload, type_check_only +from typing_extensions import Never, deprecated __all__ = [ "copyfileobj", @@ -191,7 +191,7 @@ else: if sys.platform == "win32" and sys.version_info < (3, 12): @overload @deprecated("On Windows before Python 3.12, using a PathLike as `cmd` would always fail or return `None`.") - def which(cmd: os.PathLike[str], mode: int = 1, path: StrPath | None = None) -> NoReturn: ... + def which(cmd: os.PathLike[str], mode: int = 1, path: StrPath | None = None) -> Never: ... @overload def which(cmd: StrPath, mode: int = 1, path: StrPath | None = None) -> str | None: ... diff --git a/mypy/typeshed/stdlib/sqlite3/__init__.pyi b/mypy/typeshed/stdlib/sqlite3/__init__.pyi index d1065a509af52..80a02079dd054 100644 --- a/mypy/typeshed/stdlib/sqlite3/__init__.pyi +++ b/mypy/typeshed/stdlib/sqlite3/__init__.pyi @@ -437,7 +437,7 @@ class Connection: ) -> Literal[False]: ... @disjoint_base -class Cursor(Iterator[Any]): +class Cursor: arraysize: int @property def connection(self) -> Connection: ... diff --git a/mypy/typeshed/stdlib/sunau.pyi b/mypy/typeshed/stdlib/sunau.pyi index 1f18c041465ef..e4b9fcb6b8ca8 100644 --- a/mypy/typeshed/stdlib/sunau.pyi +++ b/mypy/typeshed/stdlib/sunau.pyi @@ -1,6 +1,6 @@ from _typeshed import Unused -from typing import IO, Any, Final, Literal, NamedTuple, NoReturn, TypeAlias, overload -from typing_extensions import Self +from typing import IO, Any, Final, Literal, NamedTuple, TypeAlias, overload +from typing_extensions import Never, Self _File: TypeAlias = str | IO[bytes] @@ -46,7 +46,7 @@ class Au_read: def getcompname(self) -> str: ... def getparams(self) -> _sunau_params: ... def getmarkers(self) -> None: ... - def getmark(self, id: Any) -> NoReturn: ... + def getmark(self, id: Any) -> Never: ... def setpos(self, pos: int) -> None: ... def readframes(self, nframes: int) -> bytes | None: ... diff --git a/mypy/typeshed/stdlib/symtable.pyi b/mypy/typeshed/stdlib/symtable.pyi index d41ef8419dec8..3c6a828fad2a6 100644 --- a/mypy/typeshed/stdlib/symtable.pyi +++ b/mypy/typeshed/stdlib/symtable.pyi @@ -56,7 +56,7 @@ class Function(SymbolTable): def get_nonlocals(self) -> tuple[str, ...]: ... class Class(SymbolTable): - @deprecated("Deprecated since Python 3.14; will be removed in Python 3.16.") + @deprecated("Deprecated; will be removed in Python 3.16.") def get_methods(self) -> tuple[str, ...]: ... class Symbol: diff --git a/mypy/typeshed/stdlib/sys/__init__.pyi b/mypy/typeshed/stdlib/sys/__init__.pyi index 72e894b9305fd..11c78b73af5b6 100644 --- a/mypy/typeshed/stdlib/sys/__init__.pyi +++ b/mypy/typeshed/stdlib/sys/__init__.pyi @@ -5,8 +5,8 @@ from builtins import object as _object from collections.abc import AsyncGenerator, Callable, Sequence from io import TextIOWrapper from types import FrameType, ModuleType, SimpleNamespace, TracebackType -from typing import Any, Final, Literal, NoReturn, Protocol, TextIO, TypeAlias, TypeVar, final, overload, type_check_only -from typing_extensions import LiteralString, deprecated +from typing import Any, Final, Literal, Protocol, TextIO, TypeAlias, TypeVar, final, overload, type_check_only +from typing_extensions import LiteralString, Never, deprecated _T = TypeVar("_T") _LazyImportMode: TypeAlias = Literal["normal", "all", "none"] @@ -377,7 +377,7 @@ def exc_info() -> OptExcInfo: ... if sys.version_info >= (3, 11): def exception() -> BaseException | None: ... -def exit(status: _ExitCode = None, /) -> NoReturn: ... +def exit(status: _ExitCode = None, /) -> Never: ... if sys.platform == "android": # noqa: Y008 def getandroidapilevel() -> int: ... @@ -521,7 +521,7 @@ if sys.version_info >= (3, 12): if sys.platform == "linux": def activate_stack_trampoline(backend: str, /) -> None: ... else: - def activate_stack_trampoline(backend: str, /) -> NoReturn: ... + def activate_stack_trampoline(backend: str, /) -> Never: ... from . import _monitoring diff --git a/mypy/typeshed/stdlib/sysconfig.pyi b/mypy/typeshed/stdlib/sysconfig.pyi index cfa3fbaceb731..bd20113e9df5e 100644 --- a/mypy/typeshed/stdlib/sysconfig.pyi +++ b/mypy/typeshed/stdlib/sysconfig.pyi @@ -45,13 +45,13 @@ elif sys.version_info >= (3, 11): @overload def is_python_build() -> bool: ... @overload - @deprecated("The `check_home` parameter is deprecated since Python 3.12; removed in Python 3.15.") + @deprecated("The `check_home` parameter is deprecated; removed in Python 3.15.") def is_python_build(check_home: object = None) -> bool: ... else: @overload def is_python_build() -> bool: ... @overload - @deprecated("The `check_home` parameter is deprecated since Python 3.12; removed in Python 3.15.") + @deprecated("The `check_home` parameter is deprecated; removed in Python 3.15.") def is_python_build(check_home: bool = False) -> bool: ... def parse_config_h(fp: IO[Any], vars: dict[str, Any] | None = None) -> dict[str, Any]: ... diff --git a/mypy/typeshed/stdlib/tarfile.pyi b/mypy/typeshed/stdlib/tarfile.pyi index 6c55683fbaa37..7cfa098bb4f89 100644 --- a/mypy/typeshed/stdlib/tarfile.pyi +++ b/mypy/typeshed/stdlib/tarfile.pyi @@ -812,10 +812,10 @@ class TarInfo: def __init__(self, name: str = "") -> None: ... @property - @deprecated("Deprecated since Python 3.13; will be removed in Python 3.16.") + @deprecated("Deprecated; will be removed in Python 3.16.") def tarfile(self) -> TarFile | None: ... @tarfile.setter - @deprecated("Deprecated since Python 3.13; will be removed in Python 3.16.") + @deprecated("Deprecated; will be removed in Python 3.16.") def tarfile(self, tarfile: TarFile | None) -> None: ... @classmethod diff --git a/mypy/typeshed/stdlib/time.pyi b/mypy/typeshed/stdlib/time.pyi index 9b5344b326cec..ac53089b8d82c 100644 --- a/mypy/typeshed/stdlib/time.pyi +++ b/mypy/typeshed/stdlib/time.pyi @@ -1,15 +1,15 @@ import sys from _typeshed import structseq -from typing import Any, Final, Literal, Protocol, SupportsFloat, SupportsIndex, TypeAlias, Union, final, type_check_only +from typing import Any, Final, Literal, Protocol, SupportsFloat, SupportsIndex, TypeAlias, final, type_check_only _TimeTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int, int] if sys.version_info >= (3, 15): # anticipate on https://github.com/python/cpython/pull/139224 - _SupportsFloatOrIndex: TypeAlias = Union[SupportsFloat, SupportsIndex] + _SupportsFloatOrIndex: TypeAlias = SupportsFloat | SupportsIndex else: # before, time functions only accept (subclass of) float, *not* SupportsFloat - _SupportsFloatOrIndex: TypeAlias = Union[float, SupportsIndex] + _SupportsFloatOrIndex: TypeAlias = float | SupportsIndex altzone: int daylight: int diff --git a/mypy/typeshed/stdlib/tkinter/__init__.pyi b/mypy/typeshed/stdlib/tkinter/__init__.pyi index 94787911df8d4..681c6ddba5461 100644 --- a/mypy/typeshed/stdlib/tkinter/__init__.pyi +++ b/mypy/typeshed/stdlib/tkinter/__init__.pyi @@ -329,13 +329,13 @@ class Variable: def trace_add(self, mode: Literal["array", "read", "write", "unset"], callback: Callable[[str, str, str], object]) -> str: ... def trace_remove(self, mode: Literal["array", "read", "write", "unset"], cbname: str) -> None: ... def trace_info(self) -> list[tuple[tuple[Literal["array", "read", "write", "unset"], ...], str]]: ... - @deprecated("Deprecated since Python 3.14. Use `trace_add()` instead.") + @deprecated("Deprecated; will be removed in Python 3.17. Use `trace_add()` instead.") def trace(self, mode, callback) -> str: ... - @deprecated("Deprecated since Python 3.14. Use `trace_add()` instead.") + @deprecated("Deprecated; will be removed in Python 3.17. Use `trace_add()` instead.") def trace_variable(self, mode, callback) -> str: ... - @deprecated("Deprecated since Python 3.14. Use `trace_remove()` instead.") + @deprecated("Deprecated; will be removed in Python 3.17. Use `trace_remove()` instead.") def trace_vdelete(self, mode, cbname) -> None: ... - @deprecated("Deprecated since Python 3.14. Use `trace_info()` instead.") + @deprecated("Deprecated; will be removed in Python 3.17. Use `trace_info()` instead.") def trace_vinfo(self) -> list[Incomplete]: ... def __eq__(self, other: object) -> bool: ... def __del__(self) -> None: ... @@ -3905,7 +3905,7 @@ class OptionMenu(Menubutton): variable: StringVar, value: str, *values: str, - command: Callable[[StringVar], object] | None = ..., + command: Callable[[str], object] | None = ..., name: str | None = None, ) -> None: ... else: @@ -3916,7 +3916,7 @@ class OptionMenu(Menubutton): variable: StringVar, value: str, *values: str, - command: Callable[[StringVar], object] | None = ..., + command: Callable[[str], object] | None = ..., ) -> None: ... # configure, config, cget are inherited from Menubutton # destroy and __getitem__ are overridden, signature does not change diff --git a/mypy/typeshed/stdlib/typing.pyi b/mypy/typeshed/stdlib/typing.pyi index 82389ec261232..35031a27445be 100644 --- a/mypy/typeshed/stdlib/typing.pyi +++ b/mypy/typeshed/stdlib/typing.pyi @@ -423,7 +423,7 @@ def overload(func: _F) -> _F: ... def no_type_check(arg: _F) -> _F: ... if sys.version_info < (3, 15): - @deprecated("Deprecated since Python 3.13; removed in Python 3.15.") + @deprecated("Deprecated; removed in Python 3.15.") def no_type_check_decorator(decorator: Callable[_P, _T]) -> Callable[_P, _T]: ... if sys.version_info >= (3, 15): @@ -663,14 +663,17 @@ class AsyncGenerator(AsyncIterator[_YieldT_co], Protocol[_YieldT_co, _SendT_cont def aclose(self) -> Coroutine[Any, Any, None]: ... +_ContainerT_contra = TypeVar("_ContainerT_contra", contravariant=True, default=Any) + @runtime_checkable -class Container(Protocol[_T_co]): +class Container(Protocol[_ContainerT_contra]): # This is generic more on vibes than anything else @abstractmethod - def __contains__(self, x: object, /) -> bool: ... + def __contains__(self, x: _ContainerT_contra, /) -> bool: ... @runtime_checkable -class Collection(Iterable[_T_co], Container[_T_co], Protocol[_T_co]): +class Collection(Iterable[_T_co], Container[Any], Protocol[_T_co]): + # Note: need to use Container[Any] instead of Container[_T_co] to ensure covariance. # Implement Sized (but don't have it as a base class). @abstractmethod def __len__(self) -> int: ... diff --git a/mypy/typeshed/stdlib/typing_extensions.pyi b/mypy/typeshed/stdlib/typing_extensions.pyi index 5a8848e9151d8..b89d96b2be9ca 100644 --- a/mypy/typeshed/stdlib/typing_extensions.pyi +++ b/mypy/typeshed/stdlib/typing_extensions.pyi @@ -629,7 +629,7 @@ else: def __module__(self) -> str | None: ... # type: ignore[override] # Returns typing._GenericAlias, which isn't stubbed. def __getitem__(self, parameters: Incomplete | tuple[Incomplete, ...]) -> AnnotationForm: ... - def __init_subclass__(cls, *args: Unused, **kwargs: Unused) -> NoReturn: ... + def __init_subclass__(cls, *args: Unused, **kwargs: Unused) -> Never: ... def __or__(self, right: Any, /) -> _SpecialForm: ... def __ror__(self, left: Any, /) -> _SpecialForm: ... diff --git a/mypy/typeshed/stdlib/unittest/case.pyi b/mypy/typeshed/stdlib/unittest/case.pyi index 942154ea53aea..1d1206b7fc360 100644 --- a/mypy/typeshed/stdlib/unittest/case.pyi +++ b/mypy/typeshed/stdlib/unittest/case.pyi @@ -12,7 +12,6 @@ from typing import ( AnyStr, Final, Generic, - NoReturn, ParamSpec, Protocol, SupportsAbs, @@ -91,7 +90,7 @@ class TestCase: def tearDownClass(cls) -> None: ... def run(self, result: unittest.result.TestResult | None = None) -> unittest.result.TestResult | None: ... def __call__(self, result: unittest.result.TestResult | None = ...) -> unittest.result.TestResult | None: ... - def skipTest(self, reason: Any) -> NoReturn: ... + def skipTest(self, reason: Any) -> Never: ... def subTest(self, msg: Any = ..., **params: Any) -> AbstractContextManager[None]: ... def debug(self) -> None: ... if sys.version_info < (3, 11): @@ -267,7 +266,7 @@ class TestCase: # assertDictEqual accepts only true dict instances. We can't use that here, since that would make # assertDictEqual incompatible with TypedDict. def assertDictEqual(self, d1: Mapping[Any, object], d2: Mapping[Any, object], msg: Any = None) -> None: ... - def fail(self, msg: Any = None) -> NoReturn: ... + def fail(self, msg: Any = None) -> Never: ... def countTestCases(self) -> int: ... def defaultTestResult(self) -> unittest.result.TestResult: ... def id(self) -> str: ... diff --git a/mypy/typeshed/stdlib/unittest/loader.pyi b/mypy/typeshed/stdlib/unittest/loader.pyi index 0d92b78f3461d..106004fadcc2e 100644 --- a/mypy/typeshed/stdlib/unittest/loader.pyi +++ b/mypy/typeshed/stdlib/unittest/loader.pyi @@ -35,21 +35,21 @@ class TestLoader: defaultTestLoader: TestLoader if sys.version_info < (3, 13): - @deprecated("Deprecated since Python 3.11; removed in Python 3.13.") + @deprecated("Deprecated; removed in Python 3.13.") def getTestCaseNames( testCaseClass: type[unittest.case.TestCase], prefix: str, sortUsing: _SortComparisonMethod = ..., testNamePatterns: list[str] | None = None, ) -> Sequence[str]: ... - @deprecated("Deprecated since Python 3.11; removed in Python 3.13.") + @deprecated("Deprecated; removed in Python 3.13.") def makeSuite( testCaseClass: type[unittest.case.TestCase], prefix: str = "test", sortUsing: _SortComparisonMethod = ..., suiteClass: _SuiteClass = ..., ) -> unittest.suite.TestSuite: ... - @deprecated("Deprecated since Python 3.11; removed in Python 3.13.") + @deprecated("Deprecated; removed in Python 3.13.") def findTestCases( module: ModuleType, prefix: str = "test", sortUsing: _SortComparisonMethod = ..., suiteClass: _SuiteClass = ... ) -> unittest.suite.TestSuite: ... diff --git a/mypy/typeshed/stdlib/unittest/main.pyi b/mypy/typeshed/stdlib/unittest/main.pyi index f48347c16ec39..09b547cd1cd6c 100644 --- a/mypy/typeshed/stdlib/unittest/main.pyi +++ b/mypy/typeshed/stdlib/unittest/main.pyi @@ -64,7 +64,7 @@ class TestProgram: ) -> None: ... if sys.version_info < (3, 13): - @deprecated("Deprecated since Python 3.11; removed in Python 3.13.") + @deprecated("Deprecated; removed in Python 3.13.") def usageExit(self, msg: Any = None) -> None: ... def parseArgs(self, argv: list[str]) -> None: ... diff --git a/mypy/typeshed/stdlib/urllib/request.pyi b/mypy/typeshed/stdlib/urllib/request.pyi index 0ec26052b23c6..17a283321df48 100644 --- a/mypy/typeshed/stdlib/urllib/request.pyi +++ b/mypy/typeshed/stdlib/urllib/request.pyi @@ -6,8 +6,8 @@ from email.message import Message from http.client import HTTPConnection, HTTPMessage, HTTPResponse from http.cookiejar import CookieJar from re import Pattern -from typing import IO, Any, ClassVar, Literal, NoReturn, Protocol, TypeAlias, TypeVar, overload, type_check_only -from typing_extensions import deprecated +from typing import IO, Any, ClassVar, Literal, Protocol, TypeAlias, TypeVar, overload, type_check_only +from typing_extensions import Never, deprecated from urllib.error import HTTPError as HTTPError from urllib.response import addclosehook, addinfourl @@ -336,7 +336,7 @@ class CacheFTPHandler(FTPHandler): def clear_cache(self) -> None: ... # undocumented class UnknownHandler(BaseHandler): - def unknown_open(self, req: Request) -> NoReturn: ... + def unknown_open(self, req: Request) -> Never: ... class HTTPErrorProcessor(BaseHandler): def http_response(self, request: Request, response: HTTPResponse) -> _UrlopenRet: ... diff --git a/mypy/typeshed/stdlib/uuid.pyi b/mypy/typeshed/stdlib/uuid.pyi index 06285e03aea7e..1b5d0c1fbf5ab 100644 --- a/mypy/typeshed/stdlib/uuid.pyi +++ b/mypy/typeshed/stdlib/uuid.pyi @@ -2,8 +2,8 @@ import builtins import sys from _typeshed import Unused from enum import Enum -from typing import Final, NoReturn, TypeAlias -from typing_extensions import LiteralString +from typing import Final, TypeAlias +from typing_extensions import LiteralString, Never _FieldsType: TypeAlias = tuple[int, int, int, int, int, int] @@ -65,7 +65,7 @@ class UUID: def __gt__(self, other: UUID) -> bool: ... def __ge__(self, other: UUID) -> bool: ... def __hash__(self) -> builtins.int: ... - def __setattr__(self, name: Unused, value: Unused) -> NoReturn: ... + def __setattr__(self, name: Unused, value: Unused) -> Never: ... def getnode() -> int: ... def uuid1(node: int | None = None, clock_seq: int | None = None) -> UUID: ... diff --git a/mypy/typeshed/stdlib/wave.pyi b/mypy/typeshed/stdlib/wave.pyi index 74f8b8a9e3cf7..70bf87281550e 100644 --- a/mypy/typeshed/stdlib/wave.pyi +++ b/mypy/typeshed/stdlib/wave.pyi @@ -1,7 +1,7 @@ import sys from _typeshed import ReadableBuffer, StrOrBytesPath, Unused -from typing import IO, Any, BinaryIO, Final, Literal, NamedTuple, NoReturn, TypeAlias, overload -from typing_extensions import Self, deprecated +from typing import IO, Any, BinaryIO, Final, Literal, NamedTuple, TypeAlias, overload +from typing_extensions import Never, Self, deprecated __all__ = ["open", "Error", "Wave_read", "Wave_write"] if sys.version_info >= (3, 15): @@ -47,10 +47,10 @@ class Wave_read: def getcompname(self) -> str: ... def getparams(self) -> _wave_params: ... if sys.version_info < (3, 15): - @deprecated("Deprecated since Python 3.13; will be removed in Python 3.15.") + @deprecated("Deprecated; will be removed in Python 3.15.") def getmarkers(self) -> None: ... - @deprecated("Deprecated since Python 3.13; will be removed in Python 3.15.") - def getmark(self, id: Any) -> NoReturn: ... + @deprecated("Deprecated; will be removed in Python 3.15.") + def getmark(self, id: Any) -> Never: ... def setpos(self, pos: int) -> None: ... def readframes(self, nframes: int) -> bytes: ... @@ -85,11 +85,11 @@ class Wave_write: def getparams(self) -> _wave_params: ... if sys.version_info < (3, 15): - @deprecated("Deprecated since Python 3.13; will be removed in Python 3.15.") - def setmark(self, id: Any, pos: Any, name: Any) -> NoReturn: ... - @deprecated("Deprecated since Python 3.13; will be removed in Python 3.15.") - def getmark(self, id: Any) -> NoReturn: ... - @deprecated("Deprecated since Python 3.13; will be removed in Python 3.15.") + @deprecated("Deprecated; will be removed in Python 3.15.") + def setmark(self, id: Any, pos: Any, name: Any) -> Never: ... + @deprecated("Deprecated; will be removed in Python 3.15.") + def getmark(self, id: Any) -> Never: ... + @deprecated("Deprecated; will be removed in Python 3.15.") def getmarkers(self) -> None: ... def tell(self) -> int: ... diff --git a/mypy/typeshed/stdlib/webbrowser.pyi b/mypy/typeshed/stdlib/webbrowser.pyi index 40b57c3c6a097..4bcaf33075919 100644 --- a/mypy/typeshed/stdlib/webbrowser.pyi +++ b/mypy/typeshed/stdlib/webbrowser.pyi @@ -64,7 +64,7 @@ if sys.platform == "win32": if sys.platform == "darwin": if sys.version_info < (3, 13): - @deprecated("Deprecated since Python 3.11; removed in Python 3.13.") + @deprecated("Deprecated; removed in Python 3.13.") class MacOSX(BaseBrowser): def __init__(self, name: str) -> None: ... def open(self, url: str, new: int = 0, autoraise: bool = True) -> bool: ... diff --git a/mypy/typeshed/stdlib/wsgiref/validate.pyi b/mypy/typeshed/stdlib/wsgiref/validate.pyi index 498e03aa36731..ce3e79f341f90 100644 --- a/mypy/typeshed/stdlib/wsgiref/validate.pyi +++ b/mypy/typeshed/stdlib/wsgiref/validate.pyi @@ -1,6 +1,7 @@ from _typeshed.wsgi import ErrorStream, InputStream, WSGIApplication from collections.abc import Callable, Iterable, Iterator -from typing import Any, NoReturn, TypeAlias +from typing import Any, TypeAlias +from typing_extensions import Never __all__ = ["validator"] @@ -15,7 +16,7 @@ class InputWrapper: def readline(self, size: int = ...) -> bytes: ... def readlines(self, hint: int = ...) -> bytes: ... def __iter__(self) -> Iterator[bytes]: ... - def close(self) -> NoReturn: ... + def close(self) -> Never: ... class ErrorWrapper: errors: ErrorStream @@ -23,7 +24,7 @@ class ErrorWrapper: def write(self, s: str) -> None: ... def flush(self) -> None: ... def writelines(self, seq: Iterable[str]) -> None: ... - def close(self) -> NoReturn: ... + def close(self) -> Never: ... _WriterCallback: TypeAlias = Callable[[bytes], Any] diff --git a/mypy/typeshed/stdlib/xml/dom/expatbuilder.pyi b/mypy/typeshed/stdlib/xml/dom/expatbuilder.pyi index e410671829358..5aef384ff0f2a 100644 --- a/mypy/typeshed/stdlib/xml/dom/expatbuilder.pyi +++ b/mypy/typeshed/stdlib/xml/dom/expatbuilder.pyi @@ -1,5 +1,6 @@ from _typeshed import ReadableBuffer, SupportsRead -from typing import Any, Final, NoReturn, TypeAlias +from typing import Any, Final, TypeAlias +from typing_extensions import Never from xml.dom.minidom import Document, DocumentFragment, DOMImplementation, Element, Node, TypeInfo from xml.dom.xmlbuilder import DOMBuilderFilter, Options from xml.parsers.expat import XMLParserType @@ -115,8 +116,8 @@ class InternalSubsetExtractor(ExpatBuilder): def start_doctype_decl_handler( # type: ignore[override] self, name: str, publicId: str | None, systemId: str | None, has_internal_subset: bool ) -> None: ... - def end_doctype_decl_handler(self) -> NoReturn: ... - def start_element_handler(self, name: str, attrs: list[str]) -> NoReturn: ... + def end_doctype_decl_handler(self) -> Never: ... + def start_element_handler(self, name: str, attrs: list[str]) -> Never: ... def parse(file: str | SupportsRead[ReadableBuffer | str], namespaces: bool = True) -> Document: ... def parseString(string: str | ReadableBuffer, namespaces: bool = True) -> Document: ... diff --git a/mypy/typeshed/stdlib/xml/dom/minidom.pyi b/mypy/typeshed/stdlib/xml/dom/minidom.pyi index c54b0de86e556..7d287a6c9b600 100644 --- a/mypy/typeshed/stdlib/xml/dom/minidom.pyi +++ b/mypy/typeshed/stdlib/xml/dom/minidom.pyi @@ -3,8 +3,8 @@ from _collections_abc import dict_keys, dict_values from _typeshed import Incomplete, ReadableBuffer, SupportsRead, SupportsWrite from collections.abc import Iterable, Sequence from types import TracebackType -from typing import Any, ClassVar, Generic, Literal, NoReturn, Protocol, TypeAlias, TypeVar, overload, type_check_only -from typing_extensions import Self +from typing import Any, ClassVar, Generic, Literal, Protocol, TypeAlias, TypeVar, overload, type_check_only +from typing_extensions import Never, Self from xml.dom.minicompat import EmptyNodeList, NodeList from xml.dom.xmlbuilder import DocumentLS, DOMImplementationLS from xml.sax.xmlreader import XMLReader @@ -367,14 +367,14 @@ class Childless: def firstChild(self) -> None: ... @property def lastChild(self) -> None: ... - def appendChild(self, node: _NodesThatAreChildren | DocumentFragment) -> NoReturn: ... + def appendChild(self, node: _NodesThatAreChildren | DocumentFragment) -> Never: ... def hasChildNodes(self) -> Literal[False]: ... def insertBefore( self, newChild: _NodesThatAreChildren | DocumentFragment, refChild: _NodesThatAreChildren | None - ) -> NoReturn: ... - def removeChild(self, oldChild: _NodesThatAreChildren) -> NoReturn: ... + ) -> Never: ... + def removeChild(self, oldChild: _NodesThatAreChildren) -> Never: ... def normalize(self) -> None: ... - def replaceChild(self, newChild: _NodesThatAreChildren | DocumentFragment, oldChild: _NodesThatAreChildren) -> NoReturn: ... + def replaceChild(self, newChild: _NodesThatAreChildren | DocumentFragment, oldChild: _NodesThatAreChildren) -> Never: ... class ProcessingInstruction(Childless, Node): __slots__ = ("target", "data") @@ -501,10 +501,10 @@ class ReadOnlySequentialNamedNodeMap(Generic[_N]): def getNamedItemNS(self, namespaceURI: str | None, localName: str) -> _N | None: ... def __getitem__(self, name_or_tuple: str | _NSName) -> _N | None: ... def item(self, index: int) -> _N | None: ... - def removeNamedItem(self, name: str) -> NoReturn: ... - def removeNamedItemNS(self, namespaceURI: str | None, localName: str) -> NoReturn: ... - def setNamedItem(self, node: Node) -> NoReturn: ... - def setNamedItemNS(self, node: Node) -> NoReturn: ... + def removeNamedItem(self, name: str) -> Never: ... + def removeNamedItemNS(self, namespaceURI: str | None, localName: str) -> Never: ... + def setNamedItem(self, node: Node) -> Never: ... + def setNamedItemNS(self, node: Node) -> Never: ... @property def length(self) -> int: ... @@ -568,10 +568,10 @@ class Entity(Identified, Node): notationName: str | None def __init__(self, name: str, publicId: str | None, systemId: str | None, notation: str | None) -> None: ... - def appendChild(self, newChild: _EntityChildren) -> NoReturn: ... # type: ignore[override] - def insertBefore(self, newChild: _EntityChildren, refChild: _EntityChildren | None) -> NoReturn: ... # type: ignore[override] - def removeChild(self, oldChild: _EntityChildren) -> NoReturn: ... # type: ignore[override] - def replaceChild(self, newChild: _EntityChildren, oldChild: _EntityChildren) -> NoReturn: ... # type: ignore[override] + def appendChild(self, newChild: _EntityChildren) -> Never: ... # type: ignore[override] + def insertBefore(self, newChild: _EntityChildren, refChild: _EntityChildren | None) -> Never: ... # type: ignore[override] + def removeChild(self, oldChild: _EntityChildren) -> Never: ... # type: ignore[override] + def replaceChild(self, newChild: _EntityChildren, oldChild: _EntityChildren) -> Never: ... # type: ignore[override] class Notation(Identified, Childless, Node): nodeType: ClassVar[Literal[12]] diff --git a/mypy/typeshed/stdlib/xml/dom/pulldom.pyi b/mypy/typeshed/stdlib/xml/dom/pulldom.pyi index 4ede390155855..7014c865bcdd2 100644 --- a/mypy/typeshed/stdlib/xml/dom/pulldom.pyi +++ b/mypy/typeshed/stdlib/xml/dom/pulldom.pyi @@ -1,8 +1,8 @@ import sys from _typeshed import Incomplete, Unused from collections.abc import MutableSequence, Sequence -from typing import Final, Literal, NoReturn, TypeAlias -from typing_extensions import Self +from typing import Final, Literal, TypeAlias +from typing_extensions import Never, Self from xml.dom.minidom import Comment, Document, DOMImplementation, Element, ProcessingInstruction, Text from xml.sax import _SupportsReadClose from xml.sax.handler import ContentHandler @@ -73,8 +73,8 @@ class PullDOM(ContentHandler): class ErrorHandler: def warning(self, exception: BaseException) -> None: ... - def error(self, exception: BaseException) -> NoReturn: ... - def fatalError(self, exception: BaseException) -> NoReturn: ... + def error(self, exception: BaseException) -> Never: ... + def fatalError(self, exception: BaseException) -> Never: ... class DOMEventStream: stream: _SupportsReadClose[bytes] | _SupportsReadClose[str] diff --git a/mypy/typeshed/stdlib/xml/dom/xmlbuilder.pyi b/mypy/typeshed/stdlib/xml/dom/xmlbuilder.pyi index f19f7050b08df..686c9d8efe8fa 100644 --- a/mypy/typeshed/stdlib/xml/dom/xmlbuilder.pyi +++ b/mypy/typeshed/stdlib/xml/dom/xmlbuilder.pyi @@ -1,5 +1,6 @@ from _typeshed import SupportsRead -from typing import Any, Final, Literal, NoReturn +from typing import Any, Final, Literal +from typing_extensions import Never from xml.dom.minidom import Document, Node, _DOMErrorHandler __all__ = ["DOMBuilder", "DOMEntityResolver", "DOMInputSource"] @@ -41,7 +42,7 @@ class DOMBuilder: def getFeature(self, name: str) -> Any: ... def parseURI(self, uri: str) -> Document: ... def parse(self, input: DOMInputSource) -> Document: ... - def parseWithContext(self, input: DOMInputSource, cnode: Node, action: Literal[1, 2, 3, 4]) -> NoReturn: ... + def parseWithContext(self, input: DOMInputSource, cnode: Node, action: Literal[1, 2, 3, 4]) -> Never: ... class DOMEntityResolver: __slots__ = ("_opener",) @@ -68,14 +69,14 @@ class DOMBuilderFilter: class DocumentLS: async_: bool - def abort(self) -> NoReturn: ... - def load(self, uri: str) -> NoReturn: ... - def loadXML(self, source: str) -> NoReturn: ... + def abort(self) -> Never: ... + def load(self, uri: str) -> Never: ... + def loadXML(self, source: str) -> Never: ... def saveXML(self, snode: Node | None) -> str: ... class DOMImplementationLS: MODE_SYNCHRONOUS: Final = 1 MODE_ASYNCHRONOUS: Final = 2 def createDOMBuilder(self, mode: Literal[1], schemaType: None) -> DOMBuilder: ... - def createDOMWriter(self) -> NoReturn: ... + def createDOMWriter(self) -> Never: ... def createDOMInputSource(self) -> DOMInputSource: ... diff --git a/mypy/typeshed/stdlib/xml/sax/_exceptions.pyi b/mypy/typeshed/stdlib/xml/sax/_exceptions.pyi index e9cc8856a9c8d..8f5e3a827185a 100644 --- a/mypy/typeshed/stdlib/xml/sax/_exceptions.pyi +++ b/mypy/typeshed/stdlib/xml/sax/_exceptions.pyi @@ -1,11 +1,11 @@ -from typing import NoReturn +from typing_extensions import Never from xml.sax.xmlreader import Locator class SAXException(Exception): def __init__(self, msg: str, exception: Exception | None = None) -> None: ... def getMessage(self) -> str: ... def getException(self) -> Exception | None: ... - def __getitem__(self, ix: object) -> NoReturn: ... + def __getitem__(self, ix: object) -> Never: ... class SAXParseException(SAXException): def __init__(self, msg: str, exception: Exception | None, locator: Locator) -> None: ... diff --git a/mypy/typeshed/stdlib/xml/sax/handler.pyi b/mypy/typeshed/stdlib/xml/sax/handler.pyi index e1e080ac2d1aa..654c98866cfb5 100644 --- a/mypy/typeshed/stdlib/xml/sax/handler.pyi +++ b/mypy/typeshed/stdlib/xml/sax/handler.pyi @@ -1,17 +1,18 @@ -from typing import Final, NoReturn, Protocol, type_check_only +from typing import Final, Protocol, type_check_only +from typing_extensions import Never from xml.sax import xmlreader version: Final[str] @type_check_only class _ErrorHandlerProtocol(Protocol): # noqa: Y046 # Protocol is not used - def error(self, exception: BaseException) -> NoReturn: ... - def fatalError(self, exception: BaseException) -> NoReturn: ... + def error(self, exception: BaseException) -> Never: ... + def fatalError(self, exception: BaseException) -> Never: ... def warning(self, exception: BaseException) -> None: ... class ErrorHandler: - def error(self, exception: BaseException) -> NoReturn: ... - def fatalError(self, exception: BaseException) -> NoReturn: ... + def error(self, exception: BaseException) -> Never: ... + def fatalError(self, exception: BaseException) -> Never: ... def warning(self, exception: BaseException) -> None: ... @type_check_only diff --git a/mypy/typeshed/stdlib/xml/sax/saxutils.pyi b/mypy/typeshed/stdlib/xml/sax/saxutils.pyi index a29588faae2ae..0f5251def6b03 100644 --- a/mypy/typeshed/stdlib/xml/sax/saxutils.pyi +++ b/mypy/typeshed/stdlib/xml/sax/saxutils.pyi @@ -2,7 +2,8 @@ from _typeshed import SupportsWrite from codecs import StreamReaderWriter, StreamWriter from collections.abc import Mapping from io import RawIOBase, TextIOBase -from typing import Literal, NoReturn +from typing import Literal +from typing_extensions import Never from xml.sax import _Source, handler, xmlreader def escape(data: str, entities: Mapping[str, str] = {}) -> str: ... @@ -32,8 +33,8 @@ class XMLGenerator(handler.ContentHandler): class XMLFilterBase(xmlreader.XMLReader): def __init__(self, parent: xmlreader.XMLReader | None = None) -> None: ... # ErrorHandler methods - def error(self, exception: BaseException) -> NoReturn: ... - def fatalError(self, exception: BaseException) -> NoReturn: ... + def error(self, exception: BaseException) -> Never: ... + def fatalError(self, exception: BaseException) -> Never: ... def warning(self, exception: BaseException) -> None: ... # ContentHandler methods def setDocumentLocator(self, locator: xmlreader.Locator) -> None: ... From 1f380f2cdbf21d443a8e08ce148fe0a9812b02d2 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 18 May 2026 17:33:09 +0200 Subject: [PATCH 03/12] Adjust stubs to fix mypy lookup error due to circular dependencies in stubs --- mypy/typeshed/stdlib/__future__.pyi | 2 +- mypy/typeshed/stdlib/dis.pyi | 4 ++-- mypy/typeshed/stdlib/inspect.pyi | 4 ++-- mypy/typeshed/stdlib/itertools.pyi | 2 +- mypy/typeshed/stdlib/time.pyi | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mypy/typeshed/stdlib/__future__.pyi b/mypy/typeshed/stdlib/__future__.pyi index aa445d22bd20d..a90cf1eddab76 100644 --- a/mypy/typeshed/stdlib/__future__.pyi +++ b/mypy/typeshed/stdlib/__future__.pyi @@ -1,4 +1,4 @@ -from typing import TypeAlias +from typing_extensions import TypeAlias _VersionInfo: TypeAlias = tuple[int, int, int, str, int] diff --git a/mypy/typeshed/stdlib/dis.pyi b/mypy/typeshed/stdlib/dis.pyi index 984f932e33115..0ad928934671b 100644 --- a/mypy/typeshed/stdlib/dis.pyi +++ b/mypy/typeshed/stdlib/dis.pyi @@ -2,7 +2,7 @@ import sys import types from collections.abc import Callable, Iterator from opcode import * # `dis` re-exports it as a part of public API -from typing import IO, Any, Final, NamedTuple, TypeAlias, overload +from typing import IO, Any, Final, NamedTuple, overload from typing_extensions import Self, deprecated, disjoint_base __all__ = [ @@ -41,7 +41,7 @@ else: # Strictly this should not have to include Callable, but mypy doesn't use FunctionType # for functions (python/mypy#3171) -_HaveCodeType: TypeAlias = types.MethodType | types.FunctionType | types.CodeType | type | Callable[..., Any] +_HaveCodeType = types.MethodType | types.FunctionType | types.CodeType | type | Callable[..., Any] if sys.version_info >= (3, 11): class Positions(NamedTuple): diff --git a/mypy/typeshed/stdlib/inspect.pyi b/mypy/typeshed/stdlib/inspect.pyi index c3110ce28d8ea..1bd2b9dee325b 100644 --- a/mypy/typeshed/stdlib/inspect.pyi +++ b/mypy/typeshed/stdlib/inspect.pyi @@ -195,8 +195,8 @@ if sys.version_info >= (3, 14): modulesbyfile: dict[str, Any] -_GetMembersPredicateTypeGuard: TypeAlias = Callable[[Any], TypeGuard[_T]] -_GetMembersPredicateTypeIs: TypeAlias = Callable[[Any], TypeIs[_T]] +_GetMembersPredicateTypeGuard = Callable[[Any], TypeGuard[_T]] +_GetMembersPredicateTypeIs = Callable[[Any], TypeIs[_T]] _GetMembersPredicate: TypeAlias = Callable[[Any], bool] _GetMembersReturn: TypeAlias = list[tuple[str, _T]] diff --git a/mypy/typeshed/stdlib/itertools.pyi b/mypy/typeshed/stdlib/itertools.pyi index d26a4e1da21e4..60e79bc2e4113 100644 --- a/mypy/typeshed/stdlib/itertools.pyi +++ b/mypy/typeshed/stdlib/itertools.pyi @@ -23,7 +23,7 @@ _T10 = TypeVar("_T10") _Step: TypeAlias = SupportsFloat | SupportsInt | SupportsIndex | SupportsComplex -_Predicate: TypeAlias = Callable[[_T], object] +_Predicate = Callable[[_T], object] # Technically count can take anything that implements a number protocol and has an add method # but we can't enforce the add method diff --git a/mypy/typeshed/stdlib/time.pyi b/mypy/typeshed/stdlib/time.pyi index ac53089b8d82c..9b5344b326cec 100644 --- a/mypy/typeshed/stdlib/time.pyi +++ b/mypy/typeshed/stdlib/time.pyi @@ -1,15 +1,15 @@ import sys from _typeshed import structseq -from typing import Any, Final, Literal, Protocol, SupportsFloat, SupportsIndex, TypeAlias, final, type_check_only +from typing import Any, Final, Literal, Protocol, SupportsFloat, SupportsIndex, TypeAlias, Union, final, type_check_only _TimeTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int, int] if sys.version_info >= (3, 15): # anticipate on https://github.com/python/cpython/pull/139224 - _SupportsFloatOrIndex: TypeAlias = SupportsFloat | SupportsIndex + _SupportsFloatOrIndex: TypeAlias = Union[SupportsFloat, SupportsIndex] else: # before, time functions only accept (subclass of) float, *not* SupportsFloat - _SupportsFloatOrIndex: TypeAlias = float | SupportsIndex + _SupportsFloatOrIndex: TypeAlias = Union[float, SupportsIndex] altzone: int daylight: int From 2adc788b5739686202cc8c88d201f21a2fb398aa Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 15 Feb 2025 20:11:06 +0100 Subject: [PATCH 04/12] Partially revert Clean up argparse hacks --- mypy/typeshed/stdlib/argparse.pyi | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mypy/typeshed/stdlib/argparse.pyi b/mypy/typeshed/stdlib/argparse.pyi index 36ea1981af3f5..6ee01a82d00a6 100644 --- a/mypy/typeshed/stdlib/argparse.pyi +++ b/mypy/typeshed/stdlib/argparse.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import SupportsWrite, sentinel from collections.abc import Callable, Generator, Iterable, Sequence from re import Pattern -from typing import IO, Any, ClassVar, Final, Generic, Protocol, TypeAlias, TypeVar, overload, type_check_only +from typing import IO, Any, ClassVar, Final, Generic, NewType, Protocol, TypeAlias, TypeVar, overload, type_check_only from typing_extensions import Never, Self, deprecated __all__ = [ @@ -36,7 +36,9 @@ ONE_OR_MORE: Final = "+" OPTIONAL: Final = "?" PARSER: Final = "A..." REMAINDER: Final = "..." -SUPPRESS: Final = "==SUPPRESS==" +_SUPPRESS_T = NewType("_SUPPRESS_T", str) +SUPPRESS: _SUPPRESS_T | str # not using Literal because argparse sometimes compares SUPPRESS with is +# the | str is there so that foo = argparse.SUPPRESS; foo = "test" checks out in mypy ZERO_OR_MORE: Final = "*" _UNRECOGNIZED_ARGS_ATTR: Final = "_unrecognized_args" # undocumented @@ -79,7 +81,7 @@ class _ActionsContainer: # more precisely, Literal["?", "*", "+", "...", "A...", "==SUPPRESS=="], # but using this would make it hard to annotate callers that don't use a # literal argument and for subclasses to override this method. - nargs: int | str | None = None, + nargs: int | str | _SUPPRESS_T | None = None, const: Any = ..., default: Any = ..., type: _ActionType = ..., From c7c144835b6aa1690c06c4c9fa5135c02018b497 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Mon, 26 Sep 2022 12:55:07 -0700 Subject: [PATCH 05/12] Remove use of LiteralString in builtins (#13743) --- mypy/typeshed/stdlib/builtins.pyi | 127 +----------------------------- 1 file changed, 1 insertion(+), 126 deletions(-) diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi index 3c549d97316c7..ec72c308e2f8a 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi @@ -65,7 +65,7 @@ from typing import ( # noqa: Y022,UP035 ) # we can't import `Literal` from typing or mypy crashes: see #11247 -from typing_extensions import Literal, LiteralString, Self, TypeIs, TypeVarTuple, deprecated, disjoint_base # noqa: Y023, UP035 +from typing_extensions import Literal, Self, TypeIs, TypeVarTuple, deprecated, disjoint_base # noqa: Y023, UP035 if sys.version_info >= (3, 14): from _typeshed import AnnotateFunc @@ -491,20 +491,8 @@ class str(Sequence[str]): def __new__(cls, object: object = "") -> Self: ... @overload def __new__(cls, object: ReadableBuffer, encoding: str = "utf-8", errors: str = "strict") -> Self: ... - - @overload - def capitalize(self: LiteralString) -> LiteralString: ... - @overload def capitalize(self) -> str: ... # type: ignore[misc] - - @overload - def casefold(self: LiteralString) -> LiteralString: ... - @overload def casefold(self) -> str: ... # type: ignore[misc] - - @overload - def center(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ... - @overload def center(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc] def count(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ... @@ -512,17 +500,9 @@ class str(Sequence[str]): def endswith( self, suffix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, / ) -> bool: ... - - @overload - def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ... - @overload def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc] def find(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ... - - @overload - def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ... - @overload def format(self, *args: object, **kwargs: object) -> str: ... def format_map(self, mapping: _FormatMapMapping, /) -> str: ... @@ -539,119 +519,38 @@ class str(Sequence[str]): def isspace(self) -> bool: ... def istitle(self) -> bool: ... def isupper(self) -> bool: ... - - @overload - def join(self: LiteralString, iterable: Iterable[LiteralString], /) -> LiteralString: ... - @overload def join(self, iterable: Iterable[str], /) -> str: ... # type: ignore[misc] - - @overload - def ljust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ... - @overload def ljust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc] - - @overload - def lower(self: LiteralString) -> LiteralString: ... - @overload def lower(self) -> str: ... # type: ignore[misc] - - @overload - def lstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ... - @overload def lstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc] - - @overload - def partition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ... - @overload def partition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc] if sys.version_info >= (3, 13): - @overload - def replace( - self: LiteralString, old: LiteralString, new: LiteralString, /, count: SupportsIndex = -1 - ) -> LiteralString: ... - @overload def replace(self, old: str, new: str, /, count: SupportsIndex = -1) -> str: ... # type: ignore[misc] else: - @overload - def replace( - self: LiteralString, old: LiteralString, new: LiteralString, count: SupportsIndex = -1, / - ) -> LiteralString: ... - @overload def replace(self, old: str, new: str, count: SupportsIndex = -1, /) -> str: ... # type: ignore[misc] - @overload - def removeprefix(self: LiteralString, prefix: LiteralString, /) -> LiteralString: ... - @overload def removeprefix(self, prefix: str, /) -> str: ... # type: ignore[misc] - - @overload - def removesuffix(self: LiteralString, suffix: LiteralString, /) -> LiteralString: ... - @overload def removesuffix(self, suffix: str, /) -> str: ... # type: ignore[misc] def rfind(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ... def rindex(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ... - - @overload - def rjust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ... - @overload def rjust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc] - - @overload - def rpartition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ... - @overload def rpartition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc] - - @overload - def rsplit(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ... - @overload def rsplit(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc] - - @overload - def rstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ... - @overload def rstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc] - - @overload - def split(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ... - @overload def split(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc] - - @overload - def splitlines(self: LiteralString, keepends: bool = False) -> list[LiteralString]: ... - @overload def splitlines(self, keepends: bool = False) -> list[str]: ... # type: ignore[misc] def startswith( self, prefix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, / ) -> bool: ... - - @overload - def strip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ... - @overload def strip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc] - - @overload - def swapcase(self: LiteralString) -> LiteralString: ... - @overload def swapcase(self) -> str: ... # type: ignore[misc] - - @overload - def title(self: LiteralString) -> LiteralString: ... - @overload def title(self) -> str: ... # type: ignore[misc] def translate(self, table: _TranslateTable, /) -> str: ... - - @overload - def upper(self: LiteralString) -> LiteralString: ... - @overload def upper(self) -> str: ... # type: ignore[misc] - - @overload - def zfill(self: LiteralString, width: SupportsIndex, /) -> LiteralString: ... - @overload def zfill(self, width: SupportsIndex, /) -> str: ... # type: ignore[misc] if sys.version_info >= (3, 15): @@ -679,49 +578,25 @@ class str(Sequence[str]): @staticmethod @overload def maketrans(x: str, y: str, z: str, /) -> dict[int, int | None]: ... - - @overload - def __add__(self: LiteralString, value: LiteralString, /) -> LiteralString: ... - @overload def __add__(self, value: str, /) -> str: ... # type: ignore[misc] # Incompatible with Sequence.__contains__ def __contains__(self, key: str, /) -> bool: ... # type: ignore[override] def __eq__(self, value: object, /) -> bool: ... def __ge__(self, value: str, /) -> bool: ... - - @overload - def __getitem__(self: LiteralString, key: SupportsIndex | slice[SupportsIndex | None], /) -> LiteralString: ... - @overload def __getitem__(self, key: SupportsIndex | slice[SupportsIndex | None], /) -> str: ... # type: ignore[misc] def __gt__(self, value: str, /) -> bool: ... def __hash__(self) -> int: ... - - @overload - def __iter__(self: LiteralString) -> Iterator[LiteralString]: ... - @overload def __iter__(self) -> Iterator[str]: ... # type: ignore[misc] def __le__(self, value: str, /) -> bool: ... def __len__(self) -> int: ... def __lt__(self, value: str, /) -> bool: ... - - @overload - def __mod__(self: LiteralString, value: LiteralString | tuple[LiteralString, ...], /) -> LiteralString: ... - @overload def __mod__(self, value: Any, /) -> str: ... - - @overload - def __mul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ... - @overload def __mul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc] def __ne__(self, value: object, /) -> bool: ... - - @overload - def __rmul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ... - @overload def __rmul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc] def __getnewargs__(self) -> tuple[str]: ... From e14bef4897599b82a3aec626ae98c11deb21650f Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 21 Dec 2024 22:36:38 +0100 Subject: [PATCH 06/12] Revert Remove redundant inheritances from Iterator in builtins --- mypy/typeshed/stdlib/_asyncio.pyi | 4 +- mypy/typeshed/stdlib/builtins.pyi | 10 ++--- mypy/typeshed/stdlib/csv.pyi | 4 +- mypy/typeshed/stdlib/fileinput.pyi | 6 +-- mypy/typeshed/stdlib/itertools.pyi | 38 +++++++++---------- mypy/typeshed/stdlib/multiprocessing/pool.pyi | 4 +- mypy/typeshed/stdlib/sqlite3/__init__.pyi | 2 +- 7 files changed, 34 insertions(+), 34 deletions(-) diff --git a/mypy/typeshed/stdlib/_asyncio.pyi b/mypy/typeshed/stdlib/_asyncio.pyi index 242093e1ec799..92bb4e5f41706 100644 --- a/mypy/typeshed/stdlib/_asyncio.pyi +++ b/mypy/typeshed/stdlib/_asyncio.pyi @@ -1,6 +1,6 @@ import sys from asyncio.events import AbstractEventLoop -from collections.abc import Awaitable, Callable, Coroutine, Generator +from collections.abc import Awaitable, Callable, Coroutine, Generator, Iterable from contextvars import Context from types import FrameType, GenericAlias from typing import Any, Literal, TextIO, TypeAlias, TypeVar @@ -11,7 +11,7 @@ _T_co = TypeVar("_T_co", covariant=True) _TaskYieldType: TypeAlias = Future[object] | None @disjoint_base -class Future(Awaitable[_T]): +class Future(Awaitable[_T], Iterable[_T]): _state: str @property def _exception(self) -> BaseException | None: ... diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi index ec72c308e2f8a..d0963d5b70546 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi @@ -1376,7 +1376,7 @@ class frozenset(AbstractSet[_T_co]): def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... @disjoint_base -class enumerate(Generic[_T]): +class enumerate(Iterator[tuple[int, _T]]): def __new__(cls, iterable: Iterable[_T], start: int = 0) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> tuple[int, _T]: ... @@ -1642,7 +1642,7 @@ else: exit: _sitebuiltins.Quitter @disjoint_base -class filter(Generic[_T]): +class filter(Iterator[_T]): @overload def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ... @overload @@ -1713,7 +1713,7 @@ license: _sitebuiltins._Printer def locals() -> dict[str, Any]: ... @disjoint_base -class map(Generic[_S]): +class map(Iterator[_S]): # 3.14 adds `strict` argument. if sys.version_info >= (3, 14): @overload @@ -2033,7 +2033,7 @@ class _SupportsReversed(Protocol[_T_co]): def __reversed__(self) -> _T_co: ... @disjoint_base -class reversed(Generic[_T_co]): +class reversed(Iterator[_T_co]): @overload def __new__(cls, sequence: _SupportsReversed[_T], /) -> _T: ... # type: ignore[misc] @overload @@ -2113,7 +2113,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ... def vars(object: Any = ..., /) -> dict[str, Any]: ... @disjoint_base -class zip(Generic[_T_co]): +class zip(Iterator[_T_co]): @overload def __new__(cls, *, strict: bool = False) -> zip[Any]: ... @overload diff --git a/mypy/typeshed/stdlib/csv.pyi b/mypy/typeshed/stdlib/csv.pyi index f8ab5f000a043..f3b4286a6b495 100644 --- a/mypy/typeshed/stdlib/csv.pyi +++ b/mypy/typeshed/stdlib/csv.pyi @@ -21,7 +21,7 @@ if sys.version_info >= (3, 12): from _csv import QUOTE_NOTNULL as QUOTE_NOTNULL, QUOTE_STRINGS as QUOTE_STRINGS from _csv import Reader, Writer from _typeshed import SupportsWrite -from collections.abc import Collection, Iterable, Mapping, Sequence +from collections.abc import Collection, Iterable, Iterator, Mapping, Sequence from types import GenericAlias from typing import Any, Generic, Literal, TypeVar, overload from typing_extensions import Self @@ -69,7 +69,7 @@ class excel(Dialect): ... class excel_tab(excel): ... class unix_dialect(Dialect): ... -class DictReader(Generic[_T]): +class DictReader(Iterator[dict[_T | Any, str | Any]], Generic[_T]): fieldnames: Sequence[_T] | None restkey: _T | None restval: str | Any | None diff --git a/mypy/typeshed/stdlib/fileinput.pyi b/mypy/typeshed/stdlib/fileinput.pyi index 37783254c70fa..db9c228f5f28e 100644 --- a/mypy/typeshed/stdlib/fileinput.pyi +++ b/mypy/typeshed/stdlib/fileinput.pyi @@ -1,8 +1,8 @@ import sys from _typeshed import AnyStr_co, StrOrBytesPath -from collections.abc import Callable, Iterable +from collections.abc import Callable, Iterable, Iterator from types import GenericAlias, TracebackType -from typing import IO, Any, AnyStr, Generic, Literal, Protocol, TypeAlias, overload, type_check_only +from typing import IO, Any, AnyStr, Literal, Protocol, TypeAlias, overload, type_check_only from typing_extensions import Self, deprecated __all__ = [ @@ -74,7 +74,7 @@ def fileno() -> int: ... def isfirstline() -> bool: ... def isstdin() -> bool: ... -class FileInput(Generic[AnyStr]): +class FileInput(Iterator[AnyStr]): # encoding and errors are added @overload def __init__( diff --git a/mypy/typeshed/stdlib/itertools.pyi b/mypy/typeshed/stdlib/itertools.pyi index 60e79bc2e4113..fd7daf11e8086 100644 --- a/mypy/typeshed/stdlib/itertools.pyi +++ b/mypy/typeshed/stdlib/itertools.pyi @@ -28,7 +28,7 @@ _Predicate = Callable[[_T], object] # Technically count can take anything that implements a number protocol and has an add method # but we can't enforce the add method @disjoint_base -class count(Generic[_N]): +class count(Iterator[_N]): @overload def __new__(cls) -> count[int]: ... @overload @@ -40,13 +40,13 @@ class count(Generic[_N]): def __iter__(self) -> Self: ... @disjoint_base -class cycle(Generic[_T]): +class cycle(Iterator[_T]): def __new__(cls, iterable: Iterable[_T], /) -> Self: ... def __next__(self) -> _T: ... def __iter__(self) -> Self: ... @disjoint_base -class repeat(Generic[_T]): +class repeat(Iterator[_T]): @overload def __new__(cls, object: _T) -> Self: ... @overload @@ -57,7 +57,7 @@ class repeat(Generic[_T]): def __length_hint__(self) -> int: ... @disjoint_base -class accumulate(Generic[_T]): +class accumulate(Iterator[_T]): @overload def __new__(cls, iterable: Iterable[_T], func: None = None, *, initial: _T | None = None) -> Self: ... @overload @@ -67,7 +67,7 @@ class accumulate(Generic[_T]): def __next__(self) -> _T: ... @disjoint_base -class chain(Generic[_T]): +class chain(Iterator[_T]): def __new__(cls, *iterables: Iterable[_T]) -> Self: ... def __next__(self) -> _T: ... def __iter__(self) -> Self: ... @@ -77,25 +77,25 @@ class chain(Generic[_T]): def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... @disjoint_base -class compress(Generic[_T]): +class compress(Iterator[_T]): def __new__(cls, data: Iterable[_T], selectors: Iterable[Any]) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> _T: ... @disjoint_base -class dropwhile(Generic[_T]): +class dropwhile(Iterator[_T]): def __new__(cls, predicate: _Predicate[_T], iterable: Iterable[_T], /) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> _T: ... @disjoint_base -class filterfalse(Generic[_T]): +class filterfalse(Iterator[_T]): def __new__(cls, function: _Predicate[_T] | None, iterable: Iterable[_T], /) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> _T: ... @disjoint_base -class groupby(Generic[_T_co, _S_co]): +class groupby(Iterator[tuple[_T_co, Iterator[_S_co]]], Generic[_T_co, _S_co]): @overload def __new__(cls, iterable: Iterable[_T1], key: None = None) -> groupby[_T1, _T1]: ... @overload @@ -105,7 +105,7 @@ class groupby(Generic[_T_co, _S_co]): def __next__(self) -> tuple[_T_co, Iterator[_S_co]]: ... @disjoint_base -class islice(Generic[_T]): +class islice(Iterator[_T]): @overload def __new__(cls, iterable: Iterable[_T], stop: int | None, /) -> Self: ... @overload @@ -115,13 +115,13 @@ class islice(Generic[_T]): def __next__(self) -> _T: ... @disjoint_base -class starmap(Generic[_T_co]): +class starmap(Iterator[_T_co]): def __new__(cls, function: Callable[..., _T], iterable: Iterable[Iterable[Any]], /) -> starmap[_T]: ... def __iter__(self) -> Self: ... def __next__(self) -> _T_co: ... @disjoint_base -class takewhile(Generic[_T]): +class takewhile(Iterator[_T]): def __new__(cls, predicate: _Predicate[_T], iterable: Iterable[_T], /) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> _T: ... @@ -129,7 +129,7 @@ class takewhile(Generic[_T]): def tee(iterable: Iterable[_T], n: int = 2, /) -> tuple[Iterator[_T], ...]: ... @disjoint_base -class zip_longest(Generic[_T_co]): +class zip_longest(Iterator[_T_co]): # one iterable (fillvalue doesn't matter) @overload def __new__(cls, iter1: Iterable[_T1], /, *, fillvalue: object = None) -> zip_longest[tuple[_T1]]: ... @@ -209,7 +209,7 @@ class zip_longest(Generic[_T_co]): def __next__(self) -> _T_co: ... @disjoint_base -class product(Generic[_T_co]): +class product(Iterator[_T_co]): @overload def __new__(cls, iter1: Iterable[_T1], /) -> product[tuple[_T1]]: ... @overload @@ -296,7 +296,7 @@ class product(Generic[_T_co]): def __next__(self) -> _T_co: ... @disjoint_base -class permutations(Generic[_T_co]): +class permutations(Iterator[_T_co]): @overload def __new__(cls, iterable: Iterable[_T], r: Literal[2]) -> permutations[tuple[_T, _T]]: ... @overload @@ -312,7 +312,7 @@ class permutations(Generic[_T_co]): def __next__(self) -> _T_co: ... @disjoint_base -class combinations(Generic[_T_co]): +class combinations(Iterator[_T_co]): @overload def __new__(cls, iterable: Iterable[_T], r: Literal[2]) -> combinations[tuple[_T, _T]]: ... @overload @@ -328,7 +328,7 @@ class combinations(Generic[_T_co]): def __next__(self) -> _T_co: ... @disjoint_base -class combinations_with_replacement(Generic[_T_co]): +class combinations_with_replacement(Iterator[_T_co]): @overload def __new__(cls, iterable: Iterable[_T], r: Literal[2]) -> combinations_with_replacement[tuple[_T, _T]]: ... @overload @@ -344,14 +344,14 @@ class combinations_with_replacement(Generic[_T_co]): def __next__(self) -> _T_co: ... @disjoint_base -class pairwise(Generic[_T_co]): +class pairwise(Iterator[_T_co]): def __new__(cls, iterable: Iterable[_T], /) -> pairwise[tuple[_T, _T]]: ... def __iter__(self) -> Self: ... def __next__(self) -> _T_co: ... if sys.version_info >= (3, 12): @disjoint_base - class batched(Generic[_T_co]): + class batched(Iterator[_T_co], Generic[_T_co]): if sys.version_info >= (3, 13): @overload def __new__(cls, iterable: Iterable[_T], n: Literal[1], *, strict: Literal[True]) -> batched[tuple[_T]]: ... diff --git a/mypy/typeshed/stdlib/multiprocessing/pool.pyi b/mypy/typeshed/stdlib/multiprocessing/pool.pyi index 5642e50d0e768..203c5887ca7ee 100644 --- a/mypy/typeshed/stdlib/multiprocessing/pool.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/pool.pyi @@ -1,4 +1,4 @@ -from collections.abc import Callable, Iterable, Mapping +from collections.abc import Callable, Iterable, Iterator, Mapping from multiprocessing.context import DefaultContext, Process as _Process from types import GenericAlias, TracebackType from typing import Any, Final, Generic, TypeVar @@ -32,7 +32,7 @@ class MapResult(ApplyResult[list[_T]]): error_callback: Callable[[BaseException], object] | None, ) -> None: ... -class IMapIterator(Generic[_T]): +class IMapIterator(Iterator[_T]): def __init__(self, pool: Pool) -> None: ... def __iter__(self) -> Self: ... def next(self, timeout: float | None = None) -> _T: ... diff --git a/mypy/typeshed/stdlib/sqlite3/__init__.pyi b/mypy/typeshed/stdlib/sqlite3/__init__.pyi index 80a02079dd054..d1065a509af52 100644 --- a/mypy/typeshed/stdlib/sqlite3/__init__.pyi +++ b/mypy/typeshed/stdlib/sqlite3/__init__.pyi @@ -437,7 +437,7 @@ class Connection: ) -> Literal[False]: ... @disjoint_base -class Cursor: +class Cursor(Iterator[Any]): arraysize: int @property def connection(self) -> Connection: ... From 5f733088e7802e69097a2db73df46d0a0e4ba41c Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 23 Feb 2026 12:00:18 +0100 Subject: [PATCH 07/12] Revert Use contravariant type variable in Container --- mypy/typeshed/stdlib/typing.pyi | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/mypy/typeshed/stdlib/typing.pyi b/mypy/typeshed/stdlib/typing.pyi index 35031a27445be..be183d294aaea 100644 --- a/mypy/typeshed/stdlib/typing.pyi +++ b/mypy/typeshed/stdlib/typing.pyi @@ -663,17 +663,14 @@ class AsyncGenerator(AsyncIterator[_YieldT_co], Protocol[_YieldT_co, _SendT_cont def aclose(self) -> Coroutine[Any, Any, None]: ... -_ContainerT_contra = TypeVar("_ContainerT_contra", contravariant=True, default=Any) - @runtime_checkable -class Container(Protocol[_ContainerT_contra]): +class Container(Protocol[_T_co]): # This is generic more on vibes than anything else @abstractmethod - def __contains__(self, x: _ContainerT_contra, /) -> bool: ... + def __contains__(self, x: object, /) -> bool: ... @runtime_checkable -class Collection(Iterable[_T_co], Container[Any], Protocol[_T_co]): - # Note: need to use Container[Any] instead of Container[_T_co] to ensure covariance. +class Collection(Iterable[_T_co], Container[_T_co], Protocol[_T_co]): # Implement Sized (but don't have it as a base class). @abstractmethod def __len__(self) -> int: ... From c7aac17dcd189421f8d10e57c6408e9b926e0182 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Wed, 8 Apr 2026 00:01:44 +0100 Subject: [PATCH 08/12] Revert dict.__or__ typeshed change --- mypy/typeshed/stdlib/builtins.pyi | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi index d0963d5b70546..532ba324d2226 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi @@ -1235,15 +1235,28 @@ class dict(MutableMapping[_KT, _VT]): __hash__: ClassVar[None] # type: ignore[assignment] def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... if sys.version_info >= (3, 15): + @overload + def __or__(self, value: dict[_KT, _VT] | frozendict[_KT, _VT], /) -> dict[_KT, _VT]: ... + @overload def __or__(self, value: dict[_T1, _T2] | frozendict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ... + @overload + def __ror__(self, value: dict[_KT, _VT], /) -> dict[_KT, _VT]: ... @overload def __ror__(self, value: dict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ... @overload + def __ror__(self, value: frozendict[_KT, _VT], /) -> frozendict[_KT, _VT]: ... + @overload def __ror__(self, value: frozendict[_T1, _T2], /) -> frozendict[_KT | _T1, _VT | _T2]: ... else: + @overload + def __or__(self, value: dict[_KT, _VT], /) -> dict[_KT, _VT]: ... + @overload def __or__(self, value: dict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ... + @overload + def __ror__(self, value: dict[_KT, _VT], /) -> dict[_KT, _VT]: ... + @overload def __ror__(self, value: dict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ... # dict.__ior__ should be kept roughly in line with MutableMapping.update() @@ -1297,11 +1310,18 @@ if sys.version_info >= (3, 15): def __iter__(self) -> Iterator[_KT]: ... def __hash__(self) -> int: ... def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... + @overload + def __or__(self, value: dict[_KT, _VT] | frozendict[_KT, _VT], /) -> frozendict[_KT, _VT]: ... + @overload def __or__(self, value: dict[_T1, _T2] | frozendict[_T1, _T2], /) -> frozendict[_KT | _T1, _VT | _T2]: ... + @overload + def __ror__(self, value: dict[_KT, _VT], /) -> dict[_KT, _VT]: ... @overload def __ror__(self, value: dict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ... @overload + def __ror__(self, value: frozendict[_KT, _VT], /) -> frozendict[_KT, _VT]: ... + @overload def __ror__(self, value: frozendict[_T1, _T2], /) -> frozendict[_KT | _T1, _VT | _T2]: ... @disjoint_base From 5e3a871602c161e74420b66513d9c8bdc382e935 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Wed, 6 May 2026 19:49:41 -0700 Subject: [PATCH 09/12] Revert operator changes --- mypy/typeshed/stdlib/_operator.pyi | 58 ++++++++---------------------- 1 file changed, 14 insertions(+), 44 deletions(-) diff --git a/mypy/typeshed/stdlib/_operator.pyi b/mypy/typeshed/stdlib/_operator.pyi index 04dae79dcd52d..29a6d70572028 100644 --- a/mypy/typeshed/stdlib/_operator.pyi +++ b/mypy/typeshed/stdlib/_operator.pyi @@ -1,15 +1,5 @@ import sys -from _typeshed import ( - SupportsAdd, - SupportsGetItem, - SupportsMod, - SupportsMul, - SupportsRAdd, - SupportsRMod, - SupportsRMul, - SupportsRSub, - SupportsSub, -) +from _typeshed import SupportsGetItem from collections.abc import Callable, Container, Iterable, MutableMapping, MutableSequence, Sequence from operator import attrgetter as attrgetter, itemgetter as itemgetter, methodcaller as methodcaller from typing import Any, AnyStr, ParamSpec, Protocol, SupportsAbs, SupportsIndex, TypeAlias, TypeVar, overload, type_check_only @@ -18,7 +8,6 @@ from typing_extensions import TypeIs _R = TypeVar("_R") _T = TypeVar("_T") _T_co = TypeVar("_T_co", covariant=True) -_T_contra = TypeVar("_T_contra", contravariant=True) _K = TypeVar("_K") _V = TypeVar("_V") _P = ParamSpec("_P") @@ -69,43 +58,24 @@ def truth(a: object, /) -> bool: ... def is_(a: object, b: object, /) -> bool: ... def is_not(a: object, b: object, /) -> bool: ... def abs(a: SupportsAbs[_T], /) -> _T: ... - -@overload -def add(a: SupportsAdd[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ... -@overload -def add(a: _T_contra, b: SupportsRAdd[_T_contra, _T_co], /) -> _T_co: ... - -def and_(a, b, /): ... -def floordiv(a, b, /): ... +def add(a: Any, b: Any, /) -> Any: ... +def and_(a: Any, b: Any, /) -> Any: ... +def floordiv(a: Any, b: Any, /) -> Any: ... def index(a: SupportsIndex, /) -> int: ... def inv(a: _SupportsInversion[_T_co], /) -> _T_co: ... def invert(a: _SupportsInversion[_T_co], /) -> _T_co: ... -def lshift(a, b, /): ... - -@overload -def mod(a: SupportsMod[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ... -@overload -def mod(a: _T_contra, b: SupportsRMod[_T_contra, _T_co], /) -> _T_co: ... - -@overload -def mul(a: SupportsMul[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ... -@overload -def mul(a: _T_contra, b: SupportsRMul[_T_contra, _T_co], /) -> _T_co: ... - -def matmul(a, b, /): ... +def lshift(a: Any, b: Any, /) -> Any: ... +def mod(a: Any, b: Any, /) -> Any: ... +def mul(a: Any, b: Any, /) -> Any: ... +def matmul(a: Any, b: Any, /) -> Any: ... def neg(a: _SupportsNeg[_T_co], /) -> _T_co: ... -def or_(a, b, /): ... +def or_(a: Any, b: Any, /) -> Any: ... def pos(a: _SupportsPos[_T_co], /) -> _T_co: ... -def pow(a, b, /): ... -def rshift(a, b, /): ... - -@overload -def sub(a: SupportsSub[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ... -@overload -def sub(a: _T_contra, b: SupportsRSub[_T_contra, _T_co], /) -> _T_co: ... - -def truediv(a, b, /): ... -def xor(a, b, /): ... +def pow(a: Any, b: Any, /) -> Any: ... +def rshift(a: Any, b: Any, /) -> Any: ... +def sub(a: Any, b: Any, /) -> Any: ... +def truediv(a: Any, b: Any, /) -> Any: ... +def xor(a: Any, b: Any, /) -> Any: ... def concat(a: Sequence[_T], b: Sequence[_T], /) -> Sequence[_T]: ... def contains(a: Container[object], b: object, /) -> bool: ... def countOf(a: Iterable[object], b: object, /) -> int: ... From eebcc5b2f99d7f520c7eb51edf8886e7781aa7f7 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Sat, 29 Oct 2022 12:47:21 -0700 Subject: [PATCH 10/12] Revert sum literal integer change (#13961) This is allegedly causing large performance problems, see 13821 typeshed/8231 had zero hits on mypy_primer, so it's not the worst thing to undo. Patching this in typeshed also feels weird, since there's a more general soundness issue. If a typevar has a bound or constraint, we might not want to solve it to a Literal. If we can confirm the performance regression or fix the unsoundness within mypy, I might pursue upstreaming this in typeshed. (Reminder: add this to the sync_typeshed script once merged) --- mypy/typeshed/stdlib/builtins.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi index 532ba324d2226..20c21629ad2a6 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi @@ -2119,7 +2119,7 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit # without creating many false-positive errors (see #7578). # Instead, we special-case the most common examples of this: bool and literal integers. @overload -def sum(iterable: Iterable[bool | _LiteralInteger], /, start: int = 0) -> int: ... +def sum(iterable: Iterable[bool], /, start: int = 0) -> int: ... @overload def sum(iterable: Iterable[_SupportsSumNoDefaultT], /) -> _SupportsSumNoDefaultT | Literal[0]: ... @overload From 5d1fe2d4125d8438e323df6187857dcae81a07c4 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Mon, 1 May 2023 20:34:55 +0100 Subject: [PATCH 11/12] Revert typeshed ctypes change The plugin provides superior type checking: https://github.com/python/mypy/pull/13987#issuecomment-1310863427 A manual cherry-pick of e437cdf. --- mypy/typeshed/stdlib/_ctypes.pyi | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/mypy/typeshed/stdlib/_ctypes.pyi b/mypy/typeshed/stdlib/_ctypes.pyi index 36365cea3aa82..0990dac1998b0 100644 --- a/mypy/typeshed/stdlib/_ctypes.pyi +++ b/mypy/typeshed/stdlib/_ctypes.pyi @@ -324,12 +324,7 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType): @_type_.setter def _type_(self, value: type[_CT]) -> None: ... - # Note: only available if _CT == c_char - @property - def raw(self) -> bytes: ... - @raw.setter - def raw(self, value: ReadableBuffer) -> None: ... - + raw: bytes # Note: only available if _CT == c_char value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise # TODO: These methods cannot be annotated correctly at the moment. # All of these "Any"s stand for the array's element type, but it's not possible to use _CT From 007a7d0e15881ce305eec788a5691bdd00acdf97 Mon Sep 17 00:00:00 2001 From: Shantanu Jain Date: Sun, 22 Feb 2026 20:37:48 -0800 Subject: [PATCH 12/12] Temporarily revert contextlib deprecation --- mypy/typeshed/stdlib/contextlib.pyi | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/mypy/typeshed/stdlib/contextlib.pyi b/mypy/typeshed/stdlib/contextlib.pyi index dd601675265cc..ee577621c720d 100644 --- a/mypy/typeshed/stdlib/contextlib.pyi +++ b/mypy/typeshed/stdlib/contextlib.pyi @@ -5,7 +5,7 @@ from abc import ABC, abstractmethod from collections.abc import AsyncGenerator, AsyncIterator, Awaitable, Callable, Generator, Iterator from types import TracebackType from typing import Any, Generic, ParamSpec, Protocol, TypeAlias, TypeVar, overload, runtime_checkable, type_check_only -from typing_extensions import Self, deprecated +from typing_extensions import Self __all__ = [ "aclosing", @@ -84,12 +84,6 @@ class _GeneratorContextManager( self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> bool | None: ... -@overload -def contextmanager(func: Callable[_P, Generator[_T_co, None, object]]) -> Callable[_P, _GeneratorContextManager[_T_co]]: ... -@overload -@deprecated( - "Annotating the return type as `-> Iterator[Foo]` with `@contextmanager` is deprecated. Use `-> Generator[Foo]` instead." -) def contextmanager(func: Callable[_P, Iterator[_T_co]]) -> Callable[_P, _GeneratorContextManager[_T_co]]: ... _AF = TypeVar("_AF", bound=Callable[..., Awaitable[Any]]) @@ -107,13 +101,6 @@ class _AsyncGeneratorContextManager( self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> bool | None: ... -@overload -def asynccontextmanager(func: Callable[_P, AsyncGenerator[_T_co]]) -> Callable[_P, _AsyncGeneratorContextManager[_T_co]]: ... -@overload -@deprecated( - "Annotating the return type as `-> AsyncIterator[Foo]` with `@asynccontextmanager` is deprecated. " - "Use `-> AsyncGenerator[Foo]` instead." -) def asynccontextmanager(func: Callable[_P, AsyncIterator[_T_co]]) -> Callable[_P, _AsyncGeneratorContextManager[_T_co]]: ... @type_check_only