From ee75661e069fe914e920fca5e5e2f77c05713a73 Mon Sep 17 00:00:00 2001 From: Iannaan Date: Fri, 5 Sep 2025 16:22:43 +0800 Subject: [PATCH 1/2] gh-137970:add st_mode_notice code_example --- Doc/library/os.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Doc/library/os.rst b/Doc/library/os.rst index 0333fe9f9967f8..16ad69829abdc2 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -3141,6 +3141,23 @@ features: File mode: file type and file mode bits (permissions). + .. note:: + + ``st_mode`` is an **int** bitmask that combines the file type and the + permission bits. If you expect POSIX-style values like ``755`` or ``644``, + render the value in octal and/or mask out only the permission bits. For example: + + .. code-block:: pycon + + >>> import os, stat + >>> m = os.stat("somefile").st_mode + >>> oct(m) # includes the file-type bits (e.g. 0o100...) + '0o100755' + >>> oct(stat.S_IMODE(m)) # permissions only + '0o755' + >>> stat.filemode(m) # human-readable form + '-rwxr-xr-x' + .. attribute:: st_ino Platform dependent, but if non-zero, uniquely identifies the From fbaf28800bfe670a6bfc732371371336548df3dc Mon Sep 17 00:00:00 2001 From: Iannaan Date: Sat, 6 Sep 2025 03:23:25 +0800 Subject: [PATCH 2/2] Use a Sphinx --- Doc/library/os.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/os.rst b/Doc/library/os.rst index 16ad69829abdc2..c234d30cd240c7 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -3143,7 +3143,7 @@ features: .. note:: - ``st_mode`` is an **int** bitmask that combines the file type and the + ``st_mode`` is an :class:`int` bitmask that combines the file type and the permission bits. If you expect POSIX-style values like ``755`` or ``644``, render the value in octal and/or mask out only the permission bits. For example: