mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
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:
parent
681e9e85a2
commit
6313cdde58
6 changed files with 115 additions and 72 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue