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

Conversation

wei-juncheng
Copy link

@wei-juncheng wei-juncheng commented Jun 15, 2025

Closes #127264

What

Issue #127264 pointed out that users relying on exists() as a safe pre-check for resolve() may still encounter an unexpected FileNotFoundError when the cwd is gone. This note:

  • Explains the underlying cause (the getcwd() call).
  • Warns that non-strict mode isn’t immune to failing when the cwd is deleted.
  • Reminds users that a pre-check with exists() can race with filesystem changes.

How

  • Added a “.. note::” under the “Expanding and resolving paths” section of Doc/library/pathlib.rst to document that Path.resolve(strict=False) will call os.getcwd() internally and thus can raise FileNotFoundError if the current working directory has been deleted.

📚 Documentation preview 📚: https://cpython-previews--135531.org.readthedocs.build/

@python-cla-bot
Copy link

python-cla-bot bot commented Jun 15, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@uranusjr
Copy link
Contributor

Should we also add this to os.path.realpath documentation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review docs Documentation in the Doc dir skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

pathlib: Path('.').exists() returns True when current working directory (cwd) was deleted
2 participants