Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Handle `# fmt: skip` followed by a comment at the end of file (#4635)
- Fix crash when a tuple appears in the `as` clause of a `with` statement (#4634)
- Fix crash when tuple is used as a context manager inside a `with` statement (#4646)
- Fix issues/crashes caused by lack of carriage return checks (#4674)

### Preview style

Expand Down
6 changes: 4 additions & 2 deletions src/blib2to3/pgen2/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def parse_tokens(self, tokens: Iterable[TokenInfo], debug: bool = False) -> NL:
if type in (tokenize.COMMENT, tokenize.NL):
prefix += value
lineno, column = end
if value.endswith("\n"):
if value.endswith("\n") or value.endswith("\r"):
lineno += 1
column = 0
continue
Expand Down Expand Up @@ -170,7 +170,9 @@ def parse_tokens(self, tokens: Iterable[TokenInfo], debug: bool = False) -> NL:
lineno, column = end
# FSTRING_MIDDLE is the only token that can end with a newline, and
# `end` will point to the next line. For that case, don't increment lineno.
if value.endswith("\n") and type != token.FSTRING_MIDDLE:
if (
value.endswith("\n") or value.endswith("\r")
) and type != token.FSTRING_MIDDLE:
lineno += 1
column = 0
else:
Expand Down
Loading