https://github.com/python/cpython/commit/fbfb0e1f6efae7055f7420c999ad6256e10d6b62
commit: fbfb0e1f6efae7055f7420c999ad6256e10d6b62
branch: main
author: Barney Gale <[email protected]>
committer: barneygale <[email protected]>
date: 2025-03-24T15:12:29Z
summary:
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()`.
files:
M Lib/pathlib/types.py
M Lib/test/test_pathlib/test_read.py
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()
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]