Skip to content

Commit 0e45a7a

Browse files
tungolmiss-islington
authored andcommitted
pythongh-126699: allow AsyncIterator to be used as a base for Protocols (pythonGH-126702)
(cherry picked from commit feb3e0b) Co-authored-by: Stephen Morton <[email protected]>
1 parent 865f096 commit 0e45a7a

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

Lib/test/test_typing.py

+3
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

+2-1
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
}
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)