Skip to content

Commit

Permalink
pythongh-126699: allow AsyncIterator to be used as a base for Protoco…
Browse files Browse the repository at this point in the history
…ls (pythonGH-126702)

(cherry picked from commit feb3e0b)

Co-authored-by: Stephen Morton <github@tungol.org>
  • Loading branch information
tungol authored and miss-islington committed Nov 12, 2024
1 parent 46710ca commit a38877b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3998,6 +3998,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
Expand Down
3 changes: 2 additions & 1 deletion Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1815,7 +1815,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'],
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow :class:`collections.abc.AsyncIterator` to be a base for Protocols.

0 comments on commit a38877b

Please sign in to comment.