Skip to content

Commit

Permalink
gh-126705: Make os.PathLike more like a protocol (#126706)
Browse files Browse the repository at this point in the history
it can now be used as a base class in other protocols
  • Loading branch information
tungol authored Nov 12, 2024
1 parent 73cf069 commit a83472f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import inspect
import itertools
import operator
import os
import pickle
import re
import sys
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1944,6 +1944,7 @@ def _allow_reckless_class_checks(depth=2):
'Reversible', 'Buffer',
],
'contextlib': ['AbstractContextManager', 'AbstractAsyncContextManager'],
'os': ['PathLike'],
}


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

0 comments on commit a83472f

Please sign in to comment.