Repository navigation
Map only the matched prefix in PathAliases - #2268
Merged
nedbat merged 4 commits intoAug 19, 2026
Merged
Conversation
str.replace rewrote every occurrence of the matched text, so a path that repeats the aliased directory later on was rewritten twice.
nedbat
reviewed
Aug 17, 2026
The alias result ./mysrc carries a forward separator, so map() keeps forward slashes in relative mode on every platform. Wrapping the expected in os_sep() rewrote it to backslashes on Windows only, so the [True] case failed there while [False] passed (assert_mapped canonicalizes the non-relative expected). Drop os_sep, matching the sibling test_wildcard with the same result.
Contributor
Author
|
The Windows failure was my test, not the change. In relative mode map() keeps the result's separator, and ./mysrc is forward slashed, so the output stays forward slashed on every platform. My expected value wrapped it in os_sep(), which flips to backslashes on Windows, so the [True] case failed there while [False] passed through canonical_filename first. I dropped the os_sep to match test_wildcard right above it. Pushed, CI should go green. |
nedbat
added a commit
that referenced
this pull request
Aug 19, 2026
Member
|
This is now released as part of coverage 7.16.0. |
1 task
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.
PathAliases.mapsubstitutes withstr.replace, so once a rule matches it rewrites every occurrence of the matched text, not just the part that matched:The second
/ci/srcis part of the file's real location, and it gets rewritten too. The separator normalisation on the next line then runs over the damage, which is where thevendor./mysrccomes from. Combining across machines is where this shows up, since the mapped path either fails theexistscheck and falls through to the next rule, or lands on the wrong file.The regex is anchored with
match, so slicing at the match bounds is the same thing the code already means.Two open PRs touch this file, #2120 and #2233, and both change which rule matches, not the substitution. Different line, different failure. Happy to rebase behind either if you would rather land those first.
Tests are 425 passing across
test_files.py,test_api.pyandtest_data.py. Reverting just thefiles.pyline fails the new test in both its relative and absolute forms and nothing else, with the skip count at 7 either way.