Skip to content

Commit 387ef81

Browse files
Return Supports(A)Next from (a)iter (python#6035)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
1 parent 60f2d2f commit 387ef81

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎stdlib/builtins.pyi‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ from typing import (
2828
IO,
2929
AbstractSet,
3030
Any,
31-
AsyncIterable,
32-
AsyncIterator,
3331
BinaryIO,
3432
ByteString,
3533
Callable,
@@ -76,6 +74,14 @@ _T5 = TypeVar("_T5")
7674
_TT = TypeVar("_TT", bound="type")
7775
_TBE = TypeVar("_TBE", bound="BaseException")
7876
_R = TypeVar("_R") # Return-type TypeVar
77+
_SupportsNextT = TypeVar("_SupportsNextT", bound=SupportsNext[Any], covariant=True)
78+
_SupportsAnextT = TypeVar("_SupportsAnextT", bound=SupportsAnext[Any], covariant=True)
79+
80+
class _SupportsIter(Protocol[_T_co]):
81+
def __iter__(self) -> _T_co: ...
82+
83+
class _SupportsAiter(Protocol[_T_co]):
84+
def __aiter__(self) -> _T_co: ...
7985

8086
class object:
8187
__doc__: str | None
@@ -990,7 +996,7 @@ class _PathLike(Protocol[_AnyStr_co]):
990996
def __fspath__(self) -> _AnyStr_co: ...
991997

992998
if sys.version_info >= (3, 10):
993-
def aiter(__async_iterable: AsyncIterable[_T]) -> AsyncIterator[_T]: ...
999+
def aiter(__async_iterable: _SupportsAiter[_SupportsAnextT]) -> _SupportsAnextT: ...
9941000
@overload
9951001
async def anext(__i: SupportsAnext[_T]) -> _T: ...
9961002
@overload
@@ -1073,7 +1079,7 @@ def hex(__number: int | SupportsIndex) -> str: ...
10731079
def id(__obj: object) -> int: ...
10741080
def input(__prompt: object = ...) -> str: ...
10751081
@overload
1076-
def iter(__iterable: Iterable[_T]) -> Iterator[_T]: ...
1082+
def iter(__iterable: _SupportsIter[_SupportsNextT]) -> _SupportsNextT: ...
10771083
@overload
10781084
def iter(__function: Callable[[], _T | None], __sentinel: None) -> Iterator[_T]: ...
10791085
@overload

0 commit comments

Comments
 (0)