Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e152169

Browse files
csabellalarryhastings
authored andcommitted
bpo-16024: Doc cleanup regarding path_fd, dir_fd, follow_symlinks (GH-5505)
1 parent 2950073 commit e152169

File tree

1 file changed

+76
-66
lines changed

1 file changed

+76
-66
lines changed

Doc/library/os.rst

+76-66
Original file line numberDiff line numberDiff line change
@@ -1453,16 +1453,19 @@ features:
14531453
.. _path_fd:
14541454

14551455
* **specifying a file descriptor:**
1456-
For some functions, the *path* argument can be not only a string giving a path
1457-
name, but also a file descriptor. The function will then operate on the file
1458-
referred to by the descriptor. (For POSIX systems, Python will call the
1459-
``f...`` version of the function.)
1460-
1461-
You can check whether or not *path* can be specified as a file descriptor on
1462-
your platform using :data:`os.supports_fd`. If it is unavailable, using it
1463-
will raise a :exc:`NotImplementedError`.
1456+
Normally the *path* argument provided to functions in the :mod:`os` module
1457+
must be a string specifying a file path. However, some functions now
1458+
alternatively accept an open file descriptor for their *path* argument.
1459+
The function will then operate on the file referred to by the descriptor.
1460+
(For POSIX systems, Python will call the variant of the function prefixed
1461+
with ``f`` (e.g. call ``fchdir`` instead of ``chdir``).)
1462+
1463+
You can check whether or not *path* can be specified as a file descriptor
1464+
for a particular function on your platform using :data:`os.supports_fd`.
1465+
If this functionality is unavailable, using it will raise a
1466+
:exc:`NotImplementedError`.
14641467

1465-
If the function also supports *dir_fd* or *follow_symlinks* arguments, it is
1468+
If the function also supports *dir_fd* or *follow_symlinks* arguments, it's
14661469
an error to specify one of those when supplying *path* as a file descriptor.
14671470

14681471
.. _dir_fd:
@@ -1471,23 +1474,24 @@ features:
14711474
should be a file descriptor referring to a directory, and the path to operate
14721475
on should be relative; path will then be relative to that directory. If the
14731476
path is absolute, *dir_fd* is ignored. (For POSIX systems, Python will call
1474-
the ``...at`` or ``f...at`` version of the function.)
1477+
the variant of the function with an ``at`` suffix and possibly prefixed with
1478+
``f`` (e.g. call ``faccessat`` instead of ``access``).
14751479

1476-
You can check whether or not *dir_fd* is supported on your platform using
1477-
:data:`os.supports_dir_fd`. If it is unavailable, using it will raise a
1478-
:exc:`NotImplementedError`.
1480+
You can check whether or not *dir_fd* is supported for a particular function
1481+
on your platform using :data:`os.supports_dir_fd`. If it's unavailable,
1482+
using it will raise a :exc:`NotImplementedError`.
14791483

14801484
.. _follow_symlinks:
14811485

14821486
* **not following symlinks:** If *follow_symlinks* is
14831487
``False``, and the last element of the path to operate on is a symbolic link,
1484-
the function will operate on the symbolic link itself instead of the file the
1485-
link points to. (For POSIX systems, Python will call the ``l...`` version of
1486-
the function.)
1488+
the function will operate on the symbolic link itself rather than the file
1489+
pointed to by the link. (For POSIX systems, Python will call the ``l...``
1490+
variant of the function.)
14871491

1488-
You can check whether or not *follow_symlinks* is supported on your platform
1489-
using :data:`os.supports_follow_symlinks`. If it is unavailable, using it
1490-
will raise a :exc:`NotImplementedError`.
1492+
You can check whether or not *follow_symlinks* is supported for a particular
1493+
function on your platform using :data:`os.supports_follow_symlinks`.
1494+
If it's unavailable, using it will raise a :exc:`NotImplementedError`.
14911495

14921496

14931497

@@ -1662,7 +1666,7 @@ features:
16621666
.. availability:: Unix.
16631667

16641668
.. versionadded:: 3.3
1665-
Added support for specifying an open file descriptor for *path*,
1669+
Added support for specifying *path* as an open file descriptor,
16661670
and the *dir_fd* and *follow_symlinks* arguments.
16671671

16681672
.. versionchanged:: 3.6
@@ -1781,7 +1785,7 @@ features:
17811785
The *path* parameter became optional.
17821786

17831787
.. versionadded:: 3.3
1784-
Added support for specifying an open file descriptor for *path*.
1788+
Added support for specifying *path* as an open file descriptor.
17851789

17861790
.. versionchanged:: 3.6
17871791
Accepts a :term:`path-like object`.
@@ -2593,7 +2597,7 @@ features:
25932597
The :const:`ST_RDONLY` and :const:`ST_NOSUID` constants were added.
25942598

25952599
.. versionadded:: 3.3
2596-
Added support for specifying an open file descriptor for *path*.
2600+
Added support for specifying *path* as an open file descriptor.
25972601

25982602
.. versionchanged:: 3.4
25992603
The :const:`ST_NODEV`, :const:`ST_NOEXEC`, :const:`ST_SYNCHRONOUS`,
@@ -2610,59 +2614,61 @@ features:
26102614

26112615
.. data:: supports_dir_fd
26122616

2613-
A :class:`~collections.abc.Set` object indicating which functions in the
2614-
:mod:`os` module permit use of their *dir_fd* parameter. Different platforms
2615-
provide different functionality, and an option that might work on one might
2616-
be unsupported on another. For consistency's sakes, functions that support
2617-
*dir_fd* always allow specifying the parameter, but will raise an exception
2618-
if the functionality is not actually available.
2619-
2620-
To check whether a particular function permits use of its *dir_fd*
2621-
parameter, use the ``in`` operator on ``supports_dir_fd``. As an example,
2622-
this expression determines whether the *dir_fd* parameter of :func:`os.stat`
2623-
is locally available::
2617+
A :class:`set` object indicating which functions in the :mod:`os`
2618+
module accept an open file descriptor for their *dir_fd* parameter.
2619+
Different platforms provide different features, and the underlying
2620+
functionality Python uses to implement the *dir_fd* parameter is not
2621+
available on all platforms Python supports. For consistency's sake,
2622+
functions that may support *dir_fd* always allow specifying the
2623+
parameter, but will throw an exception if the functionality is used
2624+
when it's not locally available. (Specifying ``None`` for *dir_fd*
2625+
is always supported on all platforms.)
2626+
2627+
To check whether a particular function accepts an open file descriptor
2628+
for its *dir_fd* parameter, use the ``in`` operator on ``supports_dir_fd``.
2629+
As an example, this expression evaluates to ``True`` if :func:`os.stat`
2630+
accepts open file descriptors for *dir_fd* on the local platform::
26242631

26252632
os.stat in os.supports_dir_fd
26262633

2627-
Currently *dir_fd* parameters only work on Unix platforms; none of them work
2628-
on Windows.
2634+
Currently *dir_fd* parameters only work on Unix platforms;
2635+
none of them work on Windows.
26292636

26302637
.. versionadded:: 3.3
26312638

26322639

26332640
.. data:: supports_effective_ids
26342641

2635-
A :class:`~collections.abc.Set` object indicating which functions in the
2636-
:mod:`os` module permit use of the *effective_ids* parameter for
2637-
:func:`os.access`. If the local platform supports it, the collection will
2638-
contain :func:`os.access`, otherwise it will be empty.
2642+
A :class:`set` object indicating whether :func:`os.access` permits
2643+
specifying ``True`` for its *effective_ids* parameter on the local platform.
2644+
(Specifying ``False`` for *effective_ids* is always supported on all
2645+
platforms.) If the local platform supports it, the collection will contain
2646+
:func:`os.access`; otherwise it will be empty.
26392647

2640-
To check whether you can use the *effective_ids* parameter for
2641-
:func:`os.access`, use the ``in`` operator on ``supports_effective_ids``,
2642-
like so::
2648+
This expression evaluates to ``True`` if :func:`os.access` supports
2649+
``effective_ids=True`` on the local platform::
26432650

26442651
os.access in os.supports_effective_ids
26452652

2646-
Currently *effective_ids* only works on Unix platforms; it does not work on
2647-
Windows.
2653+
Currently *effective_ids* is only supported on Unix platforms;
2654+
it does not work on Windows.
26482655

26492656
.. versionadded:: 3.3
26502657

26512658

26522659
.. data:: supports_fd
26532660

2654-
A :class:`~collections.abc.Set` object indicating which functions in the
2661+
A :class:`set` object indicating which functions in the
26552662
:mod:`os` module permit specifying their *path* parameter as an open file
2656-
descriptor. Different platforms provide different functionality, and an
2657-
option that might work on one might be unsupported on another. For
2658-
consistency's sakes, functions that support *fd* always allow specifying
2659-
the parameter, but will raise an exception if the functionality is not
2660-
actually available.
2663+
descriptor on the local platform. Different platforms provide different
2664+
features, and the underlying functionality Python uses to accept open file
2665+
descriptors as *path* arguments is not available on all platforms Python
2666+
supports.
26612667

2662-
To check whether a particular function permits specifying an open file
2668+
To determine whether a particular function permits specifying an open file
26632669
descriptor for its *path* parameter, use the ``in`` operator on
2664-
``supports_fd``. As an example, this expression determines whether
2665-
:func:`os.chdir` accepts open file descriptors when called on your local
2670+
``supports_fd``. As an example, this expression evaluates to ``True`` if
2671+
:func:`os.chdir` accepts open file descriptors for *path* on your local
26662672
platform::
26672673

26682674
os.chdir in os.supports_fd
@@ -2672,17 +2678,21 @@ features:
26722678

26732679
.. data:: supports_follow_symlinks
26742680

2675-
A :class:`~collections.abc.Set` object indicating which functions in the
2676-
:mod:`os` module permit use of their *follow_symlinks* parameter. Different
2677-
platforms provide different functionality, and an option that might work on
2678-
one might be unsupported on another. For consistency's sakes, functions that
2679-
support *follow_symlinks* always allow specifying the parameter, but will
2680-
raise an exception if the functionality is not actually available.
2681-
2682-
To check whether a particular function permits use of its *follow_symlinks*
2683-
parameter, use the ``in`` operator on ``supports_follow_symlinks``. As an
2684-
example, this expression determines whether the *follow_symlinks* parameter
2685-
of :func:`os.stat` is locally available::
2681+
A :class:`set` object indicating which functions in the :mod:`os` module
2682+
accept ``False`` for their *follow_symlinks* parameter on the local platform.
2683+
Different platforms provide different features, and the underlying
2684+
functionality Python uses to implement *follow_symlinks* is not available
2685+
on all platforms Python supports. For consistency's sake, functions that
2686+
may support *follow_symlinks* always allow specifying the parameter, but
2687+
will throw an exception if the functionality is used when it's not locally
2688+
available. (Specifying ``True`` for *follow_symlinks* is always supported
2689+
on all platforms.)
2690+
2691+
To check whether a particular function accepts ``False`` for its
2692+
*follow_symlinks* parameter, use the ``in`` operator on
2693+
``supports_follow_symlinks``. As an example, this expression evaluates
2694+
to ``True`` if you may specify ``follow_symlinks=False`` when calling
2695+
:func:`os.stat` on the local platform::
26862696

26872697
os.stat in os.supports_follow_symlinks
26882698

@@ -2801,7 +2811,7 @@ features:
28012811
following symlinks <follow_symlinks>`.
28022812

28032813
.. versionadded:: 3.3
2804-
Added support for specifying an open file descriptor for *path*,
2814+
Added support for specifying *path* as an open file descriptor,
28052815
and the *dir_fd*, *follow_symlinks*, and *ns* parameters.
28062816

28072817
.. versionchanged:: 3.6
@@ -3162,7 +3172,7 @@ to be ignored.
31623172
.. availability:: Unix, Windows.
31633173

31643174
.. versionadded:: 3.3
3165-
Added support for specifying an open file descriptor for *path*
3175+
Added support for specifying *path* as an open file descriptor
31663176
for :func:`execve`.
31673177

31683178
.. versionchanged:: 3.6

0 commit comments

Comments
 (0)