]> granicus.if.org Git - python/commitdiff
Issue #28131: Fix a regression in zipimport's compile_source()
authorBerker Peksag <berker.peksag@gmail.com>
Wed, 14 Sep 2016 05:09:48 +0000 (08:09 +0300)
committerBerker Peksag <berker.peksag@gmail.com>
Wed, 14 Sep 2016 05:09:48 +0000 (08:09 +0300)
zipimport should use the same optimization level as the interpreter.

Lib/test/test_zipimport.py
Misc/NEWS
Modules/zipimport.c

index 2bb7230c26af03dde46ceaa192e349419a9dedeb..d5b3b22ae1d70287fa197dcc96c7f6a840fb6260 100644 (file)
@@ -513,6 +513,19 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
                  "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
index 246ac72e9f9e933c22a70be7b6b823f67579b67a..e61e98b9c7ed7dafb55e892634ac126bb211ed45 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ Release date: TBA
 Core and Builtins
 -----------------
 
+- Issue #28131: Fix a regression in zipimport's compile_source().  zipimport
+  should use the same optimization level as the interpreter.
+
 - Issue #25221: Fix corrupted result from PyLong_FromLong(0) when
   Python is compiled with NSMALLPOSINTS = 0.
 
index 92a82e6df269bb41f35ee48e3d5c33eed24c9219..7473a8fe8778756bcba2fab3eec9e2c2c72d5c77 100644 (file)
@@ -1370,7 +1370,7 @@ compile_source(PyObject *pathname, PyObject *source)
     }
 
     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;