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

@ -460,7 +460,7 @@ class ReadablePath(JoinablePath):
recursive = True if recurse_symlinks else _no_recurse_symlinks
globber = _PathGlobber(self.parser.sep, case_sensitive, case_pedantic, recursive)
select = globber.selector(parts)
return select(self)
return select(self.joinpath(''))
def rglob(self, pattern, *, case_sensitive=None, recurse_symlinks=True):
"""Recursively yield all existing files (of any kind, including