Attempt to fix carriage return issues #4674
Draft
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.
Description
This is my attempt at fixing the carriage return problems. In combination with tusharsadhwani/pytokens#1 , this should fix the hypothesis errors around
\r
.I'm making both PRs drafts since my changes were made with the consideration of a sledgehammer, and were just focused on getting the issue to go away, so I'm uncertain if I've accidentally broken other things. All the black tests pass, as well as a local hypothesis run gave no problems, but I might have messed something up.
pytokens changes
My general change is based around the fact that I don't understand how you could fix
issue_128233
without making\r
s behave properly as newlines, so that's what this PR does. Ifissue_128233_handling
is enabled,\r
s are treated as newlines instead of whitespace.With this change, I came across issues where a lone
\r
newline would cause a double advance to happen, so I madeis_newline
return anint
with the length of chars that should be removed. This keeps the old behavior intact, since 0 is still falsey and 1/2 are truthy, but also allows the methods that depend on\r\n
handling to work correctly through checking if the result is 2.black changes
While working on the other hypothesis issues, I noticed that
\r
s weren't accounted for properly in the driver, so this adds those checks, leaving the\n
ones first to hopefully leave\r\n
behavior unchanged.I also have no clue how to handle the cross-repository things that would make the tests show as passing, since they don't have the full effects without the other repo's changes.
One other note, I wonder if it would be easier to side-step all these problems completely and normalize the newlines early like how CPython does, probably in
src/black/__init__.py:format_str
Checklist - did you ...
CHANGES.md
if necessary?