Fix backslash carriage return comments #4663
Open
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
Fixes a
\
followed by a\r
followed by a comment causing the comment to be deleted. This also fixes Hypothesis failing the CI. This originally went under the radar since the old tokenizer largely didn't support carriage returns, so this example would crash witherror: cannot format <string>: Cannot parse for target version Python 3.13: 1:4: try:\
before getting to linegen. The new tokenizer supports carriage returns much better, and so this issue was revealed. I'm not sure why Hypothesis didn't catch this on the original tokenizer switch PR.The fix is very simple, the splitting regex for comment finding only accounted for
\r\n
and\n
, not a lone\r
. This PR adds\r
as a valid case to the regex.I added the test case to
test_black.py
instead of the cases because git would normalize the\r
s on checkout, and it's very hard in most editors to deal with\r
vs\r\n
vs\n
. While I was there I also added two of the older\r
problematic examples as tests too.Checklist - did you ...
CHANGES.md
if necessary?