Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a6fdd0e
Add `pathlib.PurePath.makepath()`; unify path object construction
barneygale Nov 20, 2022
b061747
Fix reST role name.
barneygale Dec 24, 2022
99eb8b1
Move call to `os.getcwd()` back into `Path.cwd()`
barneygale Dec 24, 2022
4759d01
Merge branch 'main' into gh-100479-add-makepath
barneygale Jan 5, 2023
ef6f4c3
Merge branch 'main' into gh-100479-add-makepath
barneygale Apr 3, 2023
595b8ae
Add news blurb.
barneygale Apr 3, 2023
dcfe70a
Merge branch 'main' into gh-100479-add-makepath
barneygale Apr 9, 2023
117fe4b
Add whatsnew entry
barneygale Apr 10, 2023
e75dedc
Merge branch 'main' into gh-100479-add-makepath
barneygale Apr 12, 2023
5a6bd3f
Merge branch 'main' into gh-100479-add-makepath
barneygale Apr 13, 2023
f2f1048
other --> pathsegments
barneygale Apr 24, 2023
3c172fb
Update Lib/pathlib.py
barneygale Apr 24, 2023
4637109
joinpath(*args) --> joinpath(*pathsegments)
barneygale Apr 24, 2023
ae48454
Restore _PathParents
barneygale Apr 25, 2023
e7a8fe3
Add note to `parents` about potential reference cycle.
barneygale Apr 25, 2023
7f12faa
Replace `makepath()` method with `template` initialiser argument.
barneygale Apr 25, 2023
687c764
Apply suggestions from code review
barneygale Apr 25, 2023
d7e326a
Fix docs for other classes.
barneygale Apr 25, 2023
a65d499
Pass template to `super()` to support diamond inheritance.
barneygale Apr 26, 2023
d4b15d7
Fixed missed `template` argument to super().
barneygale Apr 26, 2023
958b183
template --> blueprint
barneygale Apr 27, 2023
1e10188
Merge branch 'main' into gh-100479-add-makepath
barneygale May 2, 2023
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
Prev Previous commit
Next Next commit
Merge branch 'main' into gh-100479-add-makepath
  • Loading branch information
barneygale committed Apr 9, 2023
commit dcfe70a40226ac58d396fb80387348268335448a
22 changes: 11 additions & 11 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,13 @@ def _load_parts(self):
self._root = root
self._tail_cached = tail

def _from_parsed_parts(self, drv, root, parts):
path_str = self._format_parsed_parts(drv, root, parts)
def _from_parsed_parts(self, drv, root, tail):
path_str = self._format_parsed_parts(drv, root, tail)
path = self.makepath(path_str)
path._str = path_str or '.'
path._drv = drv
path._root = root
path._parts_cached = parts
path._tail_cached = tail
return path

@classmethod
Expand Down Expand Up @@ -552,7 +552,7 @@ def relative_to(self, other, /, *_deprecated, walk_up=False):
raise ValueError(f"{str(self)!r} and {str(other)!r} have different anchors")
if step and not walk_up:
raise ValueError(f"{str(self)!r} is not in the subpath of {str(other)!r}")
parts = ('..',) * step + self.parts[len(path.parts):]
parts = ['..'] * step + self._tail[len(path._tail):]
return self.makepath(*parts)

def is_relative_to(self, other, /, *_deprecated):
Expand Down Expand Up @@ -608,8 +608,8 @@ def parent(self):
"""The logical parent of the path."""
drv = self.drive
root = self.root
parts = self._parts
if len(parts) == bool(drv or root):
tail = self._tail
if not tail:
return self
return self._from_parsed_parts(drv, root, tail[:-1])

Expand All @@ -618,10 +618,10 @@ def parents(self):
"""A tuple of this path's logical parents."""
drv = self.drive
root = self.root
parts = self._parts
tail = self._tail
return tuple(
self._from_parsed_parts(drv, root, parts[:idx])
for idx in reversed(range(bool(drv or root), len(parts))))
self._from_parsed_parts(drv, root, tail[:idx])
for idx in reversed(range(len(tail))))

def is_absolute(self):
"""True if the path is absolute (has both a root and, if applicable,
Expand Down Expand Up @@ -651,7 +651,7 @@ def match(self, path_pattern):
"""
Return True if this path matches the given pattern.
"""
pat = type(self)(path_pattern)
pat = self.makepath(path_pattern)
if not pat.parts:
raise ValueError("empty pattern")
pat_parts = pat._parts_normcase
Expand Down Expand Up @@ -726,7 +726,7 @@ def _make_child_relpath(self, name):
path_str = f'{path_str}{name}'
else:
path_str = name
path = type(self)(path_str)
path = self.makepath(path_str)
path._str = path_str
path._drv = self.drive
path._root = self.root
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.