Skip to content

Commit 616f4d6

Browse files
mypybothauntsaninja
authored andcommitted
Sync typeshed
Source commit: python/typeshed@cdfb10c
1 parent 5c87e97 commit 616f4d6

35 files changed

+544
-364
lines changed

mypy/typeshed/stdlib/_asyncio.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from asyncio.events import AbstractEventLoop
3-
from collections.abc import Awaitable, Callable, Coroutine, Generator, Iterable
3+
from collections.abc import Awaitable, Callable, Coroutine, Generator
44
from contextvars import Context
55
from types import FrameType
66
from typing import Any, Literal, TextIO, TypeVar
@@ -13,7 +13,7 @@ _T = TypeVar("_T")
1313
_T_co = TypeVar("_T_co", covariant=True)
1414
_TaskYieldType: TypeAlias = Future[object] | None
1515

16-
class Future(Awaitable[_T], Iterable[_T]):
16+
class Future(Awaitable[_T]):
1717
_state: str
1818
@property
1919
def _exception(self) -> BaseException | None: ...

mypy/typeshed/stdlib/_ctypes.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,11 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType):
286286
def _type_(self) -> type[_CT]: ...
287287
@_type_.setter
288288
def _type_(self, value: type[_CT]) -> None: ...
289-
raw: bytes # Note: only available if _CT == c_char
289+
# Note: only available if _CT == c_char
290+
@property
291+
def raw(self) -> bytes: ...
292+
@raw.setter
293+
def raw(self, value: ReadableBuffer) -> None: ...
290294
value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise
291295
# TODO These methods cannot be annotated correctly at the moment.
292296
# All of these "Any"s stand for the array's element type, but it's not possible to use _CT

mypy/typeshed/stdlib/_socket.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,12 +812,12 @@ def getaddrinfo(
812812
type: int = ...,
813813
proto: int = ...,
814814
flags: int = ...,
815-
) -> list[tuple[int, int, int, str, tuple[str, int] | tuple[str, int, int, int]]]: ...
815+
) -> list[tuple[int, int, int, str, tuple[str, int] | tuple[str, int, int, int] | tuple[int, bytes]]]: ...
816816
def gethostbyname(hostname: str, /) -> str: ...
817817
def gethostbyname_ex(hostname: str, /) -> tuple[str, list[str], list[str]]: ...
818818
def gethostname() -> str: ...
819819
def gethostbyaddr(ip_address: str, /) -> tuple[str, list[str], list[str]]: ...
820-
def getnameinfo(sockaddr: tuple[str, int] | tuple[str, int, int, int], flags: int, /) -> tuple[str, str]: ...
820+
def getnameinfo(sockaddr: tuple[str, int] | tuple[str, int, int, int] | tuple[int, bytes], flags: int, /) -> tuple[str, str]: ...
821821
def getprotobyname(protocolname: str, /) -> int: ...
822822
def getservbyname(servicename: str, protocolname: str = ..., /) -> int: ...
823823
def getservbyport(port: int, protocolname: str = ..., /) -> str: ...

mypy/typeshed/stdlib/_typeshed/__init__.pyi

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ class SupportsSub(Protocol[_T_contra, _T_co]):
117117
class SupportsRSub(Protocol[_T_contra, _T_co]):
118118
def __rsub__(self, x: _T_contra, /) -> _T_co: ...
119119

120+
class SupportsMul(Protocol[_T_contra, _T_co]):
121+
def __mul__(self, x: _T_contra, /) -> _T_co: ...
122+
123+
class SupportsRMul(Protocol[_T_contra, _T_co]):
124+
def __rmul__(self, x: _T_contra, /) -> _T_co: ...
125+
120126
class SupportsDivMod(Protocol[_T_contra, _T_co]):
121127
def __divmod__(self, other: _T_contra, /) -> _T_co: ...
122128

@@ -151,11 +157,8 @@ class SupportsKeysAndGetItem(Protocol[_KT, _VT_co]):
151157
def keys(self) -> Iterable[_KT]: ...
152158
def __getitem__(self, key: _KT, /) -> _VT_co: ...
153159

154-
# This protocol is currently under discussion. Use SupportsContainsAndGetItem
155-
# instead, if you require the __contains__ method.
156-
# See https://github.com/python/typeshed/issues/11822.
160+
# stable
157161
class SupportsGetItem(Protocol[_KT_contra, _VT_co]):
158-
def __contains__(self, x: Any, /) -> bool: ...
159162
def __getitem__(self, key: _KT_contra, /) -> _VT_co: ...
160163

161164
# stable

mypy/typeshed/stdlib/argparse.pyi

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

88
__all__ = [
@@ -38,9 +38,7 @@ ONE_OR_MORE: Final = "+"
3838
OPTIONAL: Final = "?"
3939
PARSER: Final = "A..."
4040
REMAINDER: Final = "..."
41-
_SUPPRESS_T = NewType("_SUPPRESS_T", str)
42-
SUPPRESS: _SUPPRESS_T | str # not using Literal because argparse sometimes compares SUPPRESS with is
43-
# the | str is there so that foo = argparse.SUPPRESS; foo = "test" checks out in mypy
41+
SUPPRESS: Final = "==SUPPRESS=="
4442
ZERO_OR_MORE: Final = "*"
4543
_UNRECOGNIZED_ARGS_ATTR: Final = "_unrecognized_args" # undocumented
4644

@@ -83,7 +81,7 @@ class _ActionsContainer:
8381
# more precisely, Literal["?", "*", "+", "...", "A...", "==SUPPRESS=="],
8482
# but using this would make it hard to annotate callers that don't use a
8583
# literal argument and for subclasses to override this method.
86-
nargs: int | str | _SUPPRESS_T | None = None,
84+
nargs: int | str | None = None,
8785
const: Any = ...,
8886
default: Any = ...,
8987
type: _ActionType = ...,

mypy/typeshed/stdlib/asyncio/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# ruff: noqa: PLR5501 # This condition is so big, it's clearer to keep to platform condition in two blocks
2+
# Can't NOQA on a specific line: https://github.com/plinss/flake8-noqa/issues/22
13
import sys
24
from collections.abc import Awaitable, Coroutine, Generator
35
from typing import Any, TypeVar

mypy/typeshed/stdlib/asyncio/base_events.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ from asyncio.protocols import BaseProtocol
88
from asyncio.tasks import Task
99
from asyncio.transports import BaseTransport, DatagramTransport, ReadTransport, SubprocessTransport, Transport, WriteTransport
1010
from collections.abc import Callable, Iterable, Sequence
11+
from concurrent.futures import Executor, ThreadPoolExecutor
1112
from contextvars import Context
1213
from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket
1314
from typing import IO, Any, Literal, TypeVar, overload
@@ -96,8 +97,8 @@ class BaseEventLoop(AbstractEventLoop):
9697
def call_soon_threadsafe(
9798
self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None
9899
) -> Handle: ...
99-
def run_in_executor(self, executor: Any, func: Callable[[Unpack[_Ts]], _T], *args: Unpack[_Ts]) -> Future[_T]: ...
100-
def set_default_executor(self, executor: Any) -> None: ...
100+
def run_in_executor(self, executor: Executor | None, func: Callable[[Unpack[_Ts]], _T], *args: Unpack[_Ts]) -> Future[_T]: ...
101+
def set_default_executor(self, executor: ThreadPoolExecutor) -> None: ... # type: ignore[override]
101102
# Network I/O methods returning Futures.
102103
async def getaddrinfo(
103104
self,

mypy/typeshed/stdlib/asyncio/events.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ from _asyncio import (
99
from _typeshed import FileDescriptorLike, ReadableBuffer, StrPath, Unused, WriteableBuffer
1010
from abc import ABCMeta, abstractmethod
1111
from collections.abc import Callable, Sequence
12+
from concurrent.futures import Executor
1213
from contextvars import Context
1314
from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket
1415
from typing import IO, Any, Literal, Protocol, TypeVar, overload
@@ -188,9 +189,9 @@ class AbstractEventLoop:
188189
def call_soon_threadsafe(self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> Handle: ...
189190

190191
@abstractmethod
191-
def run_in_executor(self, executor: Any, func: Callable[[Unpack[_Ts]], _T], *args: Unpack[_Ts]) -> Future[_T]: ...
192+
def run_in_executor(self, executor: Executor | None, func: Callable[[Unpack[_Ts]], _T], *args: Unpack[_Ts]) -> Future[_T]: ...
192193
@abstractmethod
193-
def set_default_executor(self, executor: Any) -> None: ...
194+
def set_default_executor(self, executor: Executor) -> None: ...
194195
# Network I/O methods returning Futures.
195196
@abstractmethod
196197
async def getaddrinfo(

0 commit comments

Comments
 (0)