-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Support for not following symlinks in pathlib.Path.is_dir() #105793
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
Labels
Comments
barneygale
added a commit
to barneygale/cpython
that referenced
this issue
Jun 14, 2023
Brings `pathlib.Path.is_dir()` in line with `os.DirEntry.is_dir()`, which will be important for implementing generic path walking and globbing.
|
barneygale
added a commit
to barneygale/cpython
that referenced
this issue
Jun 15, 2023
barneygale
added a commit
to barneygale/cpython
that referenced
this issue
Jun 19, 2023
barneygale
added a commit
to barneygale/cpython
that referenced
this issue
Jun 24, 2023
barneygale
added a commit
that referenced
this issue
Jun 26, 2023
…d `is_file()` (GH-105794) Brings `pathlib.Path.is_dir()` and `in line with `os.DirEntry.is_dir()`, which will be important for implementing generic path walking and globbing. Likewise `is_file()`.
Implemented in:
Thank you Steve for the review and Eryk for the |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Feature or enhancement
Add a follow_symlinks argument to
pathlib.Path.is_dir()
, defaulting toTrue
Pitch
Pathlib's
walk()
andglob()
implementations are built uponos.scandir()
, which yieldsos.DirEntry
objects. The interface foros.DirEntry
is a rough subset ofpathlib.Path
, including thename
attribute andis_dir()
method.Pathlib only ever calls
os.scandir()
via a privatepathlib.Path._scandir()
method, currently defined as follows:In future I'd like to add a
pathlib.AbstractPath
class with abstractstat()
,iterdir()
andopen()
methods.The default implementation of
AbstractPath._scandir()
would useiterdir()
:Note how it returns
AbstractPath
objects, and notDirEntry
objects. This exploits the similarities of thePath
andDirEntry
APIs.... but there's a problem!
The
os.DirEntry.is_dir()
method accepts a keyword-onlyfollow_symlinks
argument. Our globbing implementation requires us to set this argument. But thePath.is_dir()
method does not accept this argument!If we add a keyword-only follow_symlinks argument to
Path.is_dir()
, we make it compatible withos.DirEntry.is_dir()
, which in turn allows us to build aglob()
implementation upon user-definedstat()
anditerdir()
methods in a futureAbstractPath
class.Previous discussion
General discussion of
AbstractPath
: https://discuss.python.org/t/make-pathlib-extensible/3428We added a follow_symlinks argument to
Path.exists()
in #89769 / #29655.Linked PRs
pathlib.Path.is_dir()
andis_file()
#105794The text was updated successfully, but these errors were encountered: