[Python-checkins] cpython (merge 3.2 -> default): Merge branch

florent.xicluna python-checkins at python.org
Sat Jul 7 12:27:16 CEST 2012


http://hg.python.org/cpython/rev/b4322ad1fec4
changeset:   77962:b4322ad1fec4
parent:      77960:16ff4889a858
parent:      77961:5020afc0b7c9
user:        Florent Xicluna <florent.xicluna at gmail.com>
date:        Sat Jul 07 12:26:56 2012 +0200
summary:
  Merge branch

files:
  Lib/test/test_tokenize.py |  4 ++++
  Lib/tokenize.py           |  2 +-
  Misc/NEWS                 |  3 +++
  3 files changed, 8 insertions(+), 1 deletions(-)


diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py
--- a/Lib/test/test_tokenize.py
+++ b/Lib/test/test_tokenize.py
@@ -745,6 +745,10 @@
         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
--- a/Lib/tokenize.py
+++ b/Lib/tokenize.py
@@ -388,7 +388,7 @@
             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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -23,6 +23,9 @@
 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)

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list