<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Hi,<br>
<br>
I have been using the 'scandir' package (<a href="https://github.com/benhoyt/scandir" target="_blank">https://github.com/benhoyt/scandir</a>) for a while now to
<br>
speed up some directory tree processing code. Since Python 3.5 now includes 'os.scandir' in the
<br>
stdlib (<a href="https://www.python.org/dev/peps/pep-0471/" target="_blank">https://www.python.org/dev/peps/pep-0471/</a>) I decided to try to make my code work with
<br>
the built-in version if available.<br>
<br>
The first issue I hit was that the 'DirEntry' class was not actually being exposed
<br>
(<a href="http://bugs.python.org/issue27038" target="_blank">http://bugs.python.org/issue27038</a>). However in the discussion of that bug I noticed that the
<br>
constructor for the 'DirEntry' class was deliberately being left undocumented and that there
<br>
was no clear way to manually create a DirEntry object from a path. I brought up my objections
<br>
to this decision in the bug tracker and was asked to have the discussion over here on
<br>
python-ideas.<br>
<br>
I have a bunch of functions that operate on DirEntry objects, typically doing some sort of filtering
<br>
to select the paths I actually want to process. The overwhelming majority of the time these functions
<br>
are going to be operating on DirEntry objects produced by the scandir function, but there are some
<br>
cases where the user will be supplying the path themselves (for example, the root of a directory tree
<br>
to process). In my current code base that uses the scandir package I just wrap these paths in a
<br>
'GenericDirEntry' object and then pass them through the filter functions the same as any results
<br>
coming from the scandir function.<br>
<br>
With the decision to not expose any method in the stdlib to manually create a DirEntry object, I am
<br>
stuck with no good options. The least bad option I guess would be to copy the GenericDirEntry code
<br>
out of the scandir package into my own code base. This seems rather silly. I really don't understand
<br>
the rationale for not giving users a way to create these objects themselves, and I haven't actually seen
<br>
that explained anywhere. I guess people are unhappy with the overlap between pathlib.Path objects
<br>
and DirEntry objects and this is a misguided attempt to prod people into using pathlib. I think a better
<br>
approach is to document the differences between DirEntry and pathlib.Path objects and encourage
<br>
users to default to using pathlib.Path unless they have good reasons for using DirEntry.<br>
<br>
Thanks,<br>
Brendan<br>
</div>
</body>
</html>