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

@ -1069,6 +1069,11 @@ class Path(PurePath):
pattern_parts.append('')
if pattern_parts[-1] == '**':
# GH-70303: '**' only matches directories. Add trailing slash.
warnings.warn(
"Pattern ending '**' will match files and directories in a "
"future Python release. Add a trailing slash to match only "
"directories and remove this warning.",
FutureWarning, 3)
pattern_parts.append('')
if case_sensitive is None: