From: Stephen Morton Date: Tue, 12 Nov 2024 17:54:13 +0000 (-0800) Subject: gh-126705: Make os.PathLike more like a protocol (#126706) X-Git-Tag: v3.14.0a2~73 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a83472f49b958c55befd82c871be26afbf500306;p=thirdparty%2FPython%2Fcpython.git gh-126705: Make os.PathLike more like a protocol (#126706) it can now be used as a base class in other protocols --- diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 244ce1e5da9b..aa42beca5f92 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -8,6 +8,7 @@ import gc import inspect import itertools import operator +import os import pickle import re import sys @@ -4252,6 +4253,9 @@ class ProtocolTests(BaseTestCase): class CustomProtocol(TestCase, Protocol): pass + class CustomPathLikeProtocol(os.PathLike, Protocol): + pass + class CustomContextManager(typing.ContextManager, Protocol): pass diff --git a/Lib/typing.py b/Lib/typing.py index 8e6381033fd2..938e52922aee 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -1944,6 +1944,7 @@ _PROTO_ALLOWLIST = { 'Reversible', 'Buffer', ], 'contextlib': ['AbstractContextManager', 'AbstractAsyncContextManager'], + 'os': ['PathLike'], } diff --git a/Misc/NEWS.d/next/Library/2024-11-11-14-52-21.gh-issue-126705.0W7jFW.rst b/Misc/NEWS.d/next/Library/2024-11-11-14-52-21.gh-issue-126705.0W7jFW.rst new file mode 100644 index 000000000000..f49c9c765d77 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-11-11-14-52-21.gh-issue-126705.0W7jFW.rst @@ -0,0 +1 @@ +Allow :class:`os.PathLike` to be a base for Protocols.