Skip to content

Commit

Permalink
merge heads
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminp committed Sep 14, 2016
2 parents 59e5e0d + e907885 commit 1f28a47
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Lib/test/test_zipimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,19 @@ def get_file():
"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
Expand Down
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion Modules/zipimport.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1f28a47

Please sign in to comment.