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

it can now be used as a base class in other protocols
This commit is contained in:
Stephen Morton 2024-11-12 09:54:13 -08:00 committed by GitHub
parent 73cf069099
commit a83472f49b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 0 deletions

View 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

View File

@ -1944,6 +1944,7 @@ _PROTO_ALLOWLIST = {
'Reversible', 'Buffer',
],
'contextlib': ['AbstractContextManager', 'AbstractAsyncContextManager'],
'os': ['PathLike'],
}

View File

@ -0,0 +1 @@
Allow :class:`os.PathLike` to be a base for Protocols.