Skip to content
Merged
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
6 changes: 5 additions & 1 deletion pyupgrade/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ def _fix_encode_to_binary(tokens: list[Token], i: int) -> None:
del tokens[victims]


# copied from 3.15 @ 0ac890bea7
_cookie_re = re.compile(r'^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)', re.ASCII)


def _fix_tokens(contents_text: str) -> str:
try:
tokens = src_to_tokens(contents_text)
Expand All @@ -294,7 +298,7 @@ def _fix_tokens(contents_text: str) -> str:
token.utf8_byte_offset == 0 and
token.line < 3 and
token.name == 'COMMENT' and
tokenize.cookie_re.match(token.src)
_cookie_re.match(token.src)
):
del tokens[i]
assert tokens[i].name == 'NL', tokens[i].name
Expand Down