Skip to content

Commit 468199e

Browse files
tungolpicnixz
authored andcommitted
pythongh-126705: Make os.PathLike more like a protocol (python#126706)
it can now be used as a base class in other protocols
1 parent 7b4adfe commit 468199e

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

Lib/test/test_typing.py

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import inspect
99
import itertools
1010
import operator
11+
import os
1112
import pickle
1213
import re
1314
import sys
@@ -4252,6 +4253,9 @@ def test_builtin_protocol_allowlist(self):
42524253
class CustomProtocol(TestCase, Protocol):
42534254
pass
42544255

4256+
class CustomPathLikeProtocol(os.PathLike, Protocol):
4257+
pass
4258+
42554259
class CustomContextManager(typing.ContextManager, Protocol):
42564260
pass
42574261

Lib/typing.py

+1
Original file line numberDiff line numberDiff line change
@@ -1944,6 +1944,7 @@ def _allow_reckless_class_checks(depth=2):
19441944
'Reversible', 'Buffer',
19451945
],
19461946
'contextlib': ['AbstractContextManager', 'AbstractAsyncContextManager'],
1947+
'os': ['PathLike'],
19471948
}
19481949

19491950

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow :class:`os.PathLike` to be a base for Protocols.

0 commit comments

Comments
 (0)