diff options
author | Stephen Morton <github@tungol.org> | 2024-11-12 09:17:07 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-12 09:17:07 (GMT) |
commit | feb3e0b19cb03f06364a3f5e970f0861b8883d1c (patch) | |
tree | d1fa798c38d7ea640390724984f39c5238ff5b30 | |
parent | 0052a8c638518447baf39ae02b6ff6a309efd4ce (diff) | |
download | cpython-feb3e0b19cb03f06364a3f5e970f0861b8883d1c.zip cpython-feb3e0b19cb03f06364a3f5e970f0861b8883d1c.tar.gz cpython-feb3e0b19cb03f06364a3f5e970f0861b8883d1c.tar.bz2 |
gh-126699: allow AsyncIterator to be used as a base for Protocols (#126702)
-rw-r--r-- | Lib/test/test_typing.py | 3 | ||||
-rw-r--r-- | Lib/typing.py | 3 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2024-11-11-13-24-22.gh-issue-126699.ONGbMd.rst | 1 |
3 files changed, 6 insertions, 1 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 2f1f9e8..244ce1e 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -4255,6 +4255,9 @@ class ProtocolTests(BaseTestCase): 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 diff --git a/Lib/typing.py b/Lib/typing.py index c924c76..8e63810 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -1940,7 +1940,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'], } diff --git a/Misc/NEWS.d/next/Library/2024-11-11-13-24-22.gh-issue-126699.ONGbMd.rst b/Misc/NEWS.d/next/Library/2024-11-11-13-24-22.gh-issue-126699.ONGbMd.rst new file mode 100644 index 0000000..9741294 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-11-11-13-24-22.gh-issue-126699.ONGbMd.rst @@ -0,0 +1 @@ +Allow :class:`collections.abc.AsyncIterator` to be a base for Protocols. |