]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] 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:18:53 +0000 (15:18 +0100)
committerGitHub <noreply@github.com>
Mon, 2 Dec 2024 14:18:53 +0000 (14:18 +0000)
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 106bd81b69e34c828abc9595765e1a8b003c823a..0e533757982d35a12b2f607cd3fb57a8b34e8a70 100644 (file)
@@ -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
index 94c211292ecf9d5f666a1a0749a3477f2202eeef..a271416d46cc3ebb53f25a2ae2dc5c8e741e6b9f 100644 (file)
@@ -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 (file)
index 0000000..9741294
--- /dev/null
@@ -0,0 +1 @@
+Allow :class:`collections.abc.AsyncIterator` to be a base for Protocols.