Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fed2c51

Browse files
committed
Merge branch
2 parents 36f8dcd + 11f0b41 commit fed2c51

3 files changed

Lines changed: 8 additions & 1 deletion

File tree

Lib/test/test_tokenize.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,10 @@ def test_utf8_coding_cookie_and_utf8_bom(self):
745745
f = 'tokenize_tests-utf8-coding-cookie-and-utf8-bom-sig.txt'
746746
self.assertTrue(self._testFile(f))
747747

748+
def test_bad_coding_cookie(self):
749+
self.assertRaises(SyntaxError, self._testFile, 'bad_coding.py')
750+
self.assertRaises(SyntaxError, self._testFile, 'bad_coding2.py')
751+
748752

749753
class Test_Tokenize(TestCase):
750754

Lib/tokenize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ def find_cookie(line):
388388
raise SyntaxError(msg)
389389

390390
if bom_found:
391-
if codec.name != 'utf-8':
391+
if encoding != 'utf-8':
392392
# This behaviour mimics the Python interpreter
393393
if filename is None:
394394
msg = 'encoding problem: utf-8'

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ Core and Builtins
2323
Library
2424
-------
2525

26+
- Issue #14990: Correctly fail with SyntaxError on invalid encoding
27+
declaration.
28+
2629
- Issue #14814: ipaddress now provides more informative error messages when
2730
constructing instances directly (changes permitted during beta due to
2831
provisional API status)

0 commit comments

Comments
 (0)