Skip to content

Fix backslash carriage return comments #4663

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

MeGaGiGaGon
Copy link
Collaborator

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 with error: 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 \rs 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 ...

  • Add an entry in CHANGES.md if necessary?
  • Add / update tests if necessary?
  • Add new / update outdated documentation?
    • N/A, documentation not affected

Co-authored-by: Jelle Zijlstra <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants