GH-70303: Emit FutureWarning when pathlib glob pattern ends with ** (GH-105413)

In a future Python release, patterns with this ending will match both files
and directories. Users may add a trailing slash to remove the warning.
This commit is contained in:
Barney Gale 2023-08-05 00:12:12 +01:00 committed by GitHub
parent 2c25bd82f4
commit ec0a0d2bd9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 3 deletions

View file

@ -1903,11 +1903,11 @@ class PathTest(unittest.TestCase):
"dirC/dirD", "dirC/dirD/fileD"])
_check(p.rglob("file*"), ["dirC/fileC", "dirC/dirD/fileD"])
_check(p.rglob("**/file*"), ["dirC/fileC", "dirC/dirD/fileD"])
_check(p.rglob("dir*/**"), ["dirC/dirD"])
_check(p.rglob("dir*/**/"), ["dirC/dirD"])
_check(p.rglob("*/*"), ["dirC/dirD/fileD"])
_check(p.rglob("*/"), ["dirC/dirD"])
_check(p.rglob(""), ["dirC", "dirC/dirD"])
_check(p.rglob("**"), ["dirC", "dirC/dirD"])
_check(p.rglob("**/"), ["dirC", "dirC/dirD"])
# gh-91616, a re module regression
_check(p.rglob("*.txt"), ["dirC/novel.txt"])
_check(p.rglob("*.*"), ["dirC/novel.txt"])
@ -2057,7 +2057,20 @@ class PathTest(unittest.TestCase):
path.mkdir(parents=True)
with set_recursion_limit(recursion_limit):
list(base.glob('**'))
list(base.glob('**/'))
def test_glob_recursive_no_trailing_slash(self):
P = self.cls
p = P(BASE)
with self.assertWarns(FutureWarning):
p.glob('**')
with self.assertWarns(FutureWarning):
p.glob('*/**')
with self.assertWarns(FutureWarning):
p.rglob('**')
with self.assertWarns(FutureWarning):
p.rglob('*/**')
def test_readlink(self):
if not self.can_symlink: