Closed
Description
Feature or enhancement
I propose we add a new Path.status
attribute that stores an os.DirEntry
object in paths yielded from Path.iterdir()
, or a pathlib-specific type with a similar interface in other paths.
This would:
- Allow users to access to the cached
os.DirEntry
after callingPath.iterdir()
, which is useful for efficiently determining files' types and often doesn't involve a system call. - Allow users to switch on the type of any path without repeatedly making system calls, or having to resort to
S_ISREG(st.st_mode)
and other holy incantations. - In the pathlib ABCs, allows us to entirely banish
PathBase.stat()
and thestat_result
interface, which is too low-level and local filesystem-specific
See discussion: https://discuss.python.org/t/is-there-a-pathlib-equivalent-of-os-scandir/46626
Linked PRs
- GH-125413: Add
pathlib.Path.dir_entry
attribute #125419 - GH-125413:
pathlib.Path.copy()
: get common metadata keys only once #125990 - GH-125413: Add
pathlib.Path.scandir()
method #126060 - GH-125413: pathlib ABCs: use
scandir()
to speed upglob()
#126261 - GH-125413: pathlib ABCs: use
scandir()
to speed upwalk()
#126262 - GH-125413: pathlib: use
scandir()
to speed upcopy()
#126263 - GH-125413: Revert addition of
pathlib.Path.scandir()
method #127377 - GH-125413: Add
pathlib.Path.info
attribute #127730 - GH-125413: Move
pathlib.Path.copy()
implementation alongsidePath.info
#129856 - GH-125413: Add private metadata methods to
pathlib.Path.info
#129897 - GH-125413: Add private
pathlib.Path
method to write metadata #130238 - GH-125413: pathlib ABCs: use caching
path.info.exists()
when globbing #130422 - GH-125413: Fix stale metadata from
pathlib.Path.copy()
andmove()
#130424