Mark first block before matching content as changed in line ranges mapping#4997
Open
Mark first block before matching content as changed in line ranges mapping#4997
Conversation
Collaborator
|
Thanks! Could you add a unit test for this behavior and a NEWS entry describing the user-visible change? |
Contributor
Author
|
Added both — unit test in test_ranges.py (test_first_block_changed) and a CHANGES.md entry under Stable style. The test verifies that changes in the first block before any matching content are correctly included in the adjusted line ranges. |
Collaborator
|
@bysiber Please review the test failures |
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.
In
_calculate_lines_mappings, when the firstmatching_blocksentry doesn't start at offset 0, the content before it is different between original and modified. This block should be marked asis_changed_block=True, but it's currently markedFalse.What goes wrong
The
adjusted_linesfunction usesis_changed_blockto decide how to remap line ranges:When the first changed block is mislabeled as unchanged, a linear offset is applied instead of block expansion. For example, if the original file has 5 lines changed at the top that become 3 lines after formatting, a
--line-ranges 1-5would compute the new range as(1, 5)via offset instead of the correct(1, 3)via block expansion. The range extends past the actual modified content.The
elsebranch (fori > 0) correctly marks inter-block gaps asis_changed_block=True— this first-block case was just missed.