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 calling Path.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 the stat_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
Feature or enhancement
I propose we add a new
Path.statusattribute that stores anos.DirEntryobject in paths yielded fromPath.iterdir(), or a pathlib-specific type with a similar interface in other paths.This would:
os.DirEntryafter callingPath.iterdir(), which is useful for efficiently determining files' types and often doesn't involve a system call.S_ISREG(st.st_mode)and other holy incantations.PathBase.stat()and thestat_resultinterface, which is too low-level and local filesystem-specificSee discussion: https://discuss.python.org/t/is-there-a-pathlib-equivalent-of-os-scandir/46626
Linked PRs
pathlib.Path.dir_entryattribute #125419pathlib.Path.copy(): get common metadata keys only once #125990pathlib.Path.scandir()method #126060scandir()to speed upglob()#126261scandir()to speed upwalk()#126262scandir()to speed upcopy()#126263pathlib.Path.scandir()method #127377pathlib.Path.infoattribute #127730pathlib.Path.copy()implementation alongsidePath.info#129856pathlib.Path.info#129897pathlib.Pathmethod to write metadata #130238path.info.exists()when globbing #130422pathlib.Path.copy()andmove()#130424