Skip to content

Commit 8f3381c

Browse files
author
Guido van Rossum
committed
Improve coding cookie regex based on Serhiy's advice, with new test.
1 parent 506f464 commit 8f3381c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

mypy/test/data/parse-errors.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,14 @@ file:2: error: Unknown encoding 'uft8'
481481
[out]
482482
file:4: error: Unrecognized character
483483

484+
[case testDoubleEncoding4]
485+
486+
487+
# coding: ascii
488+
á = 1
489+
[out]
490+
file:4: error: Unrecognized character
491+
484492
[case testLongLiteralInPython3]
485493
2L
486494
0x2L

mypy/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
T = TypeVar('T')
99

10-
ENCODING_RE = re.compile(br'(\s*#.*(\r\n?|\n)){0,1}?\s*#.*coding[:=]\s*([-\w.]+)')
10+
ENCODING_RE = re.compile(br'([ \t\v]*#.*(\r\n?|\n))??[ \t\v]*#.*coding[:=][ \t]*([-\w.]+)')
1111

1212
default_python2_interpreter = ['python2', 'python', '/usr/bin/python']
1313

0 commit comments

Comments
 (0)