GH-79634: Accept path-like objects as pathlib glob patterns. (#114017)

Allow `os.PathLike` objects to be passed as patterns to `pathlib.Path.glob()` and `rglob()`. (It's already possible to use them in `PurePath.match()`)

While we're in the area:

- Allow empty glob patterns in `PathBase` (but not `Path`)
- Speed up globbing in `PathBase` by generating paths with trailing slashes only as a final step, rather than for every intermediate directory.
- Simplify and speed up handling of rare patterns involving both `**` and `..` segments.
This commit is contained in:
Barney Gale 2024-01-20 02:10:25 +00:00 committed by GitHub
parent 681e9e85a2
commit 6313cdde58
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 115 additions and 72 deletions

View file

@ -1045,9 +1045,12 @@ class DummyPathTest(DummyPurePathTest):
_check(p.glob("*/"), ["dirA/", "dirB/", "dirC/", "dirE/", "linkB/"])
def test_glob_empty_pattern(self):
p = self.cls('')
with self.assertRaisesRegex(ValueError, 'Unacceptable pattern'):
list(p.glob(''))
def _check(glob, expected):
self.assertEqual(set(glob), { P(self.base, q) for q in expected })
P = self.cls
p = P(self.base)
_check(p.glob(""), [""])
_check(p.glob("."), ["."])
def test_glob_case_sensitive(self):
P = self.cls