New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make os.DirEntry exist #71225
Comments
The docs claim that os.DirEntry exists (https://docs.python.org/3/library/os.html#os.DirEntry) but it actually does not (it is internal to the posix module). Should probably actually make os.DirEntry exist (but continue to not document the constructor). |
New changeset b841972ed0bd by Brett Cannon in branch 'default': |
Thanks for the patch, Jelle! |
It would be nice if there was a supported way to create a DirEntry object from a path. If you don't want to document the constructor perhaps expose some helper function or class method (i.e. from_path)? |
Exposing a class method to construct one is no different than exposing the constructor, so it's still not desired to have. What is the specific need you have for creating a DirEntry instance on its own? |
It makes it much easier to write functions that can work with either a DirEntry object or a plain path. |
Brendan Moloney added the comment:
It's a deliberate choice to not expose the constructor. You should not Maybe the DirEntry doc must be more explicit on that point? Please use pathlib instead. pathlib objects don't cache os.stat() result, |
New changeset a95d98086621 by Ned Deily in branch 'default': |
The pathlib Path class is different enough from the DirEntry class that it doesn't really help my goal of allowing a function to work with either a DirEntry or a plain (str) path. These functions are going to be working with DirEntry objects generated by scandir 99% of the time so that we can leverage the improved performance, but I want to allow users to pass in plain paths as well. If the stdlib doesn't allow me to create my own DirEntry object from a plain path I will probably end up creating some sort of FakeDirEntry class that mimics a DirEntry, and that seems a bit silly and not a great use of time and effort. If the constructor currently "requires low-level data coming from |
If all you want is to extract the path representation from an os.DirEntry instance and continue to work with strings/bytes then you can use os.fspath() which is new in Python 3.6 to get the representation: https://docs.python.org/3.6/library/os.html#os.fspath . |
The functions were all written around DirEntry objects since that is what they will be processing 99% of the time and I want to do that as efficiently as possible. Converting a DirEntry object into a str representation doesn't help me with my use case at all. I want to be able to do it the other way around: str -> DirEntry |
Brendan Moloney: Please open a thread on the python-ideas mailing list to discuss your idea. Please don't start discussing on a *closed* issue: since an issue is closed, it's hidden from the main bug tracker and so only very few people see it. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: