Issue #14990: tokenize: correctly fail with SyntaxError on invalid encoding declaration.
This commit is contained in:
parent
9235b254dc
commit
11f0b41e9d
|
@ -674,6 +674,10 @@ class TestTokenizerAdheresToPep0263(TestCase):
|
|||
f = 'tokenize_tests-utf8-coding-cookie-and-utf8-bom-sig.txt'
|
||||
self.assertTrue(self._testFile(f))
|
||||
|
||||
def test_bad_coding_cookie(self):
|
||||
self.assertRaises(SyntaxError, self._testFile, 'bad_coding.py')
|
||||
self.assertRaises(SyntaxError, self._testFile, 'bad_coding2.py')
|
||||
|
||||
|
||||
class Test_Tokenize(TestCase):
|
||||
|
||||
|
|
|
@ -310,7 +310,7 @@ def detect_encoding(readline):
|
|||
raise SyntaxError("unknown encoding: " + encoding)
|
||||
|
||||
if bom_found:
|
||||
if codec.name != 'utf-8':
|
||||
if encoding != 'utf-8':
|
||||
# This behaviour mimics the Python interpreter
|
||||
raise SyntaxError('encoding problem: utf-8')
|
||||
encoding += '-sig'
|
||||
|
|
Loading…
Reference in New Issue