Skip to content

Commit

Permalink
Undo changes to parts
Browse files Browse the repository at this point in the history
  • Loading branch information
barneygale committed Dec 7, 2023
1 parent 0f75804 commit eeb35ff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
8 changes: 3 additions & 5 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,10 @@ def is_relative_to(self, other, /, *_deprecated):
def parts(self):
"""An object providing sequence-like access to the
components in the filesystem path."""
result = tuple(self._tail)
if self.drive or self.root:
result = (self.drive + self.root,) + result
if self.has_trailing_sep:
result = result + ('',)
return result
return (self.drive + self.root,) + tuple(self._tail)
else:
return tuple(self._tail)

def joinpath(self, *pathsegments):
"""Combine this path with one or several arguments, and return a
Expand Down
16 changes: 4 additions & 12 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ def test_drive_root_parts_common(self):
# Unanchored parts.
check((), '', '', ())
check(('a',), '', '', ('a',))
check(('a/',), '', '', ('a', ''))
check(('a/',), '', '', ('a',))
check(('a', 'b'), '', '', ('a', 'b'))
# Expansion.
check(('a/b',), '', '', ('a', 'b'))
check(('a/b/',), '', '', ('a', 'b', ''))
check(('a/b/',), '', '', ('a', 'b'))
check(('a', 'b/c', 'd'), '', '', ('a', 'b', 'c', 'd'))
# Collapsing and stripping excess slashes.
check(('a', 'b//c', 'd'), '', '', ('a', 'b', 'c', 'd'))
Expand All @@ -193,7 +193,7 @@ def test_drive_root_parts_common(self):
check(('.',), '', '', ())
check(('.', '.', 'b'), '', '', ('b',))
check(('a', '.', 'b'), '', '', ('a', 'b'))
check(('a', '.', '.'), '', '', ('a', ''))
check(('a', '.', '.'), '', '', ('a',))
# The first part is anchored.
check(('/a/b',), '', sep, (sep, 'a', 'b'))
check(('/a', 'b'), '', sep, (sep, 'a', 'b'))
Expand Down Expand Up @@ -385,10 +385,6 @@ def test_parts_common(self):
p = P('/a/b')
parts = p.parts
self.assertEqual(parts, (sep, 'a', 'b'))
# When the path has a trailing separator, an additional empty part is present.
p = P('a/b/')
parts = p.parts
self.assertEqual(parts, ('a', 'b', ''))

def test_equivalences(self):
for k, tuples in self.equivalences.items():
Expand Down Expand Up @@ -1085,7 +1081,7 @@ def test_drive_root_parts(self):
# UNC paths.
check(('a', '//b/c', 'd'), '\\\\b\\c', '\\', ('\\\\b\\c\\', 'd'))
# Collapsing and stripping excess slashes.
check(('a', 'Z://b//c/', 'd/'), 'Z:', '\\', ('Z:\\', 'b', 'c', 'd', ''))
check(('a', 'Z://b//c/', 'd/'), 'Z:', '\\', ('Z:\\', 'b', 'c', 'd'))
# UNC paths.
check(('a', '//b/c//', 'd'), '\\\\b\\c', '\\', ('\\\\b\\c\\', 'd'))
# Extended paths.
Expand Down Expand Up @@ -1240,10 +1236,6 @@ def test_parts(self):
p = P('//a/b/c/d')
parts = p.parts
self.assertEqual(parts, ('\\\\a\\b\\', 'c', 'd'))
# Trailing sep
p = P('c:/a/b/')
parts = p.parts
self.assertEqual(parts, ('c:\\', 'a', 'b', ''))

def test_parent(self):
# Anchored
Expand Down

0 comments on commit eeb35ff

Please sign in to comment.