Make collections.abcs more consistent with runtime implementation (#10816)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
James Hilton-Balfe
2024-12-28 05:31:59 +00:00
committed by GitHub
parent d2ca658a69
commit ab75b691c2
5 changed files with 25 additions and 67 deletions

View File

@@ -12,7 +12,6 @@ from re import Match as Match, Pattern as Pattern
from types import (
BuiltinFunctionType,
CodeType,
FrameType,
FunctionType,
MethodDescriptorType,
MethodType,
@@ -473,7 +472,8 @@ _YieldT_co = TypeVar("_YieldT_co", covariant=True)
_SendT_contra = TypeVar("_SendT_contra", contravariant=True, default=None)
_ReturnT_co = TypeVar("_ReturnT_co", covariant=True, default=None)
class Generator(Iterator[_YieldT_co], Generic[_YieldT_co, _SendT_contra, _ReturnT_co]):
@runtime_checkable
class Generator(Iterator[_YieldT_co], Protocol[_YieldT_co, _SendT_contra, _ReturnT_co]):
def __next__(self) -> _YieldT_co: ...
@abstractmethod
def send(self, value: _SendT_contra, /) -> _YieldT_co: ...
@@ -491,14 +491,6 @@ class Generator(Iterator[_YieldT_co], Generic[_YieldT_co, _SendT_contra, _Return
def close(self) -> None: ...
def __iter__(self) -> Generator[_YieldT_co, _SendT_contra, _ReturnT_co]: ...
@property
def gi_code(self) -> CodeType: ...
@property
def gi_frame(self) -> FrameType: ...
@property
def gi_running(self) -> bool: ...
@property
def gi_yieldfrom(self) -> Generator[Any, Any, Any] | None: ...
# NOTE: Prior to Python 3.13 these aliases are lacking the second _ExitT_co parameter
if sys.version_info >= (3, 13):
@@ -524,14 +516,7 @@ _ReturnT_co_nd = TypeVar("_ReturnT_co_nd", covariant=True)
class Coroutine(Awaitable[_ReturnT_co_nd], Generic[_YieldT_co, _SendT_contra_nd, _ReturnT_co_nd]):
__name__: str
__qualname__: str
@property
def cr_await(self) -> Any | None: ...
@property
def cr_code(self) -> CodeType: ...
@property
def cr_frame(self) -> FrameType | None: ...
@property
def cr_running(self) -> bool: ...
@abstractmethod
def send(self, value: _SendT_contra_nd, /) -> _YieldT_co: ...
@overload
@@ -566,7 +551,8 @@ class AsyncIterator(AsyncIterable[_T_co], Protocol[_T_co]):
def __anext__(self) -> Awaitable[_T_co]: ...
def __aiter__(self) -> AsyncIterator[_T_co]: ...
class AsyncGenerator(AsyncIterator[_YieldT_co], Generic[_YieldT_co, _SendT_contra]):
@runtime_checkable
class AsyncGenerator(AsyncIterator[_YieldT_co], Protocol[_YieldT_co, _SendT_contra]):
def __anext__(self) -> Coroutine[Any, Any, _YieldT_co]: ...
@abstractmethod
def asend(self, value: _SendT_contra, /) -> Coroutine[Any, Any, _YieldT_co]: ...
@@ -581,14 +567,6 @@ class AsyncGenerator(AsyncIterator[_YieldT_co], Generic[_YieldT_co, _SendT_contr
self, typ: BaseException, val: None = None, tb: TracebackType | None = None, /
) -> Coroutine[Any, Any, _YieldT_co]: ...
def aclose(self) -> Coroutine[Any, Any, None]: ...
@property
def ag_await(self) -> Any: ...
@property
def ag_code(self) -> CodeType: ...
@property
def ag_frame(self) -> FrameType: ...
@property
def ag_running(self) -> bool: ...
@runtime_checkable
class Container(Protocol[_T_co]):