Skip to content

Commit a5672be

Browse files
[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 feb3e0b) Co-authored-by: Stephen Morton <github@tungol.org>
1 parent d9bbb52 commit a5672be

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

Lib/test/test_typing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4254,6 +4254,9 @@ class CustomProtocol(TestCase, Protocol):
42544254
class CustomContextManager(typing.ContextManager, Protocol):
42554255
pass
42564256

4257+
class CustomAsyncIterator(typing.AsyncIterator, Protocol):
4258+
pass
4259+
42574260
def test_non_runtime_protocol_isinstance_check(self):
42584261
class P(Protocol):
42594262
x: int

Lib/typing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1989,7 +1989,8 @@ def _allow_reckless_class_checks(depth=2):
19891989
_PROTO_ALLOWLIST = {
19901990
'collections.abc': [
19911991
'Callable', 'Awaitable', 'Iterable', 'Iterator', 'AsyncIterable',
1992-
'Hashable', 'Sized', 'Container', 'Collection', 'Reversible', 'Buffer',
1992+
'AsyncIterator', 'Hashable', 'Sized', 'Container', 'Collection',
1993+
'Reversible', 'Buffer',
19931994
],
19941995
'contextlib': ['AbstractContextManager', 'AbstractAsyncContextManager'],
19951996
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow :class:`collections.abc.AsyncIterator` to be a base for Protocols.

0 commit comments

Comments
 (0)