mirror of
https://github.com/python/cpython.git
synced 2025-07-23 03:05:38 +00:00
GH-105793: Add follow_symlinks argument to pathlib.Path.is_dir()
and 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()`.
This commit is contained in:
parent
5d4dbf0e30
commit
219effa876
5 changed files with 59 additions and 18 deletions
|
@ -817,12 +817,12 @@ class Path(PurePath):
|
|||
return False
|
||||
return True
|
||||
|
||||
def is_dir(self):
|
||||
def is_dir(self, *, follow_symlinks=True):
|
||||
"""
|
||||
Whether this path is a directory.
|
||||
"""
|
||||
try:
|
||||
return S_ISDIR(self.stat().st_mode)
|
||||
return S_ISDIR(self.stat(follow_symlinks=follow_symlinks).st_mode)
|
||||
except OSError as e:
|
||||
if not _ignore_error(e):
|
||||
raise
|
||||
|
@ -833,13 +833,13 @@ class Path(PurePath):
|
|||
# Non-encodable path
|
||||
return False
|
||||
|
||||
def is_file(self):
|
||||
def is_file(self, *, follow_symlinks=True):
|
||||
"""
|
||||
Whether this path is a regular file (also True for symlinks pointing
|
||||
to regular files).
|
||||
"""
|
||||
try:
|
||||
return S_ISREG(self.stat().st_mode)
|
||||
return S_ISREG(self.stat(follow_symlinks=follow_symlinks).st_mode)
|
||||
except OSError as e:
|
||||
if not _ignore_error(e):
|
||||
raise
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue