| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
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.
There was a problem hiding this comment.
LGTM!
Sorry, something went wrong.
|
Woot! Thanks very much for your feedback on this, it's been most helpful in clarifying what's needed. |
Sorry, something went wrong.
|
I'm not sure if this is the correct place to put this feedback, but Path.scandir() returning an iterator of os.DirEntry directly, whose .path member is a str or bytes, rather than a Path is unexpected. 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. with path.scandir() as entries:
for entry in entries:
assert isinstance(entry.path, Path), "unexpected type" |
Sorry, something went wrong.
|
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 path / entry.name (edit: or pathlib.Path(entry)). |
Sorry, something went wrong.
|
Sorry, something went wrong.
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()`.
| Back | FazBrowse Home | New Git URL |
Add pathlib.Path.scandir() as a trivial wrapper of os.scandir().
In a future PR, I will rework pathlib._abc.PathBase.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.
📚 Documentation preview 📚: https://cpython-previews--126060.org.readthedocs.build/