gh-154690: pathlib: Resolve paths in ensure_distinct_paths() before comparing#154689
Open
dura0ok wants to merge 3 commits into
Open
gh-154690: pathlib: Resolve paths in ensure_distinct_paths() before comparing#154689dura0ok wants to merge 3 commits into
dura0ok wants to merge 3 commits into
Conversation
Path.copy() only blocked self-copies via a lexical check, so relative vs absolute paths and symlink aliases could still copy a directory into itself. Resolve when possible (like shutil._destinsrc) and add tests.
sobolevn
reviewed
Jul 25, 2026
| target = target.resolve(strict=False) | ||
| except (AttributeError, TypeError): | ||
| pass | ||
| except (OSError, ValueError, RuntimeError, NotImplementedError): |
Member
There was a problem hiding this comment.
Is there any specific reason to include two except/pass cases? Also, are you sure that these many exceptions can realistically happen? Maybe provide a comment - how?
Contributor
Author
There was a problem hiding this comment.
No, two except/pass blocks did the same thing. Merged into one and kept only AttributeError when resolve is missing and OSError when realpath fails. The rest were not realistic.
dura0ok
force-pushed
the
fix-pathlib-copy-into-self
branch
from
July 25, 2026 13:31
192abed to
d54db22
Compare
…andling Only catch AttributeError (no resolve) and OSError (realpath failed), and test the lexical fallback for both cases.
dura0ok
force-pushed
the
fix-pathlib-copy-into-self
branch
from
July 25, 2026 13:34
d54db22 to
33257e7
Compare
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.
Path.copy() only blocked self-copies via a lexical check, so relative vs absolute paths and symlink aliases could still copy a directory into itself. Resolve when possible (like shutil._destinsrc)