]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-126699: allow AsyncIterator to be used as a base for Protocols (GH-126702...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 2 Dec 2024 14:10:25 +0000 (15:10 +0100)
committerGitHub <noreply@github.com>
Mon, 2 Dec 2024 14:10:25 +0000 (15:10 +0100)
gh-126699: allow AsyncIterator to be used as a base for Protocols (GH-126702)
(cherry picked from commit feb3e0b19cb03f06364a3f5e970f0861b8883d1c)

Co-authored-by: Stephen Morton <github@tungol.org>
Lib/test/test_typing.py
Lib/typing.py
Misc/NEWS.d/next/Library/2024-11-11-13-24-22.gh-issue-126699.ONGbMd.rst [new file with mode: 0644]

index ec431af8119f1c3add958b8ff16349d66c7376c8..06a37c5494db5c745002699ac72adae2a5ea297f 100644 (file)
@@ -4254,6 +4254,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
index fda0b2dd7260c179eec178be57ffaee14fa1e455..bba29db8559da216cd2d00d5da403b53b383ab50 100644 (file)
@@ -1989,7 +1989,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 (file)
index 0000000..9741294
--- /dev/null
@@ -0,0 +1 @@
+Allow :class:`collections.abc.AsyncIterator` to be a base for Protocols.