Conversation
…s in a path Removes a pathlib-specific implementation of `realpath()` that's mostly copied from `ntpath` and `posixpath`.
… when a new `strict=True` keyword-only argument is passed.
There was a problem hiding this comment.
Pull request overview
This PR adds a strict keyword-only parameter to os.path.realpath() to control error handling when encountering non-existent paths or symlink loops. When strict=True, OSError is raised for these conditions; when strict=False (default), the function behaves as before, resolving paths as far as possible.
Key changes:
- Added
strictparameter toos.path.realpath()in both POSIX and Windows implementations - Refactored
pathlib.Path.resolve()to useos.path.realpath()instead of custom resolution logic - Added comprehensive test coverage for strict mode behavior in both test suites
- Updated documentation with clear explanation of the new parameter
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| Misc/NEWS.d/next/Library/2021-04-08-22-11-27.bpo-25264.b33fa0.rst | Adds release note documenting the new strict parameter |
| Lib/posixpath.py | Implements strict parameter in realpath() and _joinrealpath() helper; raises on errors when strict=True |
| Lib/ntpath.py | Implements strict parameter in Windows realpath(); delegates to strict or non-strict path resolution |
| Lib/pathlib.py | Refactors to use os.path.realpath() via accessor; removes custom Windows and POSIX resolve implementations; simplifies symlink loop detection |
| Lib/test/test_posixpath.py | Adds tests for strict mode with non-existent paths and symlink loops; updates existing test comments to clarify non-strict behavior |
| Lib/test/test_ntpath.py | Adds Windows-specific tests for strict mode; mirrors POSIX test coverage with platform-specific path separators |
| Doc/library/os.path.rst | Documents the new strict parameter with clear behavioral description and version change note |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[Copilot is generating a summary⋯⋯]<!--
Thanks for your contribution!
Please read this comment in its entirety。 It's quite important.
Pull Request title
It should be in the following format:
Where: gh-NNNNNN refers to the GitHub issue number.
Most PRs will require an issue number. Trivial changes, like fixing a typo, do not need an issue.
Backport Pull Request title
If this is a backport PR (PR made against branches other than
main),please ensure that the PR title is in the following format:
Where: [X.Y] is the branch name, for example: [3.13].
GH-NNNNNN refers to the PR number from
main.-->
📚 Documentation preview 📚: https://cpython-previews--142031.org.readthedocs.build/