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

@ -1835,6 +1835,31 @@ def test_symlink_to_unsupported(self):
with self.assertRaises(pathlib.UnsupportedOperation):
q.symlink_to(p)
def test_stat(self):
statA = self.cls(self.base).joinpath('fileA').stat()
statB = self.cls(self.base).joinpath('dirB', 'fileB').stat()
statC = self.cls(self.base).joinpath('dirC').stat()
# st_mode: files are the same, directory differs.
self.assertIsInstance(statA.st_mode, int)
self.assertEqual(statA.st_mode, statB.st_mode)
self.assertNotEqual(statA.st_mode, statC.st_mode)
self.assertNotEqual(statB.st_mode, statC.st_mode)
# st_ino: all different,
self.assertIsInstance(statA.st_ino, int)
self.assertNotEqual(statA.st_ino, statB.st_ino)
self.assertNotEqual(statA.st_ino, statC.st_ino)
self.assertNotEqual(statB.st_ino, statC.st_ino)
# st_dev: all the same.
self.assertIsInstance(statA.st_dev, int)
self.assertEqual(statA.st_dev, statB.st_dev)
self.assertEqual(statA.st_dev, statC.st_dev)
# other attributes not used by pathlib.
def test_stat_no_follow_symlinks_nosymlink(self):
p = self.cls(self.base) / 'fileA'
st = p.stat()
self.assertEqual(st, p.stat(follow_symlinks=False))
@needs_symlinks
def test_stat_no_follow_symlinks(self):
p = self.cls(self.base) / 'linkA'