mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
GH-128520: pathlib ABCs: reject empty pattern in ReadablePath.glob() (#127343)
For compatibility with `Path.glob()`, raise `ValueError` if an empty pattern is given to `ReadablePath.glob()`.
This commit is contained in:
parent
a04c0a9658
commit
fbfb0e1f6e
2 changed files with 4 additions and 0 deletions
|
|
@ -287,6 +287,8 @@ def glob(self, pattern, *, recurse_symlinks=True):
|
|||
anchor, parts = _explode_path(pattern)
|
||||
if anchor:
|
||||
raise NotImplementedError("Non-relative patterns are unsupported")
|
||||
elif not parts:
|
||||
raise ValueError(f"Unacceptable pattern: {pattern!r}")
|
||||
elif not recurse_symlinks:
|
||||
raise NotImplementedError("recurse_symlinks=False is unsupported")
|
||||
case_sensitive = self.parser.normcase('Aa') == 'Aa'
|
||||
|
|
|
|||
|
|
@ -127,6 +127,8 @@ def check(pattern, expected):
|
|||
check("**/file*",
|
||||
["fileA", "dirA/linkC/fileB", "dirB/fileB", "dirC/fileC", "dirC/dirD/fileD",
|
||||
"linkB/fileB"])
|
||||
with self.assertRaisesRegex(ValueError, 'Unacceptable pattern'):
|
||||
list(p.glob(''))
|
||||
|
||||
def test_walk_top_down(self):
|
||||
it = self.root.walk()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue