[3.12] Doc: Improve documentation for the `path argument in shutil.which()` (GH-124494) (#124576)

This commit is contained in:
Tom Most 2024-09-26 00:56:30 -07:00 committed by GitHub
parent d4cd39097e
commit fca2623c2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -439,8 +439,10 @@ Directory and files operations
*mode* is a permission mask passed to :func:`os.access`, by default *mode* is a permission mask passed to :func:`os.access`, by default
determining if the file exists and is executable. determining if the file exists and is executable.
When no *path* is specified, the results of :func:`os.environ` are used, *path* is a "``PATH`` string" specifying the directories to look in,
returning either the "PATH" value or a fallback of :data:`os.defpath`. delimited by :data:`os.pathsep`. When no *path* is specified, the
:envvar:`PATH` environment variable is read from :data:`os.environ`,
falling back to :data:`os.defpath` if it is not set.
On Windows, the current directory is prepended to the *path* if *mode* does On Windows, the current directory is prepended to the *path* if *mode* does
not include ``os.X_OK``. When the *mode* does include ``os.X_OK``, the not include ``os.X_OK``. When the *mode* does include ``os.X_OK``, the
@ -449,9 +451,9 @@ Directory and files operations
consulting the current working directory for executables: set the environment consulting the current working directory for executables: set the environment
variable ``NoDefaultCurrentDirectoryInExePath``. variable ``NoDefaultCurrentDirectoryInExePath``.
Also on Windows, the ``PATHEXT`` variable is used to resolve commands Also on Windows, the :envvar:`PATHEXT` environment variable is used to
that may not already include an extension. For example, if you call resolve commands that may not already include an extension. For example,
``shutil.which("python")``, :func:`which` will search ``PATHEXT`` if you call ``shutil.which("python")``, :func:`which` will search ``PATHEXT``
to know that it should look for ``python.exe`` within the *path* to know that it should look for ``python.exe`` within the *path*
directories. For example, on Windows:: directories. For example, on Windows::