From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Mon, 2 Dec 2024 14:18:53 +0000 (+0100) Subject: [3.12] gh-126699: allow AsyncIterator to be used as a base for Protocols (GH-126702... X-Git-Tag: v3.12.8~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=34137cbd23511269c6315efc082fa34a72e8582f;p=thirdparty%2FPython%2Fcpython.git [3.12] gh-126699: allow AsyncIterator to be used as a base for Protocols (GH-126702) (#126761) gh-126699: allow AsyncIterator to be used as a base for Protocols (GH-126702) (cherry picked from commit feb3e0b19cb03f06364a3f5e970f0861b8883d1c) Co-authored-by: Stephen Morton --- diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 106bd81b69e3..0e533757982d 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -3998,6 +3998,9 @@ class ProtocolTests(BaseTestCase): class CustomContextManager(typing.ContextManager, Protocol): pass + class CustomAsyncIterator(typing.AsyncIterator, Protocol): + pass + def test_non_runtime_protocol_isinstance_check(self): class P(Protocol): x: int diff --git a/Lib/typing.py b/Lib/typing.py index 94c211292ecf..a271416d46cc 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -1815,7 +1815,8 @@ def _allow_reckless_class_checks(depth=2): _PROTO_ALLOWLIST = { 'collections.abc': [ 'Callable', 'Awaitable', 'Iterable', 'Iterator', 'AsyncIterable', - 'Hashable', 'Sized', 'Container', 'Collection', 'Reversible', 'Buffer', + 'AsyncIterator', 'Hashable', 'Sized', 'Container', 'Collection', + 'Reversible', 'Buffer', ], 'contextlib': ['AbstractContextManager', 'AbstractAsyncContextManager'], } diff --git a/Misc/NEWS.d/next/Library/2024-11-11-13-24-22.gh-issue-126699.ONGbMd.rst b/Misc/NEWS.d/next/Library/2024-11-11-13-24-22.gh-issue-126699.ONGbMd.rst new file mode 100644 index 000000000000..9741294487d7 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-11-11-13-24-22.gh-issue-126699.ONGbMd.rst @@ -0,0 +1 @@ +Allow :class:`collections.abc.AsyncIterator` to be a base for Protocols.