]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-126699: allow AsyncIterator to be used as a base for Protocols (#126702)
authorStephen Morton <github@tungol.org>
Tue, 12 Nov 2024 09:17:07 +0000 (01:17 -0800)
committerGitHub <noreply@github.com>
Tue, 12 Nov 2024 09:17:07 +0000 (09:17 +0000)
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 2f1f9e86a0bce4ec786a15b14455aa19a0b79e3d..244ce1e5da9bd28363cf752f306dec58b988bbba 100644 (file)
@@ -4255,6 +4255,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 c924c7670425529bf787422de2c79a378b263f43..8e6381033fd28e211d118768658979dfe42cebaf 100644 (file)
@@ -1940,7 +1940,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.