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.
This commit is contained in:
Barney Gale 2024-12-29 21:42:07 +00:00 committed by GitHub
parent 7e819ce0f3
commit c78729f2df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 62 additions and 83 deletions

View file

@ -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):
"""