Skip to content

GH-113528: Deoptimise pathlib._abc.PurePathBase.parts #113883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Lib/pathlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
8 changes: 4 additions & 4 deletions Lib/pathlib/_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down