We should be able to call os.scandir() from pathlib.Path.iterdir() and construct results based on the os.DirEntry.path string.
Currently we call os.listdir() and _make_child_relpath(), which returns a fully parsed/normalized string; particularly, it sets _str, _drv, _root and _tail_cached.
It's probably not worth the expense of setting _drv, _root and _tail_cached - they're only useful when paths are subsequently deconstructed with PurePath methods, which isn't particularly common. It is worth setting _str, and happily os.DirEntry.path provides a string that's very nearly normalized to pathlib's standards.
Also discussed here: https://discuss.python.org/t/is-there-a-pathlib-equivalent-of-os-scandir/46626/21
Linked PRs
We should be able to call
os.scandir()frompathlib.Path.iterdir()and construct results based on theos.DirEntry.pathstring.Currently we call
os.listdir()and_make_child_relpath(), which returns a fully parsed/normalized string; particularly, it sets_str,_drv,_rootand_tail_cached.It's probably not worth the expense of setting
_drv,_rootand_tail_cached- they're only useful when paths are subsequently deconstructed withPurePathmethods, which isn't particularly common. It is worth setting_str, and happilyos.DirEntry.pathprovides a string that's very nearly normalized to pathlib's standards.Also discussed here: https://discuss.python.org/t/is-there-a-pathlib-equivalent-of-os-scandir/46626/21
Linked PRs
pathlib.Path.iterdir()by usingos.scandir()#117728