https://github.com/python/cpython/commit/a83472f49b958c55befd82c871be26afbf500306
commit: a83472f49b958c55befd82c871be26afbf500306
branch: main
author: Stephen Morton <[email protected]>
committer: AlexWaygood <[email protected]>
date: 2024-11-12T17:54:13Z
summary:

gh-126705: Make os.PathLike more like a protocol (#126706)

it can now be used as a base class in other protocols

files:
A Misc/NEWS.d/next/Library/2024-11-11-14-52-21.gh-issue-126705.0W7jFW.rst
M Lib/test/test_typing.py
M Lib/typing.py

diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 244ce1e5da9bd2..aa42beca5f9256 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -8,6 +8,7 @@
 import inspect
 import itertools
 import operator
+import os
 import pickle
 import re
 import sys
@@ -4252,6 +4253,9 @@ def test_builtin_protocol_allowlist(self):
             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 8e6381033fd28e..938e52922aee03 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -1944,6 +1944,7 @@ def _allow_reckless_class_checks(depth=2):
         '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 00000000000000..f49c9c765d778f
--- /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.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to