https://github.com/python/cpython/commit/2e519ddf413018582436ca1600994887ef2345ea
commit: 2e519ddf413018582436ca1600994887ef2345ea
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-08-10T20:31:53+02:00
summary:
gh-155358: Use named attributes with os module (#155366)
Replace os.stat() result:
* st[1] => st.st_ino
* st[6] => st.st_size
* st[ST_MTIME] => st_mtime: change int type to float
files:
M Lib/http/server.py
M Lib/test/test_os/test_posix.py
M Tools/c-analyzer/distutils/dep_util.py
diff --git a/Lib/http/server.py b/Lib/http/server.py
index a74773bf8a12d47..2fdfc78725ea4b7 100644
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -857,7 +857,7 @@ def send_head(self):
self.send_response(HTTPStatus.OK)
self.send_header("Content-type", ctype)
- self.send_header("Content-Length", str(fs[6]))
+ self.send_header("Content-Length", str(fs.st_size))
self.send_header("Last-Modified",
self.date_time_string(fs.st_mtime))
self._send_extra_response_headers()
diff --git a/Lib/test/test_os/test_posix.py b/Lib/test/test_os/test_posix.py
index 1cc8b5d7b1c6165..814f945aac7453c 100644
--- a/Lib/test/test_os/test_posix.py
+++ b/Lib/test/test_os/test_posix.py
@@ -1823,8 +1823,8 @@ def test_link_dir_fd(self):
self.skipTest('posix.link(): %s' % e)
self.addCleanup(posix.unlink, fulllinkname)
# should have same inodes
- self.assertEqual(posix.stat(fullname)[1],
- posix.stat(fulllinkname)[1])
+ self.assertEqual(posix.stat(fullname).st_ino,
+ posix.stat(fulllinkname).st_ino)
@unittest.skipUnless(os.mkdir in os.supports_dir_fd, "test needs dir_fd
support in os.mkdir()")
def test_mkdir_dir_fd(self):
diff --git a/Tools/c-analyzer/distutils/dep_util.py
b/Tools/c-analyzer/distutils/dep_util.py
index 318c830f2eab3e3..a97f925d9ee4187 100644
--- a/Tools/c-analyzer/distutils/dep_util.py
+++ b/Tools/c-analyzer/distutils/dep_util.py
@@ -20,9 +20,8 @@ def newer (source, target):
if not os.path.exists(target):
return 1
- from stat import ST_MTIME
- mtime1 = os.stat(source)[ST_MTIME]
- mtime2 = os.stat(target)[ST_MTIME]
+ mtime1 = os.stat(source).st_mtime
+ mtime2 = os.stat(target).st_mtime
return mtime1 > mtime2
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]