From bee4f2d0a61a15ed26f2611648fefb25860b3904 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 14 Mar 2022 16:29:11 +0000 Subject: [PATCH 1/8] Improve `typing.AsyncIterator` and `typing.AsyncGenerator` --- stdlib/typing.pyi | 18 +++++++----------- tests/stubtest_allowlists/py310.txt | 4 ++-- tests/stubtest_allowlists/py3_common.txt | 3 +++ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 457ad21b72d2..4766a416d9bb 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -743,26 +743,22 @@ class AsyncIterable(Protocol[_T_co]): @runtime_checkable class AsyncIterator(AsyncIterable[_T_co], Protocol[_T_co]): @abstractmethod - async def __anext__(self) -> _T_co: ... + def __anext__(self) -> Awaitable[_T_co]: ... def __aiter__(self) -> AsyncIterator[_T_co]: ... class AsyncGenerator(AsyncIterator[_T_co], Generic[_T_co, _T_contra]): + def __anext__(self) -> Awaitable[_T_co]: ... @abstractmethod - async def __anext__(self) -> _T_co: ... - @abstractmethod - async def asend(self, __value: _T_contra) -> _T_co: ... + def asend(self, __value: _T_contra) -> Awaitable[_T_co]: ... @overload @abstractmethod - async def athrow( + def athrow( self, __typ: Type[BaseException], __val: BaseException | object = ..., __tb: TracebackType | None = ... - ) -> _T_co: ... + ) -> Awaitable[_T_co]: ... @overload @abstractmethod - async def athrow(self, __typ: BaseException, __val: None = ..., __tb: TracebackType | None = ...) -> _T_co: ... - @abstractmethod - async def aclose(self) -> None: ... - @abstractmethod - def __aiter__(self) -> AsyncGenerator[_T_co, _T_contra]: ... + def athrow(self, __typ: BaseException, __val: None = ..., __tb: TracebackType | None = ...) -> Awaitable[_T_co]: ... + def aclose(self) -> Awaitable[None]: ... @property def ag_await(self) -> Any: ... @property diff --git a/tests/stubtest_allowlists/py310.txt b/tests/stubtest_allowlists/py310.txt index f59e0150fc9d..f36c2eb48918 100644 --- a/tests/stubtest_allowlists/py310.txt +++ b/tests/stubtest_allowlists/py310.txt @@ -106,8 +106,8 @@ xml.etree.ElementTree.XMLParser.__init__ # Defined in C so has general signatur xml.etree.cElementTree.XMLParser.__init__ # Defined in C so has general signature # positional-only complaints caused by differences between typing aliases and the "real" classes in the stdlib -_collections_abc.AsyncGenerator.asend -_collections_abc.AsyncGenerator.athrow +_collections_abc.AsyncGenerator.asend # is also "async def" at runtime, but sync in the stub (see discussion in #7475) +_collections_abc.AsyncGenerator.athrow # is also "async def" at runtime, but sync in the stub (see discussion in #7475) _collections_abc.Coroutine.send _collections_abc.Coroutine.throw _collections_abc.Generator.send diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index 13ac388e7bc5..51ea9a986c34 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -246,6 +246,9 @@ xml.parsers.expat.expat_CAPI # ========== # Allowlist entries that cannot or should not be fixed # ========== +_collections_abc.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7475 +_collections_abc.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7475 +_collections_abc.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7475 _pydecimal.* # See comments in file _weakref.ProxyType.__bytes__ # Doesn't really exist ast.NodeVisitor.visit_\w+ # Methods are discovered dynamically, see #3796 From 6041c28cf6feae306a51b462209d1b0c7f7629c1 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 14 Mar 2022 16:49:45 +0000 Subject: [PATCH 2/8] Fix allowlists --- tests/stubtest_allowlists/py310.txt | 2 -- tests/stubtest_allowlists/py36.txt | 5 +++++ tests/stubtest_allowlists/py37.txt | 5 +++++ tests/stubtest_allowlists/py38.txt | 5 +++++ tests/stubtest_allowlists/py39.txt | 5 +++++ tests/stubtest_allowlists/py3_common.txt | 2 ++ 6 files changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/stubtest_allowlists/py310.txt b/tests/stubtest_allowlists/py310.txt index f36c2eb48918..f05d4f94de37 100644 --- a/tests/stubtest_allowlists/py310.txt +++ b/tests/stubtest_allowlists/py310.txt @@ -106,8 +106,6 @@ xml.etree.ElementTree.XMLParser.__init__ # Defined in C so has general signatur xml.etree.cElementTree.XMLParser.__init__ # Defined in C so has general signature # positional-only complaints caused by differences between typing aliases and the "real" classes in the stdlib -_collections_abc.AsyncGenerator.asend # is also "async def" at runtime, but sync in the stub (see discussion in #7475) -_collections_abc.AsyncGenerator.athrow # is also "async def" at runtime, but sync in the stub (see discussion in #7475) _collections_abc.Coroutine.send _collections_abc.Coroutine.throw _collections_abc.Generator.send diff --git a/tests/stubtest_allowlists/py36.txt b/tests/stubtest_allowlists/py36.txt index 201e0e05e69a..b63865d1d641 100644 --- a/tests/stubtest_allowlists/py36.txt +++ b/tests/stubtest_allowlists/py36.txt @@ -11,6 +11,11 @@ asyncio.locks._ContextManagerMixin.__exit__ # Always raises; deliberately omitt builtins.float.__setformat__ # Internal method for CPython test suite builtins.str.maketrans cmath.log +collections.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. +collections.AsyncGenerator.athrow # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. +collections.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7475 +collections.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7475 +collections.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7475 collections.AsyncGenerator.ag_await collections.AsyncGenerator.ag_code collections.AsyncGenerator.ag_frame diff --git a/tests/stubtest_allowlists/py37.txt b/tests/stubtest_allowlists/py37.txt index 9a9173c76f3e..4d8c50c02ce9 100644 --- a/tests/stubtest_allowlists/py37.txt +++ b/tests/stubtest_allowlists/py37.txt @@ -15,6 +15,11 @@ builtins.dict.get builtins.float.__set_format__ # Internal method for CPython test suite builtins.str.maketrans cmath.log +collections.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. +collections.AsyncGenerator.athrow # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. +collections.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7475 +collections.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7475 +collections.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7475 collections.AsyncGenerator.ag_await collections.AsyncGenerator.ag_code collections.AsyncGenerator.ag_frame diff --git a/tests/stubtest_allowlists/py38.txt b/tests/stubtest_allowlists/py38.txt index 34c7df60e9fa..ea55ed787155 100644 --- a/tests/stubtest_allowlists/py38.txt +++ b/tests/stubtest_allowlists/py38.txt @@ -19,6 +19,11 @@ asyncio.locks._ContextManagerMixin.__enter__ # Always raises; deliberately omit asyncio.locks._ContextManagerMixin.__exit__ # Always raises; deliberately omitted from the stub builtins.dict.get builtins.float.__set_format__ # Internal method for CPython test suite +collections.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. +collections.AsyncGenerator.athrow # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. +collections.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7475 +collections.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7475 +collections.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7475 collections.AsyncGenerator.ag_await collections.AsyncGenerator.ag_code collections.AsyncGenerator.ag_frame diff --git a/tests/stubtest_allowlists/py39.txt b/tests/stubtest_allowlists/py39.txt index 6464c88c1732..aab1a1af517d 100644 --- a/tests/stubtest_allowlists/py39.txt +++ b/tests/stubtest_allowlists/py39.txt @@ -21,6 +21,11 @@ asyncio.futures.Future.__init__ # Usually initialized from c object asyncio.futures.Future._callbacks # Usually initialized from c object builtins.dict.get builtins.float.__set_format__ # Internal method for CPython test suite +collections.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. +collections.AsyncGenerator.athrow # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. +collections.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7475 +collections.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7475 +collections.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7475 collections.AsyncGenerator.ag_await collections.AsyncGenerator.ag_code collections.AsyncGenerator.ag_frame diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index 51ea9a986c34..5664eb3158a0 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -246,6 +246,8 @@ xml.parsers.expat.expat_CAPI # ========== # Allowlist entries that cannot or should not be fixed # ========== +_collections_abc.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. +_collections_abc.AsyncGenerator.athrow # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. _collections_abc.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7475 _collections_abc.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7475 _collections_abc.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7475 From 319109240c22af6dfbe8041f680c5a3296e47ff1 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 14 Mar 2022 16:58:35 +0000 Subject: [PATCH 3/8] Allow --- tests/stubtest_allowlists/py310.txt | 1 + tests/stubtest_allowlists/py36.txt | 3 ++- tests/stubtest_allowlists/py37.txt | 1 - tests/stubtest_allowlists/py38.txt | 1 - tests/stubtest_allowlists/py39.txt | 1 - tests/stubtest_allowlists/py3_common.txt | 1 - 6 files changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/stubtest_allowlists/py310.txt b/tests/stubtest_allowlists/py310.txt index f05d4f94de37..64e427666cd7 100644 --- a/tests/stubtest_allowlists/py310.txt +++ b/tests/stubtest_allowlists/py310.txt @@ -23,6 +23,7 @@ typing.IO.truncate typing.IO.write typing.IO.writelines +_collections_abc.AsyncGenerator.athrow # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. _weakref.ProxyType.__reversed__ # Doesn't really exist ast.Bytes.__new__ ast.Ellipsis.__new__ diff --git a/tests/stubtest_allowlists/py36.txt b/tests/stubtest_allowlists/py36.txt index b63865d1d641..7d18436fa964 100644 --- a/tests/stubtest_allowlists/py36.txt +++ b/tests/stubtest_allowlists/py36.txt @@ -12,7 +12,6 @@ builtins.float.__setformat__ # Internal method for CPython test suite builtins.str.maketrans cmath.log collections.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. -collections.AsyncGenerator.athrow # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. collections.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7475 collections.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7475 collections.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7475 @@ -94,6 +93,8 @@ tkinter.filedialog.TkVersion tkinter.filedialog.wantobjects tkinter.simpledialog.wantobjects tkinter.tix.wantobjects +typing.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7475 +typing.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7475 builtins.memoryview.__iter__ # C type that implements __getitem__ builtins.memoryview.cast # inspect.signature is incorrect about shape being kw-only diff --git a/tests/stubtest_allowlists/py37.txt b/tests/stubtest_allowlists/py37.txt index 4d8c50c02ce9..4971717009b2 100644 --- a/tests/stubtest_allowlists/py37.txt +++ b/tests/stubtest_allowlists/py37.txt @@ -16,7 +16,6 @@ builtins.float.__set_format__ # Internal method for CPython test suite builtins.str.maketrans cmath.log collections.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. -collections.AsyncGenerator.athrow # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. collections.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7475 collections.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7475 collections.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7475 diff --git a/tests/stubtest_allowlists/py38.txt b/tests/stubtest_allowlists/py38.txt index ea55ed787155..50d95dda070f 100644 --- a/tests/stubtest_allowlists/py38.txt +++ b/tests/stubtest_allowlists/py38.txt @@ -20,7 +20,6 @@ asyncio.locks._ContextManagerMixin.__exit__ # Always raises; deliberately omitt builtins.dict.get builtins.float.__set_format__ # Internal method for CPython test suite collections.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. -collections.AsyncGenerator.athrow # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. collections.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7475 collections.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7475 collections.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7475 diff --git a/tests/stubtest_allowlists/py39.txt b/tests/stubtest_allowlists/py39.txt index aab1a1af517d..e6eb232763fd 100644 --- a/tests/stubtest_allowlists/py39.txt +++ b/tests/stubtest_allowlists/py39.txt @@ -22,7 +22,6 @@ asyncio.futures.Future._callbacks # Usually initialized from c object builtins.dict.get builtins.float.__set_format__ # Internal method for CPython test suite collections.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. -collections.AsyncGenerator.athrow # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. collections.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7475 collections.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7475 collections.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7475 diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index 5664eb3158a0..f5e22b22b5bd 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -247,7 +247,6 @@ xml.parsers.expat.expat_CAPI # Allowlist entries that cannot or should not be fixed # ========== _collections_abc.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. -_collections_abc.AsyncGenerator.athrow # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. _collections_abc.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7475 _collections_abc.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7475 _collections_abc.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7475 From 80acd91059ae7dc8bd83a2c61ef5f62bc30645bb Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 14 Mar 2022 23:01:07 +0000 Subject: [PATCH 4/8] Fix `SupportsAnext` & `contextlib._SupportsAclose`. Co-authored-by: graingert --- stdlib/_typeshed/__init__.pyi | 4 ++-- stdlib/builtins.pyi | 14 ++++++++++++-- stdlib/contextlib.pyi | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/stdlib/_typeshed/__init__.pyi b/stdlib/_typeshed/__init__.pyi index 103af47c7524..9088e86b7b4e 100644 --- a/stdlib/_typeshed/__init__.pyi +++ b/stdlib/_typeshed/__init__.pyi @@ -7,7 +7,7 @@ import ctypes import mmap import sys from os import PathLike -from typing import AbstractSet, Any, Container, Generic, Iterable, Protocol, TypeVar, Union +from typing import AbstractSet, Any, Awaitable, Container, Generic, Iterable, Protocol, TypeVar, Union from typing_extensions import Final, Literal, final _KT = TypeVar("_KT") @@ -33,7 +33,7 @@ class SupportsNext(Protocol[_T_co]): # stable class SupportsAnext(Protocol[_T_co]): - async def __anext__(self) -> _T_co: ... + def __anext__(self) -> Awaitable[_T_co]: ... # Comparison protocols diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 176d07a9daa8..8f2149251c5a 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -29,6 +29,7 @@ from typing import ( IO, AbstractSet, Any, + Awaitable, BinaryIO, ByteString, Generic, @@ -72,6 +73,8 @@ _T4 = TypeVar("_T4") _T5 = TypeVar("_T5") _SupportsNextT = TypeVar("_SupportsNextT", bound=SupportsNext[Any], covariant=True) _SupportsAnextT = TypeVar("_SupportsAnextT", bound=SupportsAnext[Any], covariant=True) +_AwaitableT = TypeVar("_AwaitableT", bound=Awaitable[Any]) +_AwaitableT_co = TypeVar("_AwaitableT_co", bound=Awaitable[Any], covariant=True) class _SupportsIter(Protocol[_T_co]): def __iter__(self) -> _T_co: ... @@ -1068,10 +1071,17 @@ class _PathLike(Protocol[_AnyStr_co]): if sys.version_info >= (3, 10): def aiter(__async_iterable: _SupportsAiter[_SupportsAnextT]) -> _SupportsAnextT: ... + + class _SupportsSynchronousAnext(Protocol[_AwaitableT_co]): + def __anext__(self) -> _AwaitableT_co: ... + + class _SupportsAwaitableAnext(Protocol[_T_co]): + def __anext__(self) -> Awaitable[_T_co]: ... + @overload - async def anext(__i: SupportsAnext[_T]) -> _T: ... + def anext(__i: _SupportsSynchronousAnext[_AwaitableT]) -> _AwaitableT: ... @overload - async def anext(__i: SupportsAnext[_T], default: _VT) -> _T | _VT: ... + async def anext(__i: _SupportsAwaitableAnext[_T], default: _VT) -> _T | _VT: ... # TODO: `compile` has a more precise return type in reality; work on a way of expressing that? if sys.version_info >= (3, 8): diff --git a/stdlib/contextlib.pyi b/stdlib/contextlib.pyi index c2731dea7807..7c2d0db1eca9 100644 --- a/stdlib/contextlib.pyi +++ b/stdlib/contextlib.pyi @@ -155,7 +155,7 @@ class closing(AbstractContextManager[_SupportsCloseT]): if sys.version_info >= (3, 10): class _SupportsAclose(Protocol): - async def aclose(self) -> object: ... + def aclose(self) -> Awaitable[object]: ... _SupportsAcloseT = TypeVar("_SupportsAcloseT", bound=_SupportsAclose) class aclosing(AbstractAsyncContextManager[_SupportsAcloseT]): From 825910a9de2ae3cb519bac1d097b76914930e485 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 15 Mar 2022 12:03:54 +0000 Subject: [PATCH 5/8] Use `_typeshed.Anext` --- stdlib/builtins.pyi | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 8f2149251c5a..54308e4260cd 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -1075,13 +1075,10 @@ if sys.version_info >= (3, 10): class _SupportsSynchronousAnext(Protocol[_AwaitableT_co]): def __anext__(self) -> _AwaitableT_co: ... - class _SupportsAwaitableAnext(Protocol[_T_co]): - def __anext__(self) -> Awaitable[_T_co]: ... - @overload def anext(__i: _SupportsSynchronousAnext[_AwaitableT]) -> _AwaitableT: ... @overload - async def anext(__i: _SupportsAwaitableAnext[_T], default: _VT) -> _T | _VT: ... + async def anext(__i: SupportsAnext[_T], default: _VT) -> _T | _VT: ... # TODO: `compile` has a more precise return type in reality; work on a way of expressing that? if sys.version_info >= (3, 8): From e5d3697938e51cc3ecbb8f2ac2a73e00e657e7f8 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 15 Mar 2022 16:18:40 +0000 Subject: [PATCH 6/8] Add comment Co-authored-by: Thomas Grainger --- stdlib/builtins.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 54308e4260cd..dead79d08091 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -1076,6 +1076,8 @@ if sys.version_info >= (3, 10): def __anext__(self) -> _AwaitableT_co: ... @overload + # anext is not, in fact, an async function. When default is not provided + # anext is just a passthrough for obj.__anext__ def anext(__i: _SupportsSynchronousAnext[_AwaitableT]) -> _AwaitableT: ... @overload async def anext(__i: SupportsAnext[_T], default: _VT) -> _T | _VT: ... From a25aa373daff5e3f935e5a2700f03df7dd10763a Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 15 Mar 2022 16:58:38 +0000 Subject: [PATCH 7/8] Improve comment --- stdlib/builtins.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index dead79d08091..e3113951e5a7 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -1076,8 +1076,9 @@ if sys.version_info >= (3, 10): def __anext__(self) -> _AwaitableT_co: ... @overload - # anext is not, in fact, an async function. When default is not provided - # anext is just a passthrough for obj.__anext__ + # `anext` is not, in fact, an async function. When default is not provided + # `anext` is just a passthrough for `obj.__anext__` + # See discussion in #7491 and pure-Python implementation of `anext` at https://github.com/python/cpython/blob/ea786a882b9ed4261eafabad6011bc7ef3b5bf94/Lib/test/test_asyncgen.py#L52-L80 def anext(__i: _SupportsSynchronousAnext[_AwaitableT]) -> _AwaitableT: ... @overload async def anext(__i: SupportsAnext[_T], default: _VT) -> _T | _VT: ... From 748c8e8b808f4cf742d360e491fd15aab69b9cdd Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 15 Mar 2022 17:24:30 +0000 Subject: [PATCH 8/8] Fix allowlist references --- tests/stubtest_allowlists/py310.txt | 2 +- tests/stubtest_allowlists/py36.txt | 12 ++++++------ tests/stubtest_allowlists/py37.txt | 8 ++++---- tests/stubtest_allowlists/py38.txt | 8 ++++---- tests/stubtest_allowlists/py39.txt | 8 ++++---- tests/stubtest_allowlists/py3_common.txt | 8 ++++---- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/tests/stubtest_allowlists/py310.txt b/tests/stubtest_allowlists/py310.txt index 64e427666cd7..07c6b5338006 100644 --- a/tests/stubtest_allowlists/py310.txt +++ b/tests/stubtest_allowlists/py310.txt @@ -23,7 +23,7 @@ typing.IO.truncate typing.IO.write typing.IO.writelines -_collections_abc.AsyncGenerator.athrow # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. +_collections_abc.AsyncGenerator.athrow # async at runtime, deliberately not in the stub, see #7491. Pos-only differences also. _weakref.ProxyType.__reversed__ # Doesn't really exist ast.Bytes.__new__ ast.Ellipsis.__new__ diff --git a/tests/stubtest_allowlists/py36.txt b/tests/stubtest_allowlists/py36.txt index 7d18436fa964..c7e4c5145ca2 100644 --- a/tests/stubtest_allowlists/py36.txt +++ b/tests/stubtest_allowlists/py36.txt @@ -11,10 +11,10 @@ asyncio.locks._ContextManagerMixin.__exit__ # Always raises; deliberately omitt builtins.float.__setformat__ # Internal method for CPython test suite builtins.str.maketrans cmath.log -collections.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. -collections.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7475 -collections.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7475 -collections.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7475 +collections.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7491. Pos-only differences also. +collections.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7491 +collections.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7491 +collections.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7491 collections.AsyncGenerator.ag_await collections.AsyncGenerator.ag_code collections.AsyncGenerator.ag_frame @@ -93,8 +93,8 @@ tkinter.filedialog.TkVersion tkinter.filedialog.wantobjects tkinter.simpledialog.wantobjects tkinter.tix.wantobjects -typing.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7475 -typing.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7475 +typing.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7491 +typing.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7491 builtins.memoryview.__iter__ # C type that implements __getitem__ builtins.memoryview.cast # inspect.signature is incorrect about shape being kw-only diff --git a/tests/stubtest_allowlists/py37.txt b/tests/stubtest_allowlists/py37.txt index 4971717009b2..207b1efd1d96 100644 --- a/tests/stubtest_allowlists/py37.txt +++ b/tests/stubtest_allowlists/py37.txt @@ -15,10 +15,10 @@ builtins.dict.get builtins.float.__set_format__ # Internal method for CPython test suite builtins.str.maketrans cmath.log -collections.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. -collections.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7475 -collections.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7475 -collections.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7475 +collections.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7491. Pos-only differences also. +collections.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7491 +collections.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7491 +collections.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7491 collections.AsyncGenerator.ag_await collections.AsyncGenerator.ag_code collections.AsyncGenerator.ag_frame diff --git a/tests/stubtest_allowlists/py38.txt b/tests/stubtest_allowlists/py38.txt index 50d95dda070f..f8466db95d3a 100644 --- a/tests/stubtest_allowlists/py38.txt +++ b/tests/stubtest_allowlists/py38.txt @@ -19,10 +19,10 @@ asyncio.locks._ContextManagerMixin.__enter__ # Always raises; deliberately omit asyncio.locks._ContextManagerMixin.__exit__ # Always raises; deliberately omitted from the stub builtins.dict.get builtins.float.__set_format__ # Internal method for CPython test suite -collections.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. -collections.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7475 -collections.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7475 -collections.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7475 +collections.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7491. Pos-only differences also. +collections.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7491 +collections.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7491 +collections.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7491 collections.AsyncGenerator.ag_await collections.AsyncGenerator.ag_code collections.AsyncGenerator.ag_frame diff --git a/tests/stubtest_allowlists/py39.txt b/tests/stubtest_allowlists/py39.txt index e6eb232763fd..e3510b9fbe8f 100644 --- a/tests/stubtest_allowlists/py39.txt +++ b/tests/stubtest_allowlists/py39.txt @@ -21,10 +21,10 @@ asyncio.futures.Future.__init__ # Usually initialized from c object asyncio.futures.Future._callbacks # Usually initialized from c object builtins.dict.get builtins.float.__set_format__ # Internal method for CPython test suite -collections.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. -collections.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7475 -collections.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7475 -collections.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7475 +collections.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7491. Pos-only differences also. +collections.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7491 +collections.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7491 +collections.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7491 collections.AsyncGenerator.ag_await collections.AsyncGenerator.ag_code collections.AsyncGenerator.ag_frame diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index f5e22b22b5bd..bebd306bc803 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -246,10 +246,10 @@ xml.parsers.expat.expat_CAPI # ========== # Allowlist entries that cannot or should not be fixed # ========== -_collections_abc.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7475. Pos-only differences also. -_collections_abc.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7475 -_collections_abc.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7475 -_collections_abc.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7475 +_collections_abc.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7491. Pos-only differences also. +_collections_abc.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7491 +_collections_abc.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7491 +_collections_abc.AsyncIterator.__anext__ # async at runtime, deliberately not in the stub, see #7491 _pydecimal.* # See comments in file _weakref.ProxyType.__bytes__ # Doesn't really exist ast.NodeVisitor.visit_\w+ # Methods are discovered dynamically, see #3796