Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 59d06b9

Browse filesBrowse files
bharelilevkivskyi
authored andcommitted
[3.7] bpo-38878: Fix os.PathLike __subclasshook__ (GH-17336) (GH-17685)
https://bugs.python.org/issue38878
1 parent 0ffc900 commit 59d06b9
Copy full SHA for 59d06b9

3 files changed

+15-1Lines changed: 15 additions & 1 deletion

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Lib/os.py‎

Copy file name to clipboardExpand all lines: Lib/os.py
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import sys
2727
import stat as st
2828

29+
from _collections_abc import _check_methods
30+
2931
_names = sys.builtin_module_names
3032

3133
# Note: more names are added to __all__ later.
@@ -1076,4 +1078,6 @@ def __fspath__(self):
10761078

10771079
@classmethod
10781080
def __subclasshook__(cls, subclass):
1079-
return hasattr(subclass, '__fspath__')
1081+
if cls is PathLike:
1082+
return _check_methods(subclass, '__fspath__')
1083+
return NotImplemented
Collapse file

‎Lib/test/test_os.py‎

Copy file name to clipboardExpand all lines: Lib/test/test_os.py
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3745,6 +3745,14 @@ def test_bad_pathlike(self):
37453745
self.assertRaises(ZeroDivisionError, self.fspath,
37463746
FakePath(ZeroDivisionError()))
37473747

3748+
def test_pathlike_subclasshook(self):
3749+
# bpo-38878: subclasshook causes subclass checks
3750+
# true on abstract implementation.
3751+
class A(os.PathLike):
3752+
pass
3753+
self.assertFalse(issubclass(FakePath, A))
3754+
self.assertTrue(issubclass(FakePath, os.PathLike))
3755+
37483756

37493757
class TimesTests(unittest.TestCase):
37503758
def test_times(self):
Collapse file
+2Lines changed: 2 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed __subclasshook__ of :class:`os.PathLike` to return a correct result
2+
upon inheritence. Patch by Bar Harel.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.