Skip to content

Commit 9688d25

Browse files
authored
gh-101100: Document os.uname_result and os.statvfs_result with related constants (GH-151301)
1 parent d701f8e commit 9688d25

4 files changed

Lines changed: 204 additions & 54 deletions

File tree

Doc/library/os.rst

Lines changed: 201 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -800,36 +800,61 @@ process and user.
800800
single: gethostbyaddr() (in module socket)
801801

802802
Returns information identifying the current operating system.
803-
The return value is an object with five attributes:
804-
805-
* :attr:`sysname` - operating system name
806-
* :attr:`nodename` - name of machine on network (implementation-defined)
807-
* :attr:`release` - operating system release
808-
* :attr:`version` - operating system version
809-
* :attr:`machine` - hardware identifier
810-
811-
For backwards compatibility, this object is also iterable, behaving
812-
like a five-tuple containing :attr:`sysname`, :attr:`nodename`,
813-
:attr:`release`, :attr:`version`, and :attr:`machine`
814-
in that order.
815-
816-
Some systems truncate :attr:`nodename` to 8 characters or to the
817-
leading component; a better way to get the hostname is
818-
:func:`socket.gethostname` or even
819-
``socket.gethostbyaddr(socket.gethostname())``.
803+
The return value is a :class:`uname_result`.
820804

821805
On macOS, iOS and Android, this returns the *kernel* name and version (i.e.,
822806
``'Darwin'`` on macOS and iOS; ``'Linux'`` on Android). :func:`platform.uname`
823807
can be used to get the user-facing operating system name and version on iOS and
824808
Android.
825809

810+
.. seealso::
811+
:data:`sys.platform` which has finer granularity.
812+
813+
The :mod:`platform` module provides detailed checks for the
814+
system's identity.
815+
826816
.. availability:: Unix.
827817

828818
.. versionchanged:: 3.3
829819
Return type changed from a tuple to a tuple-like object
830820
with named attributes.
831821

832822

823+
.. class:: uname_result
824+
825+
Name and information about the system returned by :func:`os.uname`.
826+
These attributes correspond to the members described in :manpage:`uname(2)`.
827+
828+
For backwards compatibility, this object is also iterable, behaving
829+
like a five-tuple containing :attr:`~uname_result.sysname`,
830+
:attr:`~uname_result.nodename`, :attr:`~uname_result.release`,
831+
:attr:`~uname_result.version`, and :attr:`~uname_result.machine`
832+
in that order.
833+
834+
.. attribute:: sysname
835+
836+
Operating system name.
837+
838+
.. attribute:: nodename
839+
840+
Name of machine on network. Some systems truncate
841+
:attr:`~uname_result.nodename` to 8 characters or to the leading
842+
component; a better way to get the hostname is :func:`socket.gethostname`
843+
or even ``socket.gethostbyaddr(socket.gethostname())``.
844+
845+
.. attribute:: release
846+
847+
Operating system release.
848+
849+
.. attribute:: version
850+
851+
Operating system version.
852+
853+
.. attribute:: machine
854+
855+
Hardware identifier.
856+
857+
833858
.. function:: unsetenv(key, /)
834859

835860
.. index:: single: environment variables; deleting
@@ -1112,8 +1137,8 @@ as internal buffering of data.
11121137
.. function:: fstatvfs(fd, /)
11131138

11141139
Return information about the filesystem containing the file associated with
1115-
file descriptor *fd*, like :func:`statvfs`. As of Python 3.3, this is
1116-
equivalent to ``os.statvfs(fd)``.
1140+
file descriptor *fd* in a :class:`statvfs_result`, like :func:`statvfs`.
1141+
As of Python 3.3, this is equivalent to ``os.statvfs(fd)``.
11171142

11181143
.. availability:: Unix.
11191144

@@ -3784,48 +3809,174 @@ features:
37843809

37853810
.. function:: statvfs(path)
37863811

3787-
Perform a :c:func:`!statvfs` system call on the given path. The return value is
3788-
an object whose attributes describe the filesystem on the given path, and
3789-
correspond to the members of the :c:struct:`statvfs` structure, namely:
3790-
:attr:`f_bsize`, :attr:`f_frsize`, :attr:`f_blocks`, :attr:`f_bfree`,
3791-
:attr:`f_bavail`, :attr:`f_files`, :attr:`f_ffree`, :attr:`f_favail`,
3792-
:attr:`f_flag`, :attr:`f_namemax`, :attr:`f_fsid`.
3793-
3794-
Two module-level constants are defined for the :attr:`f_flag` attribute's
3795-
bit-flags: if :const:`ST_RDONLY` is set, the filesystem is mounted
3796-
read-only, and if :const:`ST_NOSUID` is set, the semantics of
3797-
setuid/setgid bits are disabled or not supported.
3798-
3799-
Additional module-level constants are defined for GNU/glibc based systems.
3800-
These are :const:`ST_NODEV` (disallow access to device special files),
3801-
:const:`ST_NOEXEC` (disallow program execution), :const:`ST_SYNCHRONOUS`
3802-
(writes are synced at once), :const:`ST_MANDLOCK` (allow mandatory locks on an FS),
3803-
:const:`ST_WRITE` (write on file/directory/symlink), :const:`ST_APPEND`
3804-
(append-only file), :const:`ST_IMMUTABLE` (immutable file), :const:`ST_NOATIME`
3805-
(do not update access times), :const:`ST_NODIRATIME` (do not update directory access
3806-
times), :const:`ST_RELATIME` (update atime relative to mtime/ctime).
3812+
Perform a :manpage:`statvfs(3)` system call on the given path. The return value
3813+
is a :class:`statvfs_result` whose attributes describe the filesystem
3814+
on the given path and correspond to the members of the :c:struct:`statvfs`
3815+
structure.
38073816

38083817
This function can support :ref:`specifying a file descriptor <path_fd>`.
38093818

38103819
.. availability:: Unix.
38113820

3812-
.. versionchanged:: 3.2
3813-
The :const:`ST_RDONLY` and :const:`ST_NOSUID` constants were added.
3814-
38153821
.. versionchanged:: 3.3
38163822
Added support for specifying *path* as an open file descriptor.
38173823

3818-
.. versionchanged:: 3.4
3819-
The :const:`ST_NODEV`, :const:`ST_NOEXEC`, :const:`ST_SYNCHRONOUS`,
3820-
:const:`ST_MANDLOCK`, :const:`ST_WRITE`, :const:`ST_APPEND`,
3821-
:const:`ST_IMMUTABLE`, :const:`ST_NOATIME`, :const:`ST_NODIRATIME`,
3822-
and :const:`ST_RELATIME` constants were added.
3823-
38243824
.. versionchanged:: 3.6
38253825
Accepts a :term:`path-like object`.
38263826

3827-
.. versionchanged:: 3.7
3828-
Added the :attr:`f_fsid` attribute.
3827+
3828+
.. class:: statvfs_result
3829+
3830+
Filesystem statistics returned by :func:`os.statvfs` and :func:`os.fstatvfs`.
3831+
See :manpage:`statvfs(3)` for more details.
3832+
3833+
.. attribute:: f_bsize
3834+
3835+
Block size.
3836+
3837+
.. attribute:: f_frsize
3838+
3839+
Fragment size.
3840+
3841+
.. attribute:: f_blocks
3842+
3843+
Number of :attr:`~statvfs_result.f_frsize` sized blocks the filesystem
3844+
can contain.
3845+
3846+
.. attribute:: f_bfree
3847+
3848+
Number of free blocks.
3849+
3850+
.. attribute:: f_bavail
3851+
3852+
Number of free blocks for unprivileged users.
3853+
3854+
.. attribute:: f_files
3855+
3856+
Number of file entries, inodes, the filesystem can contain.
3857+
3858+
.. attribute:: f_ffree
3859+
3860+
Number of free files entries.
3861+
3862+
.. attribute:: f_favail
3863+
3864+
Number of free file entries for unprivileged users.
3865+
3866+
.. attribute:: f_flag
3867+
3868+
Bit-mask of mount flags. The following flags are defined:
3869+
:data:`ST_RDONLY`, :data:`ST_NOSUID`, :data:`ST_NODEV`,
3870+
:data:`ST_NOEXEC`, :data:`ST_SYNCHRONOUS`, :data:`ST_MANDLOCK`,
3871+
:data:`ST_WRITE`, :data:`ST_APPEND`, :data:`ST_IMMUTABLE`,
3872+
:data:`ST_NOATIME`, :data:`ST_NODIRATIME`, and :data:`ST_RELATIME`.
3873+
3874+
.. attribute:: f_namemax
3875+
3876+
Filesystem max filename length. OS specific limitations such as
3877+
:ref:`Windows MAX_PATH <max-path>` and those described in Linux
3878+
:manpage:`pathname(7)` may exist.
3879+
3880+
.. attribute:: f_fsid
3881+
3882+
Filesystem ID.
3883+
3884+
.. versionadded:: 3.7
3885+
3886+
3887+
The following flags are used in :attr:`statvfs_result.f_flag`.
3888+
3889+
.. data:: ST_RDONLY
3890+
3891+
Read-only filesystem.
3892+
3893+
.. versionadded:: 3.2
3894+
3895+
.. data:: ST_NOSUID
3896+
3897+
Setuid/setgid bits are disabled or not supported.
3898+
3899+
.. versionadded:: 3.2
3900+
3901+
.. data:: ST_NODEV
3902+
3903+
Disallow access to device special files.
3904+
3905+
.. availability:: Linux.
3906+
3907+
.. versionadded:: 3.4
3908+
3909+
.. data:: ST_NOEXEC
3910+
3911+
Disallow program execution.
3912+
3913+
.. availability:: Linux.
3914+
3915+
.. versionadded:: 3.4
3916+
3917+
.. data:: ST_SYNCHRONOUS
3918+
3919+
Writes are synced at once.
3920+
3921+
.. availability:: Linux.
3922+
3923+
.. versionadded:: 3.4
3924+
3925+
.. data:: ST_MANDLOCK
3926+
3927+
Allow mandatory locks on an FS.
3928+
3929+
.. availability:: Linux.
3930+
3931+
.. versionadded:: 3.4
3932+
3933+
.. data:: ST_WRITE
3934+
3935+
Write on file/directory/symlink.
3936+
3937+
.. availability:: Linux.
3938+
3939+
.. versionadded:: 3.4
3940+
3941+
.. data:: ST_APPEND
3942+
3943+
Append-only file.
3944+
3945+
.. availability:: Linux.
3946+
3947+
.. versionadded:: 3.4
3948+
3949+
.. data:: ST_IMMUTABLE
3950+
3951+
Immutable file.
3952+
3953+
.. availability:: Linux.
3954+
3955+
.. versionadded:: 3.4
3956+
3957+
.. data:: ST_NOATIME
3958+
3959+
Do not update access times.
3960+
3961+
.. availability:: Linux.
3962+
3963+
.. versionadded:: 3.4
3964+
3965+
.. data:: ST_NODIRATIME
3966+
3967+
Do not update directory access times.
3968+
3969+
.. availability:: Linux.
3970+
3971+
.. versionadded:: 3.4
3972+
3973+
.. data:: ST_RELATIME
3974+
3975+
Update atime relative to mtime/ctime.
3976+
3977+
.. availability:: Linux.
3978+
3979+
.. versionadded:: 3.4
38293980

38303981

38313982
.. data:: supports_dir_fd

Doc/tools/.nitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Doc/library/lzma.rst
1818
Doc/library/mmap.rst
1919
Doc/library/multiprocessing.rst
2020
Doc/library/optparse.rst
21-
Doc/library/os.rst
2221
Doc/library/pickletools.rst
2322
Doc/library/pyexpat.rst
2423
Doc/library/select.rst

Misc/NEWS.d/3.10.0a4.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ Harmonized :func:`random.randrange` argument handling to match :func:`range`.
622622
.. nonce: O4VcCY
623623
.. section: Library
624624
625-
Restore compatibility for ``uname_result`` around deepcopy and _replace.
625+
Restore compatibility for :class:`os.uname_result` around deepcopy and _replace.
626626

627627
..
628628

Misc/NEWS.d/3.12.0a3.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,8 @@ event loop but the current event loop was set.
454454
.. nonce: humlhz
455455
.. section: Library
456456
457-
On ``uname_result``, restored expectation that ``_fields`` and ``_asdict``
458-
would include all six properties including ``processor``.
457+
On :class:`os.uname_result`, restored expectation that ``_fields`` and
458+
``_asdict`` would include all six properties including ``processor``.
459459

460460
..
461461

0 commit comments

Comments
 (0)