diff --git a/Lib/pathlib/types.py b/Lib/pathlib/types.py index 85dd9e5b2d6b9a..cd8b2a983379d0 100644 --- a/Lib/pathlib/types.py +++ b/Lib/pathlib/types.py @@ -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' diff --git a/Lib/test/test_pathlib/test_read.py b/Lib/test/test_pathlib/test_read.py index 938d3a1e987128..1a14649fafee80 100644 --- a/Lib/test/test_pathlib/test_read.py +++ b/Lib/test/test_pathlib/test_read.py @@ -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()