KEMBAR78
GH-70303: Make `pathlib.Path.glob('**')` return both files and directories by barneygale · Pull Request #114684 · python/cpython · GitHub
Skip to content

Conversation

@barneygale
Copy link
Contributor

@barneygale barneygale commented Jan 28, 2024

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 PR 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.


📚 Documentation preview 📚: https://cpython-previews--114684.org.readthedocs.build/

…directories

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.
Copy link
Member

@jaraco jaraco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. Love it.

@zooba
Copy link
Member

zooba commented Jan 29, 2024

Agree we can fix this, but let's make sure it's clearly mentioned in What's New and Porting Notes (also on the What's New page) for 3.13. If that's already been done, consider me +1

@barneygale barneygale merged commit fda7445 into python:main Jan 30, 2024
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
…directories (python#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants