[Python-checkins] cpython (merge 3.5 -> 3.6): Issue #28131: Merge from 3.5

berker.peksag python-checkins at python.org
Wed Sep 14 01:10:29 EDT 2016


https://hg.python.org/cpython/rev/7a6c0c4e6072
changeset:   103777:7a6c0c4e6072
branch:      3.6
parent:      103773:9e8e15993aae
parent:      103776:7bec326972f5
user:        Berker Peksag <berker.peksag at gmail.com>
date:        Wed Sep 14 08:10:45 2016 +0300
summary:
  Issue #28131: Merge from 3.5

files:
  Lib/test/test_zipimport.py |  13 +++++++++++++
  Misc/NEWS                  |   3 +++
  Modules/zipimport.c        |   2 +-
  3 files changed, 17 insertions(+), 1 deletions(-)


diff --git a/Lib/test/test_zipimport.py b/Lib/test/test_zipimport.py
--- a/Lib/test/test_zipimport.py
+++ b/Lib/test/test_zipimport.py
@@ -532,6 +532,19 @@
                  "some.data": (NOW, "some data")}
         self.doTest(pyc_ext, files, TESTMOD)
 
+    def testDefaultOptimizationLevel(self):
+        # zipimport should use the default optimization level (#28131)
+        src = """if 1:  # indent hack
+        def test(val):
+            assert(val)
+            return val\n"""
+        files = {TESTMOD + '.py': (NOW, src)}
+        self.makeZip(files)
+        sys.path.insert(0, TEMP_ZIP)
+        mod = importlib.import_module(TESTMOD)
+        self.assertEqual(mod.test(1), 1)
+        self.assertRaises(AssertionError, mod.test, False)
+
     def testImport_WithStuff(self):
         # try importing from a zipfile which contains additional
         # stuff at the beginning of the file
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
 Core and Builtins
 -----------------
 
+- Issue #28131: Fix a regression in zipimport's compile_source().  zipimport
+  should use the same optimization level as the interpreter.
+
 - Issue #28126: Replace Py_MEMCPY with memcpy(). Visual Studio can properly
   optimize memcpy().
 
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -1370,7 +1370,7 @@
     }
 
     code = Py_CompileStringObject(PyBytes_AsString(fixed_source),
-                                  pathname, Py_file_input, NULL, 1);
+                                  pathname, Py_file_input, NULL, -1);
 
     Py_DECREF(fixed_source);
     return code;

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


More information about the Python-checkins mailing list