https://github.com/python/cpython/commit/a5672bec68068c3a84f46f9020b5dc2fdc324501
commit: a5672bec68068c3a84f46f9020b5dc2fdc324501
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: Yhg1s <[email protected]>
date: 2024-12-02T15:10:25+01:00
summary:

[3.13] gh-126699: allow AsyncIterator to be used as a base for Protocols 
(GH-126702) (#126762)

gh-126699: allow AsyncIterator to be used as a base for Protocols (GH-126702)
(cherry picked from commit feb3e0b19cb03f06364a3f5e970f0861b8883d1c)

Co-authored-by: Stephen Morton <[email protected]>

files:
A Misc/NEWS.d/next/Library/2024-11-11-13-24-22.gh-issue-126699.ONGbMd.rst
M Lib/test/test_typing.py
M Lib/typing.py

diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index ec431af8119f1c..06a37c5494db5c 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -4254,6 +4254,9 @@ class CustomProtocol(TestCase, Protocol):
         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 fda0b2dd7260c1..bba29db8559da2 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -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
index 00000000000000..9741294487d716
--- /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.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to