diff --git a/misc/typeshed_patches/0001-Adjust-stubs-to-fix-mypy-lookup-error-due-to-circula.patch b/misc/typeshed_patches/0001-Adjust-stubs-to-fix-mypy-lookup-error-due-to-circula.patch new file mode 100644 index 0000000000000..d8c4e24af917b --- /dev/null +++ b/misc/typeshed_patches/0001-Adjust-stubs-to-fix-mypy-lookup-error-due-to-circula.patch @@ -0,0 +1,37 @@ +From 5c922a2484f2e18c7f901e62bb499b6414cf1090 Mon Sep 17 00:00:00 2001 +From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> +Date: Wed, 18 Feb 2026 13:11:02 +0100 +Subject: [PATCH] Adjust stubs to fix mypy lookup error due to circular + dependencies in stubs + +--- + mypy/typeshed/stdlib/time.pyi | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/mypy/typeshed/stdlib/time.pyi b/mypy/typeshed/stdlib/time.pyi +index 64a009318..d0853792b 100644 +--- a/mypy/typeshed/stdlib/time.pyi ++++ b/mypy/typeshed/stdlib/time.pyi +@@ -1,16 +1,16 @@ + import sys + from _typeshed import structseq +-from typing import Any, Final, Literal, Protocol, SupportsFloat, SupportsIndex, final, type_check_only ++from typing import Any, Final, Literal, Protocol, SupportsFloat, SupportsIndex, Union, final, type_check_only + from typing_extensions import TypeAlias + + _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 +-- +2.53.0 + diff --git a/misc/typeshed_patches/0001-Remove-use-of-LiteralString-in-builtins-13743.patch b/misc/typeshed_patches/0001-Remove-use-of-LiteralString-in-builtins-13743.patch index b8d0d9812198a..3ca8f4deec922 100644 --- a/misc/typeshed_patches/0001-Remove-use-of-LiteralString-in-builtins-13743.patch +++ b/misc/typeshed_patches/0001-Remove-use-of-LiteralString-in-builtins-13743.patch @@ -1,14 +1,14 @@ -From ed11d7e0204868ef1a43c17ed950372b1d78f497 Mon Sep 17 00:00:00 2001 +From b3021cdc4b4c2cf547c5bc2d1d21a5a00ffea001 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] Remove use of LiteralString in builtins (#13743) --- - mypy/typeshed/stdlib/builtins.pyi | 100 +----------------------------- - 1 file changed, 1 insertion(+), 99 deletions(-) + mypy/typeshed/stdlib/builtins.pyi | 98 ------------------------------- + 1 file changed, 98 deletions(-) diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi -index 693dd0b77..8acdeadff 100644 +index efc51fe25..8600a372b 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi @@ -64,7 +64,6 @@ from typing import ( # noqa: Y022,UP035 @@ -163,10 +163,9 @@ index 693dd0b77..8acdeadff 100644 def __eq__(self, value: object, /) -> bool: ... def __ge__(self, value: str, /) -> bool: ... - @overload -- def __getitem__(self: LiteralString, key: SupportsIndex | slice, /) -> LiteralString: ... +- def __getitem__(self: LiteralString, key: SupportsIndex | slice[SupportsIndex | None], /) -> LiteralString: ... - @overload -- def __getitem__(self, key: SupportsIndex | slice, /) -> str: ... # type: ignore[misc] -+ def __getitem__(self, key: SupportsIndex | slice, /) -> str: ... + def __getitem__(self, key: SupportsIndex | slice[SupportsIndex | None], /) -> str: ... # type: ignore[misc] def __gt__(self, value: str, /) -> bool: ... def __hash__(self) -> int: ... - @overload diff --git a/mypy/server/aststrip.py b/mypy/server/aststrip.py index cf706e97c3da7..3e91de8d33a15 100644 --- a/mypy/server/aststrip.py +++ b/mypy/server/aststrip.py @@ -136,9 +136,7 @@ def visit_class_def(self, node: ClassDef) -> None: node.type_vars = [] node.base_type_exprs.extend(node.removed_base_type_exprs) node.removed_base_type_exprs = [] - node.defs.body = [ - s for s in node.defs.body if s not in to_delete # type: ignore[comparison-overlap] - ] + node.defs.body = [s for s in node.defs.body if s not in to_delete] with self.enter_class(node.info): super().visit_class_def(node) node.defs.body.extend(node.removed_statements) diff --git a/mypy/typeshed/stdlib/VERSIONS b/mypy/typeshed/stdlib/VERSIONS index 6fcf0161790d6..e26bb8da2574e 100644 --- a/mypy/typeshed/stdlib/VERSIONS +++ b/mypy/typeshed/stdlib/VERSIONS @@ -253,6 +253,7 @@ py_compile: 3.0- pyclbr: 3.0- pydoc: 3.0- pydoc_data: 3.0- +pydoc_data.module_docs: 3.13- pyexpat: 3.0- queue: 3.0- quopri: 3.0- diff --git a/mypy/typeshed/stdlib/_collections_abc.pyi b/mypy/typeshed/stdlib/_collections_abc.pyi index 319577c9284bc..0fa81662dfbc1 100644 --- a/mypy/typeshed/stdlib/_collections_abc.pyi +++ b/mypy/typeshed/stdlib/_collections_abc.pyi @@ -1,7 +1,7 @@ import sys from abc import abstractmethod from types import MappingProxyType -from typing import ( # noqa: Y022,Y038,UP035,Y057 +from typing import ( # noqa: Y022,Y038,UP035,Y057,RUF100 AbstractSet as Set, AsyncGenerator as AsyncGenerator, AsyncIterable as AsyncIterable, diff --git a/mypy/typeshed/stdlib/_ctypes.pyi b/mypy/typeshed/stdlib/_ctypes.pyi index b7a3fb104596d..0e02092a361c9 100644 --- a/mypy/typeshed/stdlib/_ctypes.pyi +++ b/mypy/typeshed/stdlib/_ctypes.pyi @@ -6,7 +6,7 @@ from abc import abstractmethod from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence from ctypes import CDLL, ArgumentError as ArgumentError, c_void_p from types import GenericAlias -from typing import Any, ClassVar, Final, Generic, Literal, TypeVar, final, overload, type_check_only +from typing import Any, ClassVar, Final, Generic, Literal, SupportsIndex, TypeVar, final, overload, type_check_only from typing_extensions import Self, TypeAlias _T = TypeVar("_T") @@ -134,7 +134,7 @@ class _Pointer(_PointerLike, _CData, Generic[_CT], metaclass=_PyCPointerType): @overload def __getitem__(self, key: int, /) -> Any: ... @overload - def __getitem__(self, key: slice, /) -> list[Any]: ... + def __getitem__(self, key: slice[SupportsIndex | None], /) -> list[Any]: ... def __setitem__(self, key: int, value: Any, /) -> None: ... if sys.version_info < (3, 14): @@ -338,11 +338,11 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType): @overload def __getitem__(self, key: int, /) -> Any: ... @overload - def __getitem__(self, key: slice, /) -> list[Any]: ... + def __getitem__(self, key: slice[SupportsIndex | None], /) -> list[Any]: ... @overload def __setitem__(self, key: int, value: Any, /) -> None: ... @overload - def __setitem__(self, key: slice, value: Iterable[Any], /) -> None: ... + def __setitem__(self, key: slice[SupportsIndex | None], value: Iterable[Any], /) -> None: ... def __iter__(self) -> Iterator[Any]: ... # Can't inherit from Sized because the metaclass conflict between # Sized and _CData prevents using _CDataMeta. diff --git a/mypy/typeshed/stdlib/_operator.pyi b/mypy/typeshed/stdlib/_operator.pyi index cb1c1bcfc4aab..e1ef5c4bf0678 100644 --- a/mypy/typeshed/stdlib/_operator.pyi +++ b/mypy/typeshed/stdlib/_operator.pyi @@ -80,20 +80,20 @@ 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: ... @overload -def delitem(a: MutableSequence[Any], b: SupportsIndex, /) -> None: ... +def delitem(a: MutableSequence[Any], b: int, /) -> None: ... @overload -def delitem(a: MutableSequence[Any], b: slice, /) -> None: ... +def delitem(a: MutableSequence[Any], b: slice[int | None], /) -> None: ... @overload def delitem(a: MutableMapping[_K, Any], b: _K, /) -> None: ... @overload -def getitem(a: Sequence[_T], b: slice, /) -> Sequence[_T]: ... +def getitem(a: Sequence[_T], b: slice[int | None], /) -> Sequence[_T]: ... @overload def getitem(a: SupportsGetItem[_K, _V], b: _K, /) -> _V: ... def indexOf(a: Iterable[_T], b: _T, /) -> int: ... @overload -def setitem(a: MutableSequence[_T], b: SupportsIndex, c: _T, /) -> None: ... +def setitem(a: MutableSequence[_T], b: int, c: _T, /) -> None: ... @overload -def setitem(a: MutableSequence[_T], b: slice, c: Sequence[_T], /) -> None: ... +def setitem(a: MutableSequence[_T], b: slice[int | None], c: Sequence[_T], /) -> None: ... @overload def setitem(a: MutableMapping[_K, _V], b: _K, c: _V, /) -> None: ... def length_hint(obj: object, default: int = 0, /) -> int: ... diff --git a/mypy/typeshed/stdlib/_socket.pyi b/mypy/typeshed/stdlib/_socket.pyi index cdad886b3415e..372b35f22f175 100644 --- a/mypy/typeshed/stdlib/_socket.pyi +++ b/mypy/typeshed/stdlib/_socket.pyi @@ -587,7 +587,7 @@ if sys.platform != "linux": has_ipv6: bool -if sys.platform != "darwin" and sys.platform != "linux": +if sys.platform != "darwin": BDADDR_ANY: Final = "00:00:00:00:00:00" BDADDR_LOCAL: Final = "00:00:00:FF:FF:FF" @@ -660,16 +660,16 @@ if sys.platform == "darwin": PF_SYSTEM: Final[int] SYSPROTO_CONTROL: Final[int] -if sys.platform != "darwin" and sys.platform != "linux": +if sys.platform != "darwin": AF_BLUETOOTH: Final[int] -if sys.platform != "win32" and sys.platform != "darwin" and sys.platform != "linux": +if sys.platform != "win32" and sys.platform != "darwin": # Linux and some BSD support is explicit in the docs # Windows and macOS do not support in practice BTPROTO_HCI: Final[int] BTPROTO_L2CAP: Final[int] BTPROTO_SCO: Final[int] # not in FreeBSD -if sys.platform != "darwin" and sys.platform != "linux": +if sys.platform != "darwin": BTPROTO_RFCOMM: Final[int] if sys.platform == "linux": diff --git a/mypy/typeshed/stdlib/_thread.pyi b/mypy/typeshed/stdlib/_thread.pyi index 6969ae48cae79..1323a55e9aad8 100644 --- a/mypy/typeshed/stdlib/_thread.pyi +++ b/mypy/typeshed/stdlib/_thread.pyi @@ -5,7 +5,7 @@ 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, disjoint_base +from typing_extensions import TypeVarTuple, Unpack, deprecated, disjoint_base _Ts = TypeVarTuple("_Ts") @@ -38,9 +38,12 @@ if sys.version_info >= (3, 13): def acquire(self, blocking: bool = True, timeout: float = -1) -> bool: ... def release(self) -> None: ... def locked(self) -> bool: ... - def acquire_lock(self, blocking: bool = True, timeout: float = -1) -> bool: ... - def release_lock(self) -> None: ... - def locked_lock(self) -> bool: ... + @deprecated("Obsolete synonym. Use `acquire()` instead.") + def acquire_lock(self, blocking: bool = True, timeout: float = -1) -> bool: ... # undocumented + @deprecated("Obsolete synonym. Use `release()` instead.") + def release_lock(self) -> None: ... # undocumented + @deprecated("Obsolete synonym. Use `locked()` instead.") + def locked_lock(self) -> bool: ... # undocumented def __enter__(self) -> bool: ... def __exit__( self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None @@ -53,9 +56,12 @@ else: def acquire(self, blocking: bool = True, timeout: float = -1) -> bool: ... def release(self) -> None: ... def locked(self) -> bool: ... - def acquire_lock(self, blocking: bool = True, timeout: float = -1) -> bool: ... - def release_lock(self) -> None: ... - def locked_lock(self) -> bool: ... + @deprecated("Obsolete synonym. Use `acquire()` instead.") + def acquire_lock(self, blocking: bool = True, timeout: float = -1) -> bool: ... # undocumented + @deprecated("Obsolete synonym. Use `release()` instead.") + def release_lock(self) -> None: ... # undocumented + @deprecated("Obsolete synonym. Use `locked()` instead.") + def locked_lock(self) -> bool: ... # undocumented def __enter__(self) -> bool: ... def __exit__( self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None @@ -65,12 +71,12 @@ else: def start_new_thread(function: Callable[[Unpack[_Ts]], object], args: tuple[Unpack[_Ts]], /) -> int: ... @overload def start_new_thread(function: Callable[..., object], args: tuple[Any, ...], kwargs: dict[str, Any], /) -> int: ... - -# Obsolete synonym for start_new_thread() @overload -def start_new(function: Callable[[Unpack[_Ts]], object], args: tuple[Unpack[_Ts]], /) -> int: ... +@deprecated("Obsolete synonym. Use `start_new_thread()` instead.") +def start_new(function: Callable[[Unpack[_Ts]], object], args: tuple[Unpack[_Ts]], /) -> int: ... # undocumented @overload -def start_new(function: Callable[..., object], args: tuple[Any, ...], kwargs: dict[str, Any], /) -> int: ... +@deprecated("Obsolete synonym. Use `start_new_thread()` instead.") +def start_new(function: Callable[..., object], args: tuple[Any, ...], kwargs: dict[str, Any], /) -> int: ... # undocumented if sys.version_info >= (3, 10): def interrupt_main(signum: signal.Signals = signal.SIGINT, /) -> None: ... @@ -79,9 +85,11 @@ else: def interrupt_main() -> None: ... def exit() -> NoReturn: ... -def exit_thread() -> NoReturn: ... # Obsolete synonym for exit() +@deprecated("Obsolete synonym. Use `exit()` instead.") +def exit_thread() -> NoReturn: ... # undocumented def allocate_lock() -> LockType: ... -def allocate() -> LockType: ... # Obsolete synonym for allocate_lock() +@deprecated("Obsolete synonym. Use `allocate_lock()` instead.") +def allocate() -> LockType: ... # undocumented def get_ident() -> int: ... def stack_size(size: int = 0, /) -> int: ... diff --git a/mypy/typeshed/stdlib/_typeshed/README.md b/mypy/typeshed/stdlib/_typeshed/README.md index f4808944fa7bd..3e4f3cb5cd48c 100644 --- a/mypy/typeshed/stdlib/_typeshed/README.md +++ b/mypy/typeshed/stdlib/_typeshed/README.md @@ -1,6 +1,6 @@ # Utility types for typeshed -This package and its submodules contains various common types used by +This package and its submodules contain various common types used by typeshed. It can also be used by packages outside typeshed, but beware the API stability guarantees below. diff --git a/mypy/typeshed/stdlib/_typeshed/__init__.pyi b/mypy/typeshed/stdlib/_typeshed/__init__.pyi index b786923880e13..89e93ab027069 100644 --- a/mypy/typeshed/stdlib/_typeshed/__init__.pyi +++ b/mypy/typeshed/stdlib/_typeshed/__init__.pyi @@ -300,7 +300,7 @@ WriteableBuffer: TypeAlias = Buffer ReadableBuffer: TypeAlias = Buffer # stable class SliceableBuffer(Buffer, Protocol): - def __getitem__(self, slice: slice, /) -> Sequence[int]: ... + def __getitem__(self, slice: slice[SupportsIndex | None], /) -> Sequence[int]: ... class IndexableBuffer(Buffer, Protocol): def __getitem__(self, i: int, /) -> int: ... @@ -308,7 +308,7 @@ class IndexableBuffer(Buffer, Protocol): class SupportsGetItemBuffer(SliceableBuffer, IndexableBuffer, Protocol): def __contains__(self, x: Any, /) -> bool: ... @overload - def __getitem__(self, slice: slice, /) -> Sequence[int]: ... + def __getitem__(self, slice: slice[SupportsIndex | None], /) -> Sequence[int]: ... @overload def __getitem__(self, i: int, /) -> int: ... diff --git a/mypy/typeshed/stdlib/argparse.pyi b/mypy/typeshed/stdlib/argparse.pyi index c87b8f4fcc4c4..c2a6f36911968 100644 --- a/mypy/typeshed/stdlib/argparse.pyi +++ b/mypy/typeshed/stdlib/argparse.pyi @@ -336,7 +336,10 @@ class HelpFormatter: def _format_usage( self, usage: str | None, actions: Iterable[Action], groups: Iterable[_MutuallyExclusiveGroup], prefix: str | None ) -> str: ... - def _format_actions_usage(self, actions: Iterable[Action], groups: Iterable[_MutuallyExclusiveGroup]) -> str: ... + if sys.version_info < (3, 14): + # Removed in Python 3.14.3 + def _format_actions_usage(self, actions: Iterable[Action], groups: Iterable[_MutuallyExclusiveGroup]) -> str: ... + def _format_text(self, text: str) -> str: ... def _format_action(self, action: Action) -> str: ... def _format_action_invocation(self, action: Action) -> str: ... diff --git a/mypy/typeshed/stdlib/array.pyi b/mypy/typeshed/stdlib/array.pyi index a6b0344a1e2ea..eb679dd50f722 100644 --- a/mypy/typeshed/stdlib/array.pyi +++ b/mypy/typeshed/stdlib/array.pyi @@ -80,12 +80,12 @@ class array(MutableSequence[_T]): @overload def __getitem__(self, key: SupportsIndex, /) -> _T: ... @overload - def __getitem__(self, key: slice, /) -> array[_T]: ... + def __getitem__(self, key: slice[SupportsIndex | None], /) -> array[_T]: ... @overload # type: ignore[override] def __setitem__(self, key: SupportsIndex, value: _T, /) -> None: ... @overload - def __setitem__(self, key: slice, value: array[_T], /) -> None: ... - def __delitem__(self, key: SupportsIndex | slice, /) -> None: ... + def __setitem__(self, key: slice[SupportsIndex | None], value: array[_T], /) -> None: ... + def __delitem__(self, key: SupportsIndex | slice[SupportsIndex | None], /) -> None: ... def __add__(self, value: array[_T], /) -> array[_T]: ... def __eq__(self, value: object, /) -> bool: ... def __ge__(self, value: array[_T], /) -> bool: ... diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi index 0f2196070de20..03c3bd2e17c74 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi @@ -37,7 +37,7 @@ from types import CellType, CodeType, GenericAlias, TracebackType # mypy crashes if any of {ByteString, Sequence, MutableSequence, Mapping, MutableMapping} # are imported from collections.abc in builtins.pyi -from typing import ( # noqa: Y022,UP035 +from typing import ( # noqa: Y022,UP035,RUF100 IO, Any, BinaryIO, @@ -549,7 +549,7 @@ class str(Sequence[str]): def __contains__(self, key: str, /) -> bool: ... # type: ignore[override] def __eq__(self, value: object, /) -> bool: ... def __ge__(self, value: str, /) -> bool: ... - def __getitem__(self, key: SupportsIndex | slice, /) -> str: ... + def __getitem__(self, key: SupportsIndex | slice[SupportsIndex | None], /) -> str: ... # type: ignore[misc] def __gt__(self, value: str, /) -> bool: ... def __hash__(self) -> int: ... def __iter__(self) -> Iterator[str]: ... # type: ignore[misc] @@ -648,7 +648,7 @@ class bytes(Sequence[int]): @overload def __getitem__(self, key: SupportsIndex, /) -> int: ... @overload - def __getitem__(self, key: slice, /) -> bytes: ... + def __getitem__(self, key: slice[SupportsIndex | None], /) -> bytes: ... def __add__(self, value: ReadableBuffer, /) -> bytes: ... def __mul__(self, value: SupportsIndex, /) -> bytes: ... def __rmul__(self, value: SupportsIndex, /) -> bytes: ... @@ -758,12 +758,12 @@ class bytearray(MutableSequence[int]): @overload def __getitem__(self, key: SupportsIndex, /) -> int: ... @overload - def __getitem__(self, key: slice, /) -> bytearray: ... + def __getitem__(self, key: slice[SupportsIndex | None], /) -> bytearray: ... @overload def __setitem__(self, key: SupportsIndex, value: SupportsIndex, /) -> None: ... @overload - def __setitem__(self, key: slice, value: Iterable[SupportsIndex] | bytes, /) -> None: ... - def __delitem__(self, key: SupportsIndex | slice, /) -> None: ... + def __setitem__(self, key: slice[SupportsIndex | None], value: Iterable[SupportsIndex] | bytes, /) -> None: ... + def __delitem__(self, key: SupportsIndex | slice[SupportsIndex | None], /) -> None: ... def __add__(self, value: ReadableBuffer, /) -> bytearray: ... # The superclass wants us to accept Iterable[int], but that fails at runtime. def __iadd__(self, value: ReadableBuffer, /) -> Self: ... # type: ignore[override] @@ -835,14 +835,14 @@ class memoryview(Sequence[_I]): @overload def __getitem__(self, key: SupportsIndex | tuple[SupportsIndex, ...], /) -> _I: ... @overload - def __getitem__(self, key: slice, /) -> memoryview[_I]: ... + def __getitem__(self, key: slice[SupportsIndex | None], /) -> memoryview[_I]: ... def __contains__(self, x: object, /) -> bool: ... def __iter__(self) -> Iterator[_I]: ... def __len__(self) -> int: ... def __eq__(self, value: object, /) -> bool: ... def __hash__(self) -> int: ... @overload - def __setitem__(self, key: slice, value: ReadableBuffer, /) -> None: ... + def __setitem__(self, key: slice[SupportsIndex | None], value: ReadableBuffer, /) -> None: ... @overload def __setitem__(self, key: SupportsIndex | tuple[SupportsIndex, ...], value: _I, /) -> None: ... if sys.version_info >= (3, 10): @@ -949,7 +949,7 @@ class tuple(Sequence[_T_co]): @overload def __getitem__(self, key: SupportsIndex, /) -> _T_co: ... @overload - def __getitem__(self, key: slice, /) -> tuple[_T_co, ...]: ... + def __getitem__(self, key: slice[SupportsIndex | None], /) -> tuple[_T_co, ...]: ... def __iter__(self) -> Iterator[_T_co]: ... def __lt__(self, value: tuple[_T_co, ...], /) -> bool: ... def __le__(self, value: tuple[_T_co, ...], /) -> bool: ... @@ -1049,12 +1049,12 @@ class list(MutableSequence[_T]): @overload def __getitem__(self, i: SupportsIndex, /) -> _T: ... @overload - def __getitem__(self, s: slice, /) -> list[_T]: ... + def __getitem__(self, s: slice[SupportsIndex | None], /) -> list[_T]: ... @overload def __setitem__(self, key: SupportsIndex, value: _T, /) -> None: ... @overload - def __setitem__(self, key: slice, value: Iterable[_T], /) -> None: ... - def __delitem__(self, key: SupportsIndex | slice, /) -> None: ... + def __setitem__(self, key: slice[SupportsIndex | None], value: Iterable[_T], /) -> None: ... + def __delitem__(self, key: SupportsIndex | slice[SupportsIndex | None], /) -> None: ... # Overloading looks unnecessary, but is needed to work around complex mypy problems @overload def __add__(self, value: list[_T], /) -> list[_T]: ... @@ -1254,7 +1254,7 @@ class range(Sequence[int]): @overload def __getitem__(self, key: SupportsIndex, /) -> int: ... @overload - def __getitem__(self, key: slice, /) -> range: ... + def __getitem__(self, key: slice[SupportsIndex | None], /) -> range: ... def __reversed__(self) -> Iterator[int]: ... @disjoint_base @@ -1287,10 +1287,10 @@ def abs(x: SupportsAbs[_T], /) -> _T: ... def all(iterable: Iterable[object], /) -> bool: ... def any(iterable: Iterable[object], /) -> bool: ... def ascii(obj: object, /) -> str: ... -def bin(number: int | SupportsIndex, /) -> str: ... +def bin(number: SupportsIndex, /) -> str: ... def breakpoint(*args: Any, **kws: Any) -> None: ... def callable(obj: object, /) -> TypeIs[Callable[..., object]]: ... -def chr(i: int | SupportsIndex, /) -> str: ... +def chr(i: SupportsIndex, /) -> str: ... if sys.version_info >= (3, 10): def aiter(async_iterable: SupportsAiter[_SupportsAnextT_co], /) -> _SupportsAnextT_co: ... @@ -1448,7 +1448,7 @@ def hash(obj: object, /) -> int: ... help: _sitebuiltins._Helper -def hex(number: int | SupportsIndex, /) -> str: ... +def hex(number: SupportsIndex, /) -> str: ... def id(obj: object, /) -> int: ... def input(prompt: object = "", /) -> str: ... @type_check_only @@ -1615,7 +1615,7 @@ def min(iterable: Iterable[_T1], /, *, key: Callable[[_T1], SupportsRichComparis def next(i: SupportsNext[_T], /) -> _T: ... @overload def next(i: SupportsNext[_T], default: _VT, /) -> _T | _VT: ... -def oct(number: int | SupportsIndex, /) -> str: ... +def oct(number: SupportsIndex, /) -> str: ... _Opener: TypeAlias = Callable[[str, int], int] diff --git a/mypy/typeshed/stdlib/collections/__init__.pyi b/mypy/typeshed/stdlib/collections/__init__.pyi index 8636e6cdbdc31..95f13b0c8dd2b 100644 --- a/mypy/typeshed/stdlib/collections/__init__.pyi +++ b/mypy/typeshed/stdlib/collections/__init__.pyi @@ -129,12 +129,12 @@ class UserList(MutableSequence[_T]): @overload def __getitem__(self, i: SupportsIndex) -> _T: ... @overload - def __getitem__(self, i: slice) -> Self: ... + def __getitem__(self, i: slice[SupportsIndex | None]) -> Self: ... @overload def __setitem__(self, i: SupportsIndex, item: _T) -> None: ... @overload - def __setitem__(self, i: slice, item: Iterable[_T]) -> None: ... - def __delitem__(self, i: SupportsIndex | slice) -> None: ... + def __setitem__(self, i: slice[SupportsIndex | None], item: Iterable[_T]) -> None: ... + def __delitem__(self, i: SupportsIndex | slice[SupportsIndex | None]) -> None: ... def __add__(self, other: Iterable[_T]) -> Self: ... def __radd__(self, other: Iterable[_T]) -> Self: ... def __iadd__(self, other: Iterable[_T]) -> Self: ... @@ -174,7 +174,7 @@ class UserString(Sequence[UserString]): def __hash__(self) -> int: ... def __contains__(self, char: object) -> bool: ... def __len__(self) -> int: ... - def __getitem__(self, index: SupportsIndex | slice) -> Self: ... + def __getitem__(self, index: SupportsIndex | slice[SupportsIndex | None]) -> Self: ... def __iter__(self) -> Iterator[Self]: ... def __reversed__(self) -> Iterator[Self]: ... def __add__(self, other: object) -> Self: ... diff --git a/mypy/typeshed/stdlib/contextlib.pyi b/mypy/typeshed/stdlib/contextlib.pyi index 221102ee23956..8d5902c469120 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, Protocol, TypeVar, overload, runtime_checkable, type_check_only -from typing_extensions import ParamSpec, Self, TypeAlias +from typing_extensions import ParamSpec, Self, TypeAlias, deprecated __all__ = [ "contextmanager", @@ -86,6 +86,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]]: ... if sys.version_info >= (3, 10): @@ -112,6 +118,13 @@ else: 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 class _SupportsClose(Protocol): diff --git a/mypy/typeshed/stdlib/email/_header_value_parser.pyi b/mypy/typeshed/stdlib/email/_header_value_parser.pyi index dededd006e5b5..32caf83bd0220 100644 --- a/mypy/typeshed/stdlib/email/_header_value_parser.pyi +++ b/mypy/typeshed/stdlib/email/_header_value_parser.pyi @@ -1,3 +1,4 @@ +import sys from collections.abc import Iterable, Iterator from email.errors import HeaderParseError, MessageDefect from email.policy import Policy @@ -25,6 +26,10 @@ SPECIALSNL: Final[set[str]] def make_quoted_pairs(value: Any) -> str: ... def quote_string(value: Any) -> str: ... +if sys.version_info >= (3, 13): + # Added in Python 3.13.12, 3.14.3 + def make_parenthesis_pairs(value: Any) -> str: ... + rfc2047_matcher: Final[Pattern[str]] class TokenList(list[TokenList | Terminal]): @@ -311,6 +316,13 @@ class MessageID(MsgID): class InvalidMessageID(MessageID): token_type: str +if sys.version_info >= (3, 13): + # Added in Python 3.13.12, 3.14.3 + class MessageIDList(TokenList): + token_type: str + @property + def message_ids(self) -> list[MsgID | Terminal]: ... + class Header(TokenList): token_type: str @@ -381,6 +393,11 @@ def get_address_list(value: str) -> tuple[AddressList, str]: ... def get_no_fold_literal(value: str) -> tuple[NoFoldLiteral, str]: ... def get_msg_id(value: str) -> tuple[MsgID, str]: ... def parse_message_id(value: str) -> MessageID: ... + +if sys.version_info >= (3, 13): + # Added in Python 3.13.12, 3.14.3 + def parse_message_ids(value: str) -> MessageIDList: ... + def parse_mime_version(value: str) -> MIMEVersion: ... def get_invalid_parameter(value: str) -> tuple[InvalidParameter, str]: ... def get_ttext(value: str) -> tuple[ValueTerminal, str]: ... diff --git a/mypy/typeshed/stdlib/email/headerregistry.pyi b/mypy/typeshed/stdlib/email/headerregistry.pyi index bea68307e0091..8033f0ab43560 100644 --- a/mypy/typeshed/stdlib/email/headerregistry.pyi +++ b/mypy/typeshed/stdlib/email/headerregistry.pyi @@ -1,3 +1,4 @@ +import sys import types from collections.abc import Iterable, Mapping from datetime import datetime as _datetime @@ -137,6 +138,17 @@ class MessageIDHeader: @staticmethod def value_parser(value: str) -> MessageID: ... +if sys.version_info >= (3, 13): + from email._header_value_parser import MessageIDList + + # Added in Python 3.13.12, 3.14.3 + class ReferencesHeader: + max_count: ClassVar[Literal[1]] + @classmethod + def parse(cls, value: str, kwds: dict[str, Any]) -> None: ... + @staticmethod + def value_parser(value: str) -> MessageIDList: ... + @type_check_only class _HeaderParser(Protocol): max_count: ClassVar[Literal[1] | None] diff --git a/mypy/typeshed/stdlib/enum.pyi b/mypy/typeshed/stdlib/enum.pyi index c6cc5a961ee72..f9b53e1d45f16 100644 --- a/mypy/typeshed/stdlib/enum.pyi +++ b/mypy/typeshed/stdlib/enum.pyi @@ -4,7 +4,7 @@ import types from _typeshed import SupportsKeysAndGetItem, Unused from builtins import property as _builtins_property from collections.abc import Callable, Iterable, Iterator, Mapping -from typing import Any, Final, Generic, Literal, TypeVar, overload +from typing import Any, Final, Generic, Literal, SupportsIndex, TypeVar, overload from typing_extensions import Self, TypeAlias, disjoint_base __all__ = ["EnumMeta", "Enum", "IntEnum", "Flag", "IntFlag", "auto", "unique"] @@ -311,6 +311,7 @@ if sys.version_info >= (3, 11): def global_enum_repr(self: Enum) -> str: ... def global_flag_repr(self: Flag) -> str: ... def show_flag_values(value: int) -> list[int]: ... + def bin(num: SupportsIndex, max_bits: int | None = None) -> str: ... if sys.version_info >= (3, 12): # The body of the class is the same, but the base classes are different. diff --git a/mypy/typeshed/stdlib/functools.pyi b/mypy/typeshed/stdlib/functools.pyi index 52d0d0958134e..57bc3f179f7ac 100644 --- a/mypy/typeshed/stdlib/functools.pyi +++ b/mypy/typeshed/stdlib/functools.pyi @@ -63,6 +63,10 @@ class _lru_cache_wrapper(Generic[_T_co]): def __copy__(self) -> _lru_cache_wrapper[_T_co]: ... def __deepcopy__(self, memo: Any, /) -> _lru_cache_wrapper[_T_co]: ... + # as with ``Callable``, we'll assume that these attributes exist + __name__: str + __qualname__: str + @overload def lru_cache(maxsize: int | None = 128, typed: bool = False) -> Callable[[Callable[..., _T]], _lru_cache_wrapper[_T]]: ... @overload diff --git a/mypy/typeshed/stdlib/http/cookies.pyi b/mypy/typeshed/stdlib/http/cookies.pyi index 0373eae8ab297..eadf054c3a5f4 100644 --- a/mypy/typeshed/stdlib/http/cookies.pyi +++ b/mypy/typeshed/stdlib/http/cookies.pyi @@ -47,7 +47,7 @@ class Morsel(dict[str, Any], Generic[_T]): class BaseCookie(dict[str, Morsel[_T]], Generic[_T]): def __init__(self, input: _DataType | None = None) -> None: ... def value_decode(self, val: str) -> tuple[_T, str]: ... - def value_encode(self, val: _T) -> tuple[_T, str]: ... + def value_encode(self, val: _T) -> tuple[str, str]: ... def output(self, attrs: list[str] | None = None, header: str = "Set-Cookie:", sep: str = "\r\n") -> str: ... __str__ = output def js_output(self, attrs: list[str] | None = None) -> str: ... diff --git a/mypy/typeshed/stdlib/logging/__init__.pyi b/mypy/typeshed/stdlib/logging/__init__.pyi index 8248f82ea87ac..89c94816a906c 100644 --- a/mypy/typeshed/stdlib/logging/__init__.pyi +++ b/mypy/typeshed/stdlib/logging/__init__.pyi @@ -576,19 +576,40 @@ if sys.version_info >= (3, 11): def getLevelNamesMapping() -> dict[str, int]: ... def makeLogRecord(dict: Mapping[str, object]) -> LogRecord: ... +@overload # handlers is non-None def basicConfig( *, - filename: StrPath | None = ..., - filemode: str = ..., - format: str = ..., - datefmt: str | None = ..., - style: _FormatStyle = ..., - level: _Level | None = ..., - stream: SupportsWrite[str] | None = ..., - handlers: Iterable[Handler] | None = ..., - force: bool | None = ..., - encoding: str | None = ..., - errors: str | None = ..., + format: str = ..., # default value depends on the value of `style` + datefmt: str | None = None, + style: _FormatStyle = "%", + level: _Level | None = None, + handlers: Iterable[Handler], + force: bool | None = False, +) -> None: ... +@overload # handlers is None, filename is passed (but possibly None) +def basicConfig( + *, + filename: StrPath | None, + filemode: str = "a", + format: str = ..., # default value depends on the value of `style` + datefmt: str | None = None, + style: _FormatStyle = "%", + level: _Level | None = None, + handlers: None = None, + force: bool | None = False, + encoding: str | None = None, + errors: str | None = "backslashreplace", +) -> None: ... +@overload # handlers is None, filename is not passed +def basicConfig( + *, + format: str = ..., # default value depends on the value of `style` + datefmt: str | None = None, + style: _FormatStyle = "%", + level: _Level | None = None, + stream: SupportsWrite[str] | None = None, + handlers: None = None, + force: bool | None = False, ) -> None: ... def shutdown(handlerList: Sequence[Any] = ...) -> None: ... # handlerList is undocumented def setLoggerClass(klass: type[Logger]) -> None: ... @@ -616,6 +637,7 @@ class FileHandler(StreamHandler[TextIOWrapper]): encoding: str | None # undocumented delay: bool # undocumented errors: str | None # undocumented + stream: TextIOWrapper | None # type: ignore[assignment] # None when delay=True or after close() def __init__( self, filename: StrPath, mode: str = "a", encoding: str | None = None, delay: bool = False, errors: str | None = None ) -> None: ... diff --git a/mypy/typeshed/stdlib/logging/config.pyi b/mypy/typeshed/stdlib/logging/config.pyi index 72412ddc2cea5..e362145516001 100644 --- a/mypy/typeshed/stdlib/logging/config.pyi +++ b/mypy/typeshed/stdlib/logging/config.pyi @@ -97,7 +97,7 @@ class ConvertingList(list[Any], ConvertingMixin): # undocumented @overload def __getitem__(self, key: SupportsIndex) -> Any: ... @overload - def __getitem__(self, key: slice) -> Any: ... + def __getitem__(self, key: slice[SupportsIndex | None]) -> Any: ... def pop(self, idx: SupportsIndex = -1) -> Any: ... if sys.version_info >= (3, 12): @@ -105,7 +105,7 @@ if sys.version_info >= (3, 12): @overload def __getitem__(self, key: SupportsIndex) -> Any: ... @overload - def __getitem__(self, key: slice) -> Any: ... + def __getitem__(self, key: slice[SupportsIndex | None]) -> Any: ... else: @disjoint_base @@ -113,7 +113,7 @@ else: @overload def __getitem__(self, key: SupportsIndex) -> Any: ... @overload - def __getitem__(self, key: slice) -> Any: ... + def __getitem__(self, key: slice[SupportsIndex | None]) -> Any: ... class BaseConfigurator: CONVERT_PATTERN: Pattern[str] diff --git a/mypy/typeshed/stdlib/mmap.pyi b/mypy/typeshed/stdlib/mmap.pyi index 98183acba40f8..005020b8b6b30 100644 --- a/mypy/typeshed/stdlib/mmap.pyi +++ b/mypy/typeshed/stdlib/mmap.pyi @@ -2,7 +2,7 @@ import os import sys from _typeshed import ReadableBuffer, Unused from collections.abc import Iterator -from typing import Final, Literal, NoReturn, overload +from typing import Final, Literal, NoReturn, SupportsIndex, overload from typing_extensions import Self, disjoint_base ACCESS_DEFAULT: Final = 0 @@ -77,14 +77,14 @@ class mmap: def read(self, n: int | None = None, /) -> bytes: ... def write(self, bytes: ReadableBuffer, /) -> int: ... @overload - def __getitem__(self, key: int, /) -> int: ... + def __getitem__(self, key: SupportsIndex, /) -> int: ... @overload - def __getitem__(self, key: slice, /) -> bytes: ... - def __delitem__(self, key: int | slice, /) -> NoReturn: ... + def __getitem__(self, key: slice[SupportsIndex | None], /) -> bytes: ... + def __delitem__(self, key: SupportsIndex | slice[SupportsIndex | None], /) -> NoReturn: ... @overload - def __setitem__(self, key: int, value: int, /) -> None: ... + def __setitem__(self, key: SupportsIndex, value: int, /) -> None: ... @overload - def __setitem__(self, key: slice, value: ReadableBuffer, /) -> None: ... + def __setitem__(self, key: slice[SupportsIndex | None], value: ReadableBuffer, /) -> None: ... # Doesn't actually exist, but the object actually supports "in" because it has __getitem__, # so we claim that there is also a __contains__ to help type checkers. def __contains__(self, o: object, /) -> bool: ... diff --git a/mypy/typeshed/stdlib/multiprocessing/forkserver.pyi b/mypy/typeshed/stdlib/multiprocessing/forkserver.pyi index c4af295d23161..570b492e9daf3 100644 --- a/mypy/typeshed/stdlib/multiprocessing/forkserver.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/forkserver.pyi @@ -16,6 +16,7 @@ class ForkServer: def ensure_running(self) -> None: ... if sys.version_info >= (3, 14): + # `sys_argv` parameter added in Python 3.14.3 def main( listener_fd: int | None, alive_r: FileDescriptorLike, @@ -23,9 +24,22 @@ if sys.version_info >= (3, 14): main_path: str | None = None, sys_path: list[str] | None = None, *, + sys_argv: list[str] | None = None, authkey_r: int | None = None, ) -> None: ... +elif sys.version_info >= (3, 13): + # `sys_argv` parameter added in Python 3.13.12 + def main( + listener_fd: int | None, + alive_r: FileDescriptorLike, + preload: Sequence[str], + main_path: str | None = None, + sys_path: list[str] | None = None, + *, + sys_argv: list[str] | None = None, + ) -> None: ... + else: def main( listener_fd: int | None, diff --git a/mypy/typeshed/stdlib/multiprocessing/managers.pyi b/mypy/typeshed/stdlib/multiprocessing/managers.pyi index 87a245b0fa9ca..bc6b2e6a9d27f 100644 --- a/mypy/typeshed/stdlib/multiprocessing/managers.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/managers.pyi @@ -172,15 +172,15 @@ class BaseListProxy(BaseProxy, MutableSequence[_T]): __builtins__: ClassVar[dict[str, Any]] def __len__(self) -> int: ... def __add__(self, x: list[_T], /) -> list[_T]: ... - def __delitem__(self, i: SupportsIndex | slice, /) -> None: ... + def __delitem__(self, i: SupportsIndex | slice[SupportsIndex | None], /) -> None: ... @overload def __getitem__(self, i: SupportsIndex, /) -> _T: ... @overload - def __getitem__(self, s: slice, /) -> list[_T]: ... + def __getitem__(self, s: slice[SupportsIndex | None], /) -> list[_T]: ... @overload def __setitem__(self, i: SupportsIndex, o: _T, /) -> None: ... @overload - def __setitem__(self, s: slice, o: Iterable[_T], /) -> None: ... + def __setitem__(self, s: slice[SupportsIndex | None], o: Iterable[_T], /) -> None: ... def __mul__(self, n: SupportsIndex, /) -> list[_T]: ... def __rmul__(self, n: SupportsIndex, /) -> list[_T]: ... def __imul__(self, value: SupportsIndex, /) -> Self: ... diff --git a/mypy/typeshed/stdlib/multiprocessing/sharedctypes.pyi b/mypy/typeshed/stdlib/multiprocessing/sharedctypes.pyi index e2ec15f05ea23..f61ca26aab5d6 100644 --- a/mypy/typeshed/stdlib/multiprocessing/sharedctypes.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/sharedctypes.pyi @@ -5,7 +5,7 @@ from ctypes import _SimpleCData, c_char from multiprocessing.context import BaseContext from multiprocessing.synchronize import _LockLike from types import TracebackType -from typing import Any, Generic, Literal, Protocol, TypeVar, overload, type_check_only +from typing import Any, Generic, Literal, Protocol, SupportsIndex, TypeVar, overload, type_check_only __all__ = ["RawValue", "RawArray", "Value", "Array", "copy", "synchronized"] @@ -103,27 +103,27 @@ class Synchronized(SynchronizedBase[_SimpleCData[_T]], Generic[_T]): class SynchronizedArray(SynchronizedBase[ctypes.Array[_SimpleCData[_T]]], Generic[_T]): def __len__(self) -> int: ... @overload - def __getitem__(self, i: slice) -> list[_T]: ... + def __getitem__(self, i: slice[SupportsIndex | None]) -> list[_T]: ... @overload - def __getitem__(self, i: int) -> _T: ... + def __getitem__(self, i: SupportsIndex) -> _T: ... @overload - def __setitem__(self, i: slice, value: Iterable[_T]) -> None: ... + def __setitem__(self, i: slice[SupportsIndex | None], value: Iterable[_T]) -> None: ... @overload - def __setitem__(self, i: int, value: _T) -> None: ... - def __getslice__(self, start: int, stop: int) -> list[_T]: ... - def __setslice__(self, start: int, stop: int, values: Iterable[_T]) -> None: ... + def __setitem__(self, i: SupportsIndex, value: _T) -> None: ... + def __getslice__(self, start: SupportsIndex, stop: SupportsIndex) -> list[_T]: ... + def __setslice__(self, start: SupportsIndex, stop: SupportsIndex, values: Iterable[_T]) -> None: ... class SynchronizedString(SynchronizedArray[bytes]): @overload # type: ignore[override] - def __getitem__(self, i: slice) -> bytes: ... + def __getitem__(self, i: slice[SupportsIndex | None]) -> bytes: ... @overload - def __getitem__(self, i: int) -> bytes: ... + def __getitem__(self, i: SupportsIndex) -> bytes: ... @overload # type: ignore[override] - def __setitem__(self, i: slice, value: bytes) -> None: ... + def __setitem__(self, i: slice[SupportsIndex | None], value: bytes) -> None: ... @overload - def __setitem__(self, i: int, value: bytes) -> None: ... - def __getslice__(self, start: int, stop: int) -> bytes: ... # type: ignore[override] - def __setslice__(self, start: int, stop: int, values: bytes) -> None: ... # type: ignore[override] + def __setitem__(self, i: SupportsIndex, value: bytes) -> None: ... + def __getslice__(self, start: SupportsIndex, stop: SupportsIndex) -> bytes: ... # type: ignore[override] + def __setslice__(self, start: SupportsIndex, stop: SupportsIndex, values: bytes) -> None: ... # type: ignore[override] value: bytes raw: bytes diff --git a/mypy/typeshed/stdlib/pydoc_data/module_docs.pyi b/mypy/typeshed/stdlib/pydoc_data/module_docs.pyi new file mode 100644 index 0000000000000..e3f716c0b2925 --- /dev/null +++ b/mypy/typeshed/stdlib/pydoc_data/module_docs.pyi @@ -0,0 +1,3 @@ +from typing import Final + +module_docs: Final[dict[str, str]] diff --git a/mypy/typeshed/stdlib/socket.pyi b/mypy/typeshed/stdlib/socket.pyi index 24923192d1a48..a55273a8772c9 100644 --- a/mypy/typeshed/stdlib/socket.pyi +++ b/mypy/typeshed/stdlib/socket.pyi @@ -519,9 +519,10 @@ if sys.platform != "win32": __all__ += ["SO_BINDTODEVICE"] -if sys.platform != "darwin" and sys.platform != "linux": +if sys.platform != "darwin": from _socket import BDADDR_ANY as BDADDR_ANY, BDADDR_LOCAL as BDADDR_LOCAL, BTPROTO_RFCOMM as BTPROTO_RFCOMM +if sys.platform != "darwin" and sys.platform != "linux": __all__ += ["BDADDR_ANY", "BDADDR_LOCAL", "BTPROTO_RFCOMM"] if sys.platform == "darwin" and sys.version_info >= (3, 10): @@ -969,9 +970,10 @@ if sys.platform != "linux": if sys.platform != "darwin" and sys.platform != "linux": __all__ += ["AF_BLUETOOTH"] -if sys.platform != "win32" and sys.platform != "darwin" and sys.platform != "linux": +if sys.platform != "win32" and sys.platform != "darwin": from _socket import BTPROTO_HCI as BTPROTO_HCI, BTPROTO_L2CAP as BTPROTO_L2CAP, BTPROTO_SCO as BTPROTO_SCO +if sys.platform != "win32" and sys.platform != "darwin" and sys.platform != "linux": __all__ += ["BTPROTO_HCI", "BTPROTO_L2CAP", "BTPROTO_SCO"] if sys.platform != "win32" and sys.platform != "darwin" and sys.platform != "linux": @@ -1131,7 +1133,7 @@ class AddressFamily(IntEnum): AF_QIPCRTR = 42 if sys.platform != "linux": AF_LINK = 33 - if sys.platform != "darwin" and sys.platform != "linux": + if sys.platform != "darwin": AF_BLUETOOTH = 32 if sys.platform == "win32" and sys.version_info >= (3, 12): AF_HYPERV = 34 @@ -1186,7 +1188,7 @@ if sys.platform == "linux": if sys.platform != "linux": AF_LINK: Final = AddressFamily.AF_LINK -if sys.platform != "darwin" and sys.platform != "linux": +if sys.platform != "darwin": AF_BLUETOOTH: Final = AddressFamily.AF_BLUETOOTH if sys.platform == "win32" and sys.version_info >= (3, 12): AF_HYPERV: Final = AddressFamily.AF_HYPERV @@ -1425,7 +1427,7 @@ def getfqdn(name: str = "") -> str: ... if sys.version_info >= (3, 11): def create_connection( - address: tuple[str | None, int], + address: tuple[str | None, bytes | str | int | None], timeout: float | None = ..., source_address: _Address | None = None, *, diff --git a/mypy/typeshed/stdlib/sqlite3/__init__.pyi b/mypy/typeshed/stdlib/sqlite3/__init__.pyi index e4604144f0794..f12f80a35a975 100644 --- a/mypy/typeshed/stdlib/sqlite3/__init__.pyi +++ b/mypy/typeshed/stdlib/sqlite3/__init__.pyi @@ -222,7 +222,7 @@ _AdaptedInputData: TypeAlias = _SqliteData | Any _Parameters: TypeAlias = SupportsLenAndGetItem[_AdaptedInputData] | Mapping[str, _AdaptedInputData] # Controls the legacy transaction handling mode of sqlite3. _IsolationLevel: TypeAlias = Literal["DEFERRED", "EXCLUSIVE", "IMMEDIATE"] | None -_RowFactoryOptions: TypeAlias = type[Row] | Callable[[Cursor, Row], object] | None +_RowFactoryOptions: TypeAlias = type[Row] | Callable[[Cursor, tuple[Any, ...]], object] | None @type_check_only class _AnyParamWindowAggregateClass(Protocol): @@ -352,7 +352,7 @@ class Connection: self, name: str, num_params: int, aggregate_class: Callable[[], _WindowAggregateClass] | None, / ) -> None: ... - def create_collation(self, name: str, callback: Callable[[str, str], int | SupportsIndex] | None, /) -> None: ... + def create_collation(self, name: str, callback: Callable[[str, str], SupportsIndex] | None, /) -> None: ... def create_function( self, name: str, narg: int, func: Callable[..., _SqliteData] | None, *, deterministic: bool = False ) -> None: ... @@ -443,10 +443,10 @@ class PrepareProtocol: class Row(Sequence[Any]): def __new__(cls, cursor: Cursor, data: tuple[Any, ...], /) -> Self: ... def keys(self) -> list[str]: ... - @overload + @overload # Note: really needs int instead of SupportsIndex def __getitem__(self, key: int | str, /) -> Any: ... - @overload - def __getitem__(self, key: slice, /) -> tuple[Any, ...]: ... + @overload # Note: SupportsIndex does work within slices. + def __getitem__(self, key: slice[SupportsIndex | None], /) -> tuple[Any, ...]: ... def __hash__(self) -> int: ... def __iter__(self) -> Iterator[Any]: ... def __len__(self) -> int: ... diff --git a/mypy/typeshed/stdlib/tarfile.pyi b/mypy/typeshed/stdlib/tarfile.pyi index 5eecdd350c0aa..6e68c370f3aa3 100644 --- a/mypy/typeshed/stdlib/tarfile.pyi +++ b/mypy/typeshed/stdlib/tarfile.pyi @@ -119,16 +119,16 @@ class TarFile: OPEN_METH: ClassVar[Mapping[str, str]] name: StrOrBytesPath | None mode: Literal["r", "a", "w", "x"] - fileobj: _Fileobj | None - format: _TarFormat | None + fileobj: _Fileobj + format: _TarFormat tarinfo: type[TarInfo] - dereference: bool | None - ignore_zeros: bool | None - encoding: str | None + dereference: bool + ignore_zeros: bool + encoding: str errors: str fileobject: type[ExFileObject] # undocumented pax_headers: Mapping[str, str] - debug: int | None + debug: int errorlevel: int offset: int # undocumented extraction_filter: _FilterFunction | None diff --git a/mypy/typeshed/stdlib/time.pyi b/mypy/typeshed/stdlib/time.pyi index 5665efbba69d0..d0853792b636d 100644 --- a/mypy/typeshed/stdlib/time.pyi +++ b/mypy/typeshed/stdlib/time.pyi @@ -1,10 +1,17 @@ import sys from _typeshed import structseq -from typing import Any, Final, Literal, Protocol, final, type_check_only +from typing import Any, Final, Literal, Protocol, SupportsFloat, SupportsIndex, Union, final, type_check_only from typing_extensions import TypeAlias _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] +else: + # before, time functions only accept (subclass of) float, *not* SupportsFloat + _SupportsFloatOrIndex: TypeAlias = Union[float, SupportsIndex] + altzone: int daylight: int timezone: int @@ -68,11 +75,11 @@ class struct_time(structseq[Any | int], _TimeTuple): def tm_gmtoff(self) -> int: ... def asctime(time_tuple: _TimeTuple | struct_time = ..., /) -> str: ... -def ctime(seconds: float | None = None, /) -> str: ... -def gmtime(seconds: float | None = None, /) -> struct_time: ... -def localtime(seconds: float | None = None, /) -> struct_time: ... +def ctime(seconds: _SupportsFloatOrIndex | None = None, /) -> str: ... +def gmtime(seconds: _SupportsFloatOrIndex | None = None, /) -> struct_time: ... +def localtime(seconds: _SupportsFloatOrIndex | None = None, /) -> struct_time: ... def mktime(time_tuple: _TimeTuple | struct_time, /) -> float: ... -def sleep(seconds: float, /) -> None: ... +def sleep(seconds: _SupportsFloatOrIndex, /) -> None: ... def strftime(format: str, time_tuple: _TimeTuple | struct_time = ..., /) -> str: ... def strptime(data_string: str, format: str = "%a %b %d %H:%M:%S %Y", /) -> struct_time: ... def time() -> float: ... diff --git a/mypy/typeshed/stdlib/traceback.pyi b/mypy/typeshed/stdlib/traceback.pyi index d587295cd1cf7..4305706afa20b 100644 --- a/mypy/typeshed/stdlib/traceback.pyi +++ b/mypy/typeshed/stdlib/traceback.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import SupportsWrite, Unused from collections.abc import Generator, Iterable, Iterator, Mapping from types import FrameType, TracebackType -from typing import Any, ClassVar, Literal, overload +from typing import Any, ClassVar, Literal, SupportsIndex, overload from typing_extensions import Self, TypeAlias, deprecated __all__ = [ @@ -305,9 +305,9 @@ class FrameSummary: @overload def __getitem__(self, pos: Literal[3]) -> str | None: ... @overload - def __getitem__(self, pos: int) -> Any: ... + def __getitem__(self, pos: SupportsIndex) -> Any: ... @overload - def __getitem__(self, pos: slice) -> tuple[Any, ...]: ... + def __getitem__(self, pos: slice[SupportsIndex | None]) -> tuple[Any, ...]: ... def __iter__(self) -> Iterator[Any]: ... def __eq__(self, other: object) -> bool: ... def __len__(self) -> Literal[4]: ... diff --git a/mypy/typeshed/stdlib/tracemalloc.pyi b/mypy/typeshed/stdlib/tracemalloc.pyi index 31d8f74456395..2a7ee0051af9c 100644 --- a/mypy/typeshed/stdlib/tracemalloc.pyi +++ b/mypy/typeshed/stdlib/tracemalloc.pyi @@ -95,7 +95,7 @@ class Traceback(Sequence[Frame]): @overload def __getitem__(self, index: SupportsIndex) -> Frame: ... @overload - def __getitem__(self, index: slice) -> Sequence[Frame]: ... + def __getitem__(self, index: slice[SupportsIndex | None]) -> Sequence[Frame]: ... def __contains__(self, frame: Frame) -> bool: ... # type: ignore[override] def __len__(self) -> int: ... def __eq__(self, other: object) -> bool: ... diff --git a/mypy/typeshed/stdlib/typing.pyi b/mypy/typeshed/stdlib/typing.pyi index 5521055bdef3a..83e114aac1a2a 100644 --- a/mypy/typeshed/stdlib/typing.pyi +++ b/mypy/typeshed/stdlib/typing.pyi @@ -640,14 +640,17 @@ class AsyncGenerator(AsyncIterator[_YieldT_co], Protocol[_YieldT_co, _SendT_cont ) -> Coroutine[Any, Any, _YieldT_co]: ... 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: ... @@ -658,7 +661,7 @@ class Sequence(Reversible[_T_co], Collection[_T_co]): def __getitem__(self, index: int) -> _T_co: ... @overload @abstractmethod - def __getitem__(self, index: slice) -> Sequence[_T_co]: ... + def __getitem__(self, index: slice[int | None]) -> Sequence[_T_co]: ... # Mixin methods def index(self, value: Any, start: int = 0, stop: int = ...) -> int: ... def count(self, value: Any) -> int: ... @@ -674,19 +677,19 @@ class MutableSequence(Sequence[_T]): def __getitem__(self, index: int) -> _T: ... @overload @abstractmethod - def __getitem__(self, index: slice) -> MutableSequence[_T]: ... + def __getitem__(self, index: slice[int | None]) -> MutableSequence[_T]: ... @overload @abstractmethod def __setitem__(self, index: int, value: _T) -> None: ... @overload @abstractmethod - def __setitem__(self, index: slice, value: Iterable[_T]) -> None: ... + def __setitem__(self, index: slice[int | None], value: Iterable[_T]) -> None: ... @overload @abstractmethod def __delitem__(self, index: int) -> None: ... @overload @abstractmethod - def __delitem__(self, index: slice) -> None: ... + def __delitem__(self, index: slice[int | None]) -> None: ... # Mixin methods def append(self, value: _T) -> None: ... def clear(self) -> None: ... @@ -701,6 +704,8 @@ class AbstractSet(Collection[_T_co]): def __contains__(self, x: object) -> bool: ... def _hash(self) -> int: ... # Mixin methods + @classmethod + def _from_iterable(cls, it: Iterable[_S]) -> AbstractSet[_S]: ... def __le__(self, other: AbstractSet[Any]) -> bool: ... def __lt__(self, other: AbstractSet[Any]) -> bool: ... def __gt__(self, other: AbstractSet[Any]) -> bool: ... @@ -733,6 +738,8 @@ class MappingView(Sized): class ItemsView(MappingView, AbstractSet[tuple[_KT_co, _VT_co]], Generic[_KT_co, _VT_co]): def __init__(self, mapping: SupportsGetItemViewable[_KT_co, _VT_co]) -> None: ... # undocumented + @classmethod + def _from_iterable(cls, it: Iterable[_S]) -> set[_S]: ... def __and__(self, other: Iterable[Any]) -> set[tuple[_KT_co, _VT_co]]: ... def __rand__(self, other: Iterable[_T]) -> set[_T]: ... def __contains__(self, item: tuple[object, object]) -> bool: ... # type: ignore[override] @@ -746,6 +753,8 @@ class ItemsView(MappingView, AbstractSet[tuple[_KT_co, _VT_co]], Generic[_KT_co, class KeysView(MappingView, AbstractSet[_KT_co]): def __init__(self, mapping: Viewable[_KT_co]) -> None: ... # undocumented + @classmethod + def _from_iterable(cls, it: Iterable[_S]) -> set[_S]: ... def __and__(self, other: Iterable[Any]) -> set[_KT_co]: ... def __rand__(self, other: Iterable[_T]) -> set[_T]: ... def __contains__(self, key: object) -> bool: ... @@ -837,7 +846,7 @@ class MutableMapping(Mapping[_KT, _VT]): @overload def update(self: SupportsGetItem[str, _VT], m: Iterable[tuple[str, _VT]], /, **kwargs: _VT) -> None: ... @overload - def update(self: SupportsGetItem[str, _VT], **kwargs: _VT) -> None: ... + def update(self: SupportsGetItem[str, _VT], /, **kwargs: _VT) -> None: ... Text = str diff --git a/mypy/typeshed/stdlib/typing_extensions.pyi b/mypy/typeshed/stdlib/typing_extensions.pyi index 8a9f0f3919ba2..16cf0611a58ad 100644 --- a/mypy/typeshed/stdlib/typing_extensions.pyi +++ b/mypy/typeshed/stdlib/typing_extensions.pyi @@ -30,7 +30,7 @@ from collections.abc import ( from contextlib import AbstractAsyncContextManager as AsyncContextManager, AbstractContextManager as ContextManager from re import Match as Match, Pattern as Pattern from types import GenericAlias, ModuleType -from typing import ( # noqa: Y022,Y037,Y038,Y039,UP035 +from typing import ( # noqa: Y022,Y037,Y038,Y039,UP035,RUF100 IO as IO, TYPE_CHECKING as TYPE_CHECKING, AbstractSet as AbstractSet, diff --git a/mypy/typeshed/stdlib/xml/etree/ElementTree.pyi b/mypy/typeshed/stdlib/xml/etree/ElementTree.pyi index 5c16bcc4ff233..d728fb975bfb9 100644 --- a/mypy/typeshed/stdlib/xml/etree/ElementTree.pyi +++ b/mypy/typeshed/stdlib/xml/etree/ElementTree.pyi @@ -123,14 +123,14 @@ class Element(Generic[_Tag]): @overload def __getitem__(self, key: SupportsIndex, /) -> Element: ... @overload - def __getitem__(self, key: slice, /) -> list[Element]: ... + def __getitem__(self, key: slice[SupportsIndex | None], /) -> list[Element]: ... def __len__(self) -> int: ... # Doesn't actually exist at runtime, but instance of the class are indeed iterable due to __getitem__. def __iter__(self) -> Iterator[Element]: ... @overload def __setitem__(self, key: SupportsIndex, value: Element[Any], /) -> None: ... @overload - def __setitem__(self, key: slice, value: Iterable[Element[Any]], /) -> None: ... + def __setitem__(self, key: slice[SupportsIndex | None], value: Iterable[Element[Any]], /) -> None: ... # Doesn't really exist in earlier versions, where __len__ is called implicitly instead @deprecated("Testing an element's truth value is deprecated.")