Skip to content

Commit 34137cb

Browse files
[3.12] gh-126699: allow AsyncIterator to be used as a base for Protocols (GH-126702) (#126761)
gh-126699: allow AsyncIterator to be used as a base for Protocols (GH-126702) (cherry picked from commit feb3e0b) Co-authored-by: Stephen Morton <[email protected]>
1 parent 179b134 commit 34137cb

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
@@ -3998,6 +3998,9 @@ class CustomProtocol(TestCase, Protocol):
39983998
class CustomContextManager(typing.ContextManager, Protocol):
39993999
pass
40004000

4001+
class CustomAsyncIterator(typing.AsyncIterator, Protocol):
4002+
pass
4003+
40014004
def test_non_runtime_protocol_isinstance_check(self):
40024005
class P(Protocol):
40034006
x: int

Lib/typing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,8 @@ def _allow_reckless_class_checks(depth=2):
18151815
_PROTO_ALLOWLIST = {
18161816
'collections.abc': [
18171817
'Callable', 'Awaitable', 'Iterable', 'Iterator', 'AsyncIterable',
1818-
'Hashable', 'Sized', 'Container', 'Collection', 'Reversible', 'Buffer',
1818+
'AsyncIterator', 'Hashable', 'Sized', 'Container', 'Collection',
1819+
'Reversible', 'Buffer',
18191820
],
18201821
'contextlib': ['AbstractContextManager', 'AbstractAsyncContextManager'],
18211822
}
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)