Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1943,6 +1943,7 @@ def _allow_reckless_class_checks(depth=2):
'Hashable', 'Sized', 'Container', 'Collection', '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.
Loading