diff options
author | Barney Gale <barney.gale@gmail.com> | 2024-01-30 19:52:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-30 19:52:53 (GMT) |
commit | fda7445ca50b892955fc31bd72a3615fef1d70c6 (patch) | |
tree | 37347a7623b016df6a24d390d0b4c7d6399baa9f /Lib/pathlib | |
parent | 6de8aa31f39b3d8dbfba132e6649724eb07b8348 (diff) | |
download | cpython-fda7445ca50b892955fc31bd72a3615fef1d70c6.zip cpython-fda7445ca50b892955fc31bd72a3615fef1d70c6.tar.gz cpython-fda7445ca50b892955fc31bd72a3615fef1d70c6.tar.bz2 |
GH-70303: Make `pathlib.Path.glob('**')` return both files and directories (#114684)
Return files and directories from `pathlib.Path.glob()` if the pattern ends
with `**`. This is more compatible with `PurePath.full_match()` and with
other glob implementations such as bash and `glob.glob()`. Users can add a
trailing slash to match only directories.
In my previous patch I added a `FutureWarning` with the intention of fixing
this in Python 3.15. Upon further reflection I think this was an
unnecessarily cautious remedy to a clear bug.
Diffstat (limited to 'Lib/pathlib')
-rw-r--r-- | Lib/pathlib/__init__.py | 8 |
1 files changed, 0 insertions, 8 deletions
diff --git a/Lib/pathlib/__init__.py b/Lib/pathlib/__init__.py index cc159ed..4447f98 100644 --- a/Lib/pathlib/__init__.py +++ b/Lib/pathlib/__init__.py @@ -465,14 +465,6 @@ class PurePath(_abc.PurePathBase): elif pattern[-1] in (self.pathmod.sep, self.pathmod.altsep): # GH-65238: pathlib doesn't preserve trailing slash. Add it back. parts.append('') - elif 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, 4) - parts.append('') parts.reverse() return parts |