Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
GH-125413: Add pathlib.Path.info attribute#127730
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
barneygale commented Dec 7, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
When a path object is generated by `PathBase.iterdir()`, then its `_info` attribute now stores a `os.DirEntry`-like object that can be used to query the file type. This removes any need for a `_scandir()` method. Currently the `_info` attribute is private and only guaranteed to be populated in paths from `iterdir()`. Later on, I'm hoping to rename it to `info` and ensure that it's populated for all kinds of paths (this probably involves adding a `pathlib.FileInfo` class.) In the pathlib ABCs, `info` will replace `stat()` as the lowest-level abstract file status querying mechanism.
barneygale commented Dec 8, 2024
Steve - hopefully this helps address the issues you raised in #127377, but perhaps I'm only moving the problem around here. |
zooba commented Dec 9, 2024
I think this is just moving stuff around. It might end up being the right places, but let's see the Discourse discussion play out a bit first. |
_scandir() with _info_scandir() with _status_scandir() with _statuspathlib.Path.status attributebarneygale commented Dec 9, 2024
I've revised the PR to be a more complete implementation of what I described on the forum, mostly as a demonstration/proof-of-concept at this stage. |
barneygale commented Dec 17, 2024
Right, I think this is ready for review. Alyssa, sorry if this seems like deja-vu! |
pathlib.Path.status attributepathlib.Path.info attribute
encukou left a comment
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.
This looks great, thank you!
I do have a nitpick:
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Petr Viktorin <encukou@gmail.com>
barneygale commented Jan 14, 2025
Thank you Petr :) I'll wait another month until I merge, in case Alyssa or Steve have feedback |
barneygale commented Feb 4, 2025
I'll merge this on Friday if there's no further feedback. Cheers |
718ab66 into python:mainUh oh!
There was an error while loading. Please reload this page.
Add
pathlib.Path.infoattribute, which stores an object implementing thepathlib.types.PathInfoprotocol (also new). The object supports querying the file type and internally cachingos.stat()results. Path objects generated byPath.iterdir()are initialised with status information fromos.DirEntryobjects, which is gleaned from scanning the parent directory.The
PathInfoprotocol has four methods:exists(),is_dir(),is_file()andis_symlink().os.DirEntryobjects from pathlib #125413