diff --git a/Lib/pathlib/__init__.py b/Lib/pathlib/__init__.py index 749c68d2999bdc..26e14b3f7b2005 100644 --- a/Lib/pathlib/__init__.py +++ b/Lib/pathlib/__init__.py @@ -195,6 +195,15 @@ def __ge__(self, other): return NotImplemented return self._parts_normcase >= other._parts_normcase + @property + def parts(self): + """An object providing sequence-like access to the + components in the filesystem path.""" + if self.drive or self.root: + return (self.drive + self.root,) + tuple(self._tail) + else: + return tuple(self._tail) + @property def parent(self): """The logical parent of the path.""" diff --git a/Lib/pathlib/_abc.py b/Lib/pathlib/_abc.py index caa84fc40559f7..c16beca71aa7c7 100644 --- a/Lib/pathlib/_abc.py +++ b/Lib/pathlib/_abc.py @@ -381,10 +381,10 @@ def is_relative_to(self, other): def parts(self): """An object providing sequence-like access to the components in the filesystem path.""" - if self.drive or self.root: - return (self.drive + self.root,) + tuple(self._tail) - else: - return tuple(self._tail) + anchor, parts = self._stack + if anchor: + parts.append(anchor) + return tuple(reversed(parts)) def joinpath(self, *pathsegments): """Combine this path with one or several arguments, and return a