-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
Expose os.DirEntry objects from pathlib #125413
Copy link
Copy link
Closed
Labels
performancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-pathlibtype-featureA feature request or enhancementA feature request or enhancement
Metadata
Metadata
Assignees
Labels
performancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-pathlibtype-featureA feature request or enhancementA feature request or enhancement
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