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

Skip to content

gh-127264: Update document behavior of Path.resolve() #135531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Doc/library/pathlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,24 @@ Expanding and resolving paths
strict mode, and no exception is raised in non-strict mode. In previous
versions, :exc:`RuntimeError` is raised no matter the value of *strict*.

.. note::

Even with ``strict=False``, ``Path.resolve()`` internally calls
:func:`os.getcwd` to obtain the current working directory (cwd).
If the cwd has been removed (for example, by unlinking it externally),
:func:`os.getcwd` will raise :exc:`FileNotFoundError`, causing
``resolve()`` to fail.

Therefore:

- Do **not** rely solely on ``Path.exists()`` as a pre-check for
``resolve()``: ``exists()`` only reflects the existence of the
*target* path in the filesystem, and does not detect whether the cwd
has been deleted.
- In multi-threaded or multi-process environments, a successful
``exists()`` check may still race with filesystem changes that occur
before calling ``resolve()``.


.. method:: Path.readlink()

Expand Down
Loading