-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-115060: Speed up pathlib.Path.glob()
by omitting initial stat()
#117831
Conversation
…stat()` Since 6258844, paths that might not exist can be fed into pathlib's globbing implementation, which will call `os.scandir()` / `os.lstat()` only when strictly necessary. This allows us to drop an initial `self.is_dir()` call, which saves a `stat()`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this was previously explicitly documented, should this have a versionchanged in the docs? Oh hmm, I guess this was just documented recently in #114036 by you, so it's probably fine... :-)
I also wonder if we can improve tests, e.g. it looks like the if not self.is_dir():
branch was not covered by tests
Misc/NEWS.d/next/Library/2024-04-13-01-45-15.gh-issue-115060.IxoM03.rst
Outdated
Show resolved
Hide resolved
Thanks! I think it's probably not important enough for |
…xoM03.rst Co-authored-by: Shantanu <[email protected]>
On reflection, I think this works best as a |
…stat()` (python#117831) Since 6258844, paths that might not exist can be fed into pathlib's globbing implementation, which will call `os.scandir()` / `os.lstat()` only when strictly necessary. This allows us to drop an initial `self.is_dir()` call, which saves a `stat()`. Co-authored-by: Shantanu <[email protected]>
Since 6258844, paths that might not exist can be fed into pathlib's globbing implementation, which will call
os.scandir()
/os.lstat()
only when strictly necessary. This allows us to drop an initialself.is_dir()
call, which saves astat()
.pathlib.Path.glob()
by removing redundant regex matching #115060📚 Documentation preview 📚: https://cpython-previews--117831.org.readthedocs.build/