Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a1326c8
GH-65238: Preserve trailing slash in pathlib
barneygale Nov 24, 2023
df1e115
Fix absolute() on bare DOS drive
barneygale Nov 24, 2023
61be2e3
Simplify diff
barneygale Nov 24, 2023
445364a
Reduce diff
barneygale Nov 24, 2023
6395815
Speed up _make_child_relpath()
barneygale Nov 24, 2023
435be1b
Ignore empty initialiser arguments for backwards compat
barneygale Nov 25, 2023
e577a67
Merge branch 'main' into keep-trailing-slash-wip3
barneygale Nov 25, 2023
d766d06
Simplify implementation
barneygale Dec 1, 2023
12cfb1a
Merge branch 'main' into keep-trailing-slash-wip3
barneygale Dec 2, 2023
2593ddb
Merge branch 'main' into keep-trailing-slash-wip3
barneygale Dec 3, 2023
b275078
Add tests
barneygale Dec 3, 2023
5d87cf4
Docstrings
barneygale Dec 4, 2023
af12c24
Docs
barneygale Dec 4, 2023
cae3774
Ensure has_trailing_sep is boolean
barneygale Dec 4, 2023
d4c87c6
Add tests for new methods/properties
barneygale Dec 4, 2023
1a77c8a
Fix WindowsPath('C:').absolute()
barneygale Dec 4, 2023
120beed
Merge branch 'main' into keep-trailing-slash-wip3
barneygale Dec 4, 2023
df79c49
Don't access `.parts` from `._glob()`
barneygale Dec 7, 2023
0f75804
Fix pickle roundtripping
barneygale Dec 7, 2023
eeb35ff
Undo changes to `parts`
barneygale Dec 7, 2023
153c4af
Merge branch 'main' into keep-trailing-slash-wip3
barneygale Dec 7, 2023
b852339
Simplify `_glob()` slightly
barneygale Dec 7, 2023
2b77a61
Fix possible scoping issue in `_glob()`
barneygale Dec 7, 2023
7b6766f
Formatting
barneygale Dec 8, 2023
f5c2265
Add test cases for preserving slash in absolute() and expanduser()
barneygale Dec 8, 2023
1126117
Add notes to `match()` and `glob()` docs
barneygale Dec 8, 2023
9c9b5ea
Merge branch 'main' into keep-trailing-slash-wip3
barneygale Dec 8, 2023
9539c60
Merge branch 'main' into keep-trailing-slash-wip3
barneygale Dec 11, 2023
14a9635
Merge branch 'main' into keep-trailing-slash-wip3
barneygale Dec 17, 2023
305381b
Undo pickling change
barneygale Dec 17, 2023
dfe7aae
Undo pickling changes.
barneygale Dec 18, 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
Undo changes to parts
  • Loading branch information
barneygale committed Dec 7, 2023
commit eeb35ffa0472ca09364141064656eb1f786ccc7c
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