summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_tokenize.py4
-rw-r--r--Lib/tokenize.py2
-rw-r--r--Misc/NEWS3
3 files changed, 8 insertions, 1 deletions
diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py
index 4e798d7..213e9b4 100644
--- a/Lib/test/test_tokenize.py
+++ b/Lib/test/test_tokenize.py
@@ -745,6 +745,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):
diff --git a/Lib/tokenize.py b/Lib/tokenize.py
index 0a53435..d669412 100644
--- a/Lib/tokenize.py
+++ b/Lib/tokenize.py
@@ -388,7 +388,7 @@ def detect_encoding(readline):
raise SyntaxError(msg)
if bom_found:
- if codec.name != 'utf-8':
+ if encoding != 'utf-8':
# This behaviour mimics the Python interpreter
if filename is None:
msg = 'encoding problem: utf-8'
diff --git a/Misc/NEWS b/Misc/NEWS
index 2d17eb3..d06ced8 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -23,6 +23,9 @@ Core and Builtins
Library
-------
+- Issue #14990: Correctly fail with SyntaxError on invalid encoding
+ declaration.
+
- Issue #14814: ipaddress now provides more informative error messages when
constructing instances directly (changes permitted during beta due to
provisional API status)