]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-126705: Make os.PathLike more like a protocol (#126706)
authorStephen Morton <git@tungol.org>
Tue, 12 Nov 2024 17:54:13 +0000 (09:54 -0800)
committerGitHub <noreply@github.com>
Tue, 12 Nov 2024 17:54:13 +0000 (17:54 +0000)
it can now be used as a base class in other protocols

Lib/test/test_typing.py
Lib/typing.py
Misc/NEWS.d/next/Library/2024-11-11-14-52-21.gh-issue-126705.0W7jFW.rst [new file with mode: 0644]

index 244ce1e5da9bd28363cf752f306dec58b988bbba..aa42beca5f9256bad4428bcd779ff610eb2c6867 100644 (file)
@@ -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
 
index 8e6381033fd28e211d118768658979dfe42cebaf..938e52922aee0344f91273902cc52331cfd05925 100644 (file)
@@ -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 (file)
index 0000000..f49c9c7
--- /dev/null
@@ -0,0 +1 @@
+Allow :class:`os.PathLike` to be a base for Protocols.