mirror of
https://github.com/python/cpython.git
synced 2025-10-17 04:08:28 +00:00
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:
parent
7e819ce0f3
commit
c78729f2df
4 changed files with 62 additions and 83 deletions
|
@ -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):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue