Skip to content

Commit 1f28a47

Browse files
committed
merge heads
2 parents 59e5e0d + e907885 commit 1f28a47

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

Lib/test/test_zipimport.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,19 @@ def get_file():
513513
"some.data": (NOW, "some data")}
514514
self.doTest(pyc_ext, files, TESTMOD)
515515

516+
def testDefaultOptimizationLevel(self):
517+
# zipimport should use the default optimization level (#28131)
518+
src = """if 1: # indent hack
519+
def test(val):
520+
assert(val)
521+
return val\n"""
522+
files = {TESTMOD + '.py': (NOW, src)}
523+
self.makeZip(files)
524+
sys.path.insert(0, TEMP_ZIP)
525+
mod = importlib.import_module(TESTMOD)
526+
self.assertEqual(mod.test(1), 1)
527+
self.assertRaises(AssertionError, mod.test, False)
528+
516529
def testImport_WithStuff(self):
517530
# try importing from a zipfile which contains additional
518531
# stuff at the beginning of the file

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Release date: TBA
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #28131: Fix a regression in zipimport's compile_source(). zipimport
14+
should use the same optimization level as the interpreter.
15+
1316
- Issue #25221: Fix corrupted result from PyLong_FromLong(0) when
1417
Python is compiled with NSMALLPOSINTS = 0.
1518

Modules/zipimport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ compile_source(PyObject *pathname, PyObject *source)
13701370
}
13711371

13721372
code = Py_CompileStringObject(PyBytes_AsString(fixed_source),
1373-
pathname, Py_file_input, NULL, 1);
1373+
pathname, Py_file_input, NULL, -1);
13741374

13751375
Py_DECREF(fixed_source);
13761376
return code;

0 commit comments

Comments
 (0)