File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222"""
2323
2424#'
25-
25+ import abc
2626import sys , errno
2727import stat as st
2828
@@ -1125,3 +1125,18 @@ def fspath(path):
11251125
11261126 raise TypeError ("expected str, bytes or os.PathLike object, not "
11271127 + path_type .__name__ )
1128+
1129+ class PathLike (abc .ABC ):
1130+ """
1131+ Abstract base class for implementing the file system path protocol.
1132+ """
1133+ @abc .abstractmethod
1134+ def __fspath__ (self ):
1135+ """
1136+ Return the file system path representation of the object.
1137+ """
1138+ raise NotImplementedError
1139+
1140+ @classmethod
1141+ def __subclasshook__ (cls , subclass ):
1142+ return hasattr (subclass , '__fspath__' )
Original file line number Diff line number Diff line change @@ -3127,6 +3127,8 @@ def __fspath__(self):
31273127 return '#feelthegil'
31283128
31293129 self .assertEqual ('#feelthegil' , os .fspath (PathLike ()))
3130+ self .assertTrue (issubclass (PathLike , os .PathLike ))
3131+ self .assertTrue (isinstance (PathLike (), os .PathLike ))
31303132
31313133 def test_garbage_in_exception_out (self ):
31323134 vapor = type ('blah' , (), {})
You can’t perform that action at this time.
0 commit comments