Skip to content

Commit 372cb61

Browse files
authored
Merge pull request #1040 from asottile/315-hax
vendor cookie_re from cpython
2 parents afcce08 + fb9f503 commit 372cb61

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pyupgrade/_main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ def _fix_encode_to_binary(tokens: list[Token], i: int) -> None:
276276
del tokens[victims]
277277

278278

279+
# copied from 3.15 @ 0ac890bea7
280+
_cookie_re = re.compile(r'^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)', re.ASCII)
281+
282+
279283
def _fix_tokens(contents_text: str) -> str:
280284
try:
281285
tokens = src_to_tokens(contents_text)
@@ -294,7 +298,7 @@ def _fix_tokens(contents_text: str) -> str:
294298
token.utf8_byte_offset == 0 and
295299
token.line < 3 and
296300
token.name == 'COMMENT' and
297-
tokenize.cookie_re.match(token.src)
301+
_cookie_re.match(token.src)
298302
):
299303
del tokens[i]
300304
assert tokens[i].name == 'NL', tokens[i].name

0 commit comments

Comments
 (0)