summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Morton <git@tungol.org>2024-11-12 17:54:13 (GMT)
committerGitHub <noreply@github.com>2024-11-12 17:54:13 (GMT)
commita83472f49b958c55befd82c871be26afbf500306 (patch)
treee7e356f23d13a624a2b24e5a5858c89b09ac88d9
parent73cf0690997647c9801d9ebba43305a868d3b776 (diff)
downloadcpython-a83472f49b958c55befd82c871be26afbf500306.zip
cpython-a83472f49b958c55befd82c871be26afbf500306.tar.gz
cpython-a83472f49b958c55befd82c871be26afbf500306.tar.bz2
gh-126705: Make os.PathLike more like a protocol (#126706)
it can now be used as a base class in other protocols
-rw-r--r--Lib/test/test_typing.py4
-rw-r--r--Lib/typing.py1
-rw-r--r--Misc/NEWS.d/next/Library/2024-11-11-14-52-21.gh-issue-126705.0W7jFW.rst1
3 files changed, 6 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 244ce1e..aa42bec 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 8e63810..938e529 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 0000000..f49c9c7
--- /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.