-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable the stability check with --line-ranges for now. #4034
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9d9b9f5
Disable the stability check with --line-ranges for now.
yilei 1a6206d
Oops, fix the test case after last minute new comment.
yilei 24193b3
Merge branch 'main' into b_4033
yilei c592688
Update the documentation of `--line-ranges`.
yilei 7366fc6
Update docs/usage_and_configuration/the_basics.md
yilei 54b650a
Reformat.
yilei File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# flags: --line-ranges=10-11 | ||
# NOTE: If you need to modify this file, pay special attention to the --line-ranges= | ||
# flag above as it's formatting specifically these lines. | ||
|
||
# Reproducible example for https://github.com/psf/black/issues/4033. | ||
# This can be fixed in the future if we use a better diffing algorithm, or make Black | ||
# perform formatting in a single pass. | ||
|
||
print ( "format me" ) | ||
print ( "format me" ) | ||
print ( "format me" ) | ||
print ( "format me" ) | ||
print ( "format me" ) | ||
|
||
# output | ||
# flags: --line-ranges=10-11 | ||
# NOTE: If you need to modify this file, pay special attention to the --line-ranges= | ||
# flag above as it's formatting specifically these lines. | ||
|
||
# Reproducible example for https://github.com/psf/black/issues/4033. | ||
# This can be fixed in the future if we use a better diffing algorithm, or make Black | ||
# perform formatting in a single pass. | ||
|
||
print ( "format me" ) | ||
print("format me") | ||
print("format me") | ||
print("format me") | ||
print("format me") |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these lines formatted? Shouldn't it only format the second and third prints?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is caused exactly by the diff algorithm used in
adjusted_lines
. In the second formatting pass, the adjusted lines becomes 12-13 but it should have stayed as 10-11.This PR doesn't fix this underlying issue (I'll file a separate issue if this PR is merged). Until it's really fixed, I'm proposing to skip the stability check (affected by the same issue) to avoid the crash.
The edge case is very rare in real code as it requires many same unformatted lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks. Maybe in that case we should put a warning in the docs for now about this bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree that this doesn't feel very likely in real code, though @tartley apparently did run into this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the doc.
@tartley can correct me, but #4033 appears to be a "toy" example for just trying out the new
--line-ranges
feature. #4052 can also serves the purpose of collecting real world example in case it happens.What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that I only encountered the problem using toy example code. By bad luck the toy example was the first thing I tried
--line-ranges
out on, while trying to integrate the use of it into my editor (e.g. so Vim would call Black on the selected range of lines). Although only a toy example it did genuinely confuse the heck out of me, and convinced me at the time that--line-ranges
wasn't working for me at all.