Skip to content

Commit feb3e0b

Browse files
authored
gh-126699: allow AsyncIterator to be used as a base for Protocols (#126702)
1 parent 0052a8c commit feb3e0b

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
@@ -4255,6 +4255,9 @@ class CustomProtocol(TestCase, Protocol):
42554255
class CustomContextManager(typing.ContextManager, Protocol):
42564256
pass
42574257

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

Lib/typing.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1940,7 +1940,8 @@ def _allow_reckless_class_checks(depth=2):
19401940
_PROTO_ALLOWLIST = {
19411941
'collections.abc': [
19421942
'Callable', 'Awaitable', 'Iterable', 'Iterator', 'AsyncIterable',
1943-
'Hashable', 'Sized', 'Container', 'Collection', 'Reversible', 'Buffer',
1943+
'AsyncIterator', 'Hashable', 'Sized', 'Container', 'Collection',
1944+
'Reversible', 'Buffer',
19441945
],
19451946
'contextlib': ['AbstractContextManager', 'AbstractAsyncContextManager'],
19461947
}
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)