Skip to content

Commit 2a19f1b

Browse files
committed
Fix SupportsAnext & contextlib._SupportsAclose.
Co-authored-by: https//@graingert.co.uk
1 parent 3191092 commit 2a19f1b

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

stdlib/_typeshed/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import ctypes
77
import mmap
88
import sys
99
from os import PathLike
10-
from typing import AbstractSet, Any, Container, Generic, Iterable, Protocol, TypeVar, Union
10+
from typing import AbstractSet, Any, Awaitable, Container, Generic, Iterable, Protocol, TypeVar, Union
1111
from typing_extensions import Final, Literal, final
1212

1313
_KT = TypeVar("_KT")
@@ -33,7 +33,7 @@ class SupportsNext(Protocol[_T_co]):
3333

3434
# stable
3535
class SupportsAnext(Protocol[_T_co]):
36-
async def __anext__(self) -> _T_co: ...
36+
def __anext__(self) -> Awaitable[_T_co]: ...
3737

3838
# Comparison protocols
3939

stdlib/builtins.pyi

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ from typing import (
2929
IO,
3030
AbstractSet,
3131
Any,
32+
Awaitable,
3233
BinaryIO,
3334
ByteString,
3435
Generic,
@@ -72,6 +73,8 @@ _T4 = TypeVar("_T4")
7273
_T5 = TypeVar("_T5")
7374
_SupportsNextT = TypeVar("_SupportsNextT", bound=SupportsNext[Any], covariant=True)
7475
_SupportsAnextT = TypeVar("_SupportsAnextT", bound=SupportsAnext[Any], covariant=True)
76+
_AwaitableT = TypeVar("_AwaitableT", bound=Awaitable[Any])
77+
_AwaitableT_co = TypeVar("_AwaitableT_co", bound=Awaitable[Any], covariant=True)
7578

7679
class _SupportsIter(Protocol[_T_co]):
7780
def __iter__(self) -> _T_co: ...
@@ -1068,10 +1071,17 @@ class _PathLike(Protocol[_AnyStr_co]):
10681071

10691072
if sys.version_info >= (3, 10):
10701073
def aiter(__async_iterable: _SupportsAiter[_SupportsAnextT]) -> _SupportsAnextT: ...
1074+
1075+
class _SupportsSynchronousAnext(Protocol[_AwaitableT_co]):
1076+
def __anext__(self) -> _AwaitableT_co: ...
1077+
1078+
class _SupportsAwaitableAnext(Protocol[_T_co]):
1079+
def __anext__(self) -> Awaitable[_T_co]: ...
1080+
10711081
@overload
1072-
async def anext(__i: SupportsAnext[_T]) -> _T: ...
1082+
def anext(__i: _SupportsSynchronousAnext[_AwaitableT]) -> _AwaitableT: ...
10731083
@overload
1074-
async def anext(__i: SupportsAnext[_T], default: _VT) -> _T | _VT: ...
1084+
async def anext(__i: _SupportsAwaitableAnext[_T], default: _VT) -> _T | _VT: ...
10751085

10761086
# TODO: `compile` has a more precise return type in reality; work on a way of expressing that?
10771087
if sys.version_info >= (3, 8):

stdlib/contextlib.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class closing(AbstractContextManager[_SupportsCloseT]):
155155

156156
if sys.version_info >= (3, 10):
157157
class _SupportsAclose(Protocol):
158-
async def aclose(self) -> object: ...
158+
def aclose(self) -> Awaitable[object]: ...
159159
_SupportsAcloseT = TypeVar("_SupportsAcloseT", bound=_SupportsAclose)
160160

161161
class aclosing(AbstractAsyncContextManager[_SupportsAcloseT]):

0 commit comments

Comments
 (0)