import sys
import stat as st
+from _collections_abc import _check_methods
+
_names = sys.builtin_module_names
# Note: more names are added to __all__ later.
@classmethod
def __subclasshook__(cls, subclass):
- return hasattr(subclass, '__fspath__')
+ if cls is PathLike:
+ return _check_methods(subclass, '__fspath__')
+ return NotImplemented
def __class_getitem__(cls, type):
return cls
self.assertRaises(ZeroDivisionError, self.fspath,
FakePath(ZeroDivisionError()))
+ def test_pathlike_subclasshook(self):
+ # bpo-38878: subclasshook causes subclass checks
+ # true on abstract implementation.
+ class A(os.PathLike):
+ pass
+ self.assertFalse(issubclass(FakePath, A))
+ self.assertTrue(issubclass(FakePath, os.PathLike))
+
def test_pathlike_class_getitem(self):
self.assertIs(os.PathLike[bytes], os.PathLike)