Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Merge branch 'main' into gh-101362-exclude-anchor-from-parts
  • Loading branch information
barneygale committed Mar 10, 2023
commit ac26f8474c54e09b7e9c85f7afb7be066e1286af
8 changes: 6 additions & 2 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,12 @@ def _from_parsed_parts(cls, drv, root, tail):

@classmethod
def _format_parsed_parts(cls, drv, root, tail):
tail = cls._flavour.sep.join(tail)
sep = cls._flavour.sep
tail = sep.join(tail)
if drv or root:
return f'{drv}{root}{tail}'
elif cls._flavour.splitdrive(tail)[0]:
return f'.{sep}{tail}'
else:
return tail

Expand Down Expand Up @@ -1188,7 +1191,8 @@ def expanduser(self):
homedir = self._flavour.expanduser(self._tail[0])
if homedir[:1] == "~":
raise RuntimeError("Could not determine home directory.")
return self._from_parts([homedir] + self._tail[1:])
drv, root, tail = self._parse_parts((homedir,))
return self._from_parsed_parts(drv, root, tail + self._tail[1:])

return self

Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_pathlib.py
Comment thread
barneygale marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ def test_parse_parts(self):
# the second path is relative.
check(['c:/a/b', 'c:x/y'], ('c:', '\\', ['a', 'b', 'x', 'y']))
check(['c:/a/b', 'c:/x/y'], ('c:', '\\', ['x', 'y']))
# Paths to files with NTFS alternate data streams
check(['./c:s'], ('', '', ['c:s']))
check(['cc:s'], ('', '', ['cc:s']))
check(['C:c:s'], ('C:', '', ['c:s']))
check(['C:/c:s'], ('C:', '\\', ['c:s']))
check(['D:a', './c:b'], ('D:', '', ['a', 'c:b']))
check(['D:/a', './c:b'], ('D:', '\\', ['a', 'c:b']))


#
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.