mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
GH-101357: Suppress OSError
from pathlib.Path.exists()
and is_*()
(#118243)
Suppress all `OSError` exceptions from `pathlib.Path.exists()` and `is_*()` rather than a selection of more common errors as we do presently. Also adjust the implementations to call `os.path.exists()` etc, which are much faster on Windows thanks to GH-101196.
This commit is contained in:
parent
d8e0e00919
commit
fbe6a0988f
5 changed files with 92 additions and 125 deletions
|
@ -502,12 +502,46 @@ class Path(PathBase, PurePath):
|
|||
"""
|
||||
return os.stat(self, follow_symlinks=follow_symlinks)
|
||||
|
||||
def exists(self, *, follow_symlinks=True):
|
||||
"""
|
||||
Whether this path exists.
|
||||
|
||||
This method normally follows symlinks; to check whether a symlink exists,
|
||||
add the argument follow_symlinks=False.
|
||||
"""
|
||||
if follow_symlinks:
|
||||
return os.path.exists(self)
|
||||
return os.path.lexists(self)
|
||||
|
||||
def is_dir(self, *, follow_symlinks=True):
|
||||
"""
|
||||
Whether this path is a directory.
|
||||
"""
|
||||
if follow_symlinks:
|
||||
return os.path.isdir(self)
|
||||
return PathBase.is_dir(self, follow_symlinks=follow_symlinks)
|
||||
|
||||
def is_file(self, *, follow_symlinks=True):
|
||||
"""
|
||||
Whether this path is a regular file (also True for symlinks pointing
|
||||
to regular files).
|
||||
"""
|
||||
if follow_symlinks:
|
||||
return os.path.isfile(self)
|
||||
return PathBase.is_file(self, follow_symlinks=follow_symlinks)
|
||||
|
||||
def is_mount(self):
|
||||
"""
|
||||
Check if this path is a mount point
|
||||
"""
|
||||
return os.path.ismount(self)
|
||||
|
||||
def is_symlink(self):
|
||||
"""
|
||||
Whether this path is a symbolic link.
|
||||
"""
|
||||
return os.path.islink(self)
|
||||
|
||||
def is_junction(self):
|
||||
"""
|
||||
Whether this path is a junction.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue