Uh oh!
There was an error while loading. Please reload this page.
GH-125413: Add pathlib.Path.scandir() method - #126060
Conversation
Add `pathlib.Path.scandir()` as a trivial wrapper of `os.scandir()`. In the private `pathlib._abc.PathBase` class, we can rework the `iterdir()`, `glob()`, `walk()` and `copy()` methods to call `scandir()` and make use of cached directory entry information, and thereby improve performance. Because the `Path.copy()` method is provided by `PathBase`, this also speeds up traversal when copying local files and directories.
I'll save these for another PR.
barneygale
commented
Oct 30, 2024
Woot! Thanks very much for your feedback on this, it's been most helpful in clarifying what's needed. |
I'm not sure if this is the correct place to put this feedback, but At least on first glance, it's unexpected that a member named "path" on an object returned from a method of Path is not actually of type Path. withpath.scandir() asentries:
forentryinentries:
assertisinstance(entry.path, Path), "unexpected type" |
Would you care to open a topic on discuss.python.org? It's a good thought and worth bringing to wider attention I think. At the moment you can get a path object with |
Ferdi265
commented
Nov 20, 2024
|
Add `pathlib.Path.scandir()` as a trivial wrapper of `os.scandir()`. This will be used to implement several `PathBase` methods more efficiently, including methods that provide `Path.copy()`.
Add `pathlib.Path.scandir()` as a trivial wrapper of `os.scandir()`. This will be used to implement several `PathBase` methods more efficiently, including methods that provide `Path.copy()`.
Add
pathlib.Path.scandir()as a trivial wrapper ofos.scandir().In a future PR, I will rework
pathlib._abc.PathBase.glob(),walk()andcopy()methods to callscandir()and make use of cached directory entry information, and thereby improve performance. Because thePath.copy()method is provided byPathBase, this also speeds up traversal when copying local files and directories.os.DirEntryobjects from pathlib #125413📚 Documentation preview 📚: https://cpython-previews--126060.org.readthedocs.build/