(original) (raw)
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 @@ -527,16 +527,29 @@ class UncompressedZipImportTestCase(Impo return __file__ if __loader__.get_data("some.data") != b"some data": raise AssertionError("bad data")\n""" pyc = make_pyc(compile(src, "", "exec"), NOW, len(src)) files = {TESTMOD + pyc_ext: (NOW, pyc), "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 files = {TESTMOD + ".py": (NOW, test_src)} self.doTest(".py", files, TESTMOD, stuff=b"Some Stuff"*31) def assertModuleSource(self, module): diff --git a/Modules/zipimport.c b/Modules/zipimport.c --- a/Modules/zipimport.c +++ b/Modules/zipimport.c @@ -1365,17 +1365,17 @@ compile_source(PyObject *pathname, PyObj PyObject *code, *fixed_source; fixed_source = normalize_line_endings(source); if (fixed_source == NULL) { return NULL; } 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; } /* Convert the date/time values found in the Zip archive to a value that's compatible with the time stamp stored in .pyc files. */ static time_t