diff options
author | Barney Gale <barney.gale@gmail.com> | 2024-12-29 21:42:07 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-29 21:42:07 (GMT) |
commit | c78729f2df7c0e220f1080edb2a0d0cdd49e22df (patch) | |
tree | 8bbe6b09b6c4171463f46d03bbfb3e94fb29835d /Lib/pathlib/_local.py | |
parent | 7e819ce0f32068de7914cd1ba3b4b95e91ea9873 (diff) | |
download | cpython-c78729f2df7c0e220f1080edb2a0d0cdd49e22df.zip cpython-c78729f2df7c0e220f1080edb2a0d0cdd49e22df.tar.gz cpython-c78729f2df7c0e220f1080edb2a0d0cdd49e22df.tar.bz2 |
GH-127381: pathlib ABCs: remove `PathBase.stat()` (#128334)
Remove the `PathBase.stat()` method. Its use of the `os.stat_result` API,
with its 10 mandatory fields and low-level types, makes it an awkward fit
for virtual filesystems.
We'll look to add a `PathBase.info` attribute later - see GH-125413.
Diffstat (limited to 'Lib/pathlib/_local.py')
-rw-r--r-- | Lib/pathlib/_local.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/Lib/pathlib/_local.py b/Lib/pathlib/_local.py index 915402e..4484d95 100644 --- a/Lib/pathlib/_local.py +++ b/Lib/pathlib/_local.py @@ -7,7 +7,7 @@ import sys from errno import * from glob import _StringGlobber, _no_recurse_symlinks from itertools import chain -from stat import S_IMODE, S_ISSOCK, S_ISBLK, S_ISCHR, S_ISFIFO +from stat import S_IMODE, S_ISDIR, S_ISREG, S_ISSOCK, S_ISBLK, S_ISCHR, S_ISFIFO from _collections_abc import Sequence try: @@ -725,7 +725,10 @@ class Path(PathBase, PurePath): """ if follow_symlinks: return os.path.isdir(self) - return PathBase.is_dir(self, follow_symlinks=follow_symlinks) + try: + return S_ISDIR(self.stat(follow_symlinks=follow_symlinks).st_mode) + except (OSError, ValueError): + return False def is_file(self, *, follow_symlinks=True): """ @@ -734,7 +737,10 @@ class Path(PathBase, PurePath): """ if follow_symlinks: return os.path.isfile(self) - return PathBase.is_file(self, follow_symlinks=follow_symlinks) + try: + return S_ISREG(self.stat(follow_symlinks=follow_symlinks).st_mode) + except (OSError, ValueError): + return False def is_mount(self): """ |