summaryrefslogtreecommitdiffstats
path: root/Lib/os.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2016-06-04 19:49:35 (GMT)
committerEthan Furman <ethan@stoneleaf.us>2016-06-04 19:49:35 (GMT)
commit958b3e40581af8577c7213992d502786f87ec173 (patch)
tree56c5f576f464209721f45478a2fbca42e1ec2e87 /Lib/os.py
parent8bc9378c98e0dab872e41c59e1cb00c0fab1a146 (diff)
downloadcpython-958b3e40581af8577c7213992d502786f87ec173.zip
cpython-958b3e40581af8577c7213992d502786f87ec173.tar.gz
cpython-958b3e40581af8577c7213992d502786f87ec173.tar.bz2
issue27186: add PathLike ABC
Diffstat (limited to 'Lib/os.py')
-rw-r--r--Lib/os.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/Lib/os.py b/Lib/os.py
index 0131ed8..e7d089e 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -22,7 +22,7 @@ and opendir), and leave all pathname manipulation to os.path
"""
#'
-
+import abc
import sys, errno
import stat as st
@@ -1125,3 +1125,18 @@ if not _exists('fspath'):
raise TypeError("expected str, bytes or os.PathLike object, not "
+ path_type.__name__)
+
+class PathLike(abc.ABC):
+ """
+ Abstract base class for implementing the file system path protocol.
+ """
+ @abc.abstractmethod
+ def __fspath__(self):
+ """
+ Return the file system path representation of the object.
+ """
+ raise NotImplementedError
+
+ @classmethod
+ def __subclasshook__(cls, subclass):
+ return hasattr(subclass, '__fspath__')