GH-129835: Yield path with trailing slash from ReadablePath.glob('') (#129836)

In the private pathlib ABCs, make `ReadablePath.glob('')` yield a path with
a trailing slash (if it yields anything at all). As a result, `glob()`
works similarly to `joinpath()` when given a non-magic pattern.

In the globbing implementation, we preemptively add trailing slashes to
intermediate paths if there are pattern parts remaining; this removes the
need to check for existing trailing slashes (in the removed `add_slash()`
method) at subsequent steps.
This commit is contained in:
Barney Gale 2025-02-08 06:47:09 +00:00 committed by GitHub
parent 6c67904e79
commit 707d066193
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 15 additions and 30 deletions

View file

@ -959,7 +959,7 @@ class Path(WritablePath, ReadablePath, PurePath):
globber = _StringGlobber(self.parser.sep, case_sensitive, case_pedantic, recursive)
select = globber.selector(parts[::-1])
root = str(self)
paths = select(root)
paths = select(self.parser.join(root, ''))
# Normalize results
if root == '.':