Skip to content

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

Open
wei-juncheng wants to merge 1 commit intopython:mainfrom
wei-juncheng:wei-juncheng/doc/gh127264-update-pathlib-resolve
Open

gh-127264: Update document behavior of Path.resolve()#135531
wei-juncheng wants to merge 1 commit intopython:mainfrom
wei-juncheng:wei-juncheng/doc/gh127264-update-pathlib-resolve

Conversation

@wei-juncheng
Copy link
Copy Markdown

@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
Copy Markdown

python-cla-bot Bot commented Jun 15, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@uranusjr
Copy link
Copy Markdown
Contributor

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

@github-actions
Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 26, 2026
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 stale Stale PR or inactive for long period of time.

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