[pypy-commit] pypy py3.6: issue #3000: fix -O removing asserts on pypy3
cfbolz
pypy.commits at gmail.com
Tue Apr 16 16:52:23 EDT 2019
Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch: py3.6
Changeset: r96508:8cc60ea707b3
Date: 2019-04-16 22:44 +0200
http://bitbucket.org/pypy/pypy/changeset/8cc60ea707b3/
Log: issue #3000: fix -O removing asserts on pypy3
diff --git a/pypy/interpreter/astcompiler/codegen.py b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -509,8 +509,7 @@
return
self.update_position(asrt.lineno)
end = self.new_block()
- if self.compile_info.optimize != 0:
- self.emit_jump(ops.JUMP_IF_NOT_DEBUG, end)
+ self.emit_jump(ops.JUMP_IF_NOT_DEBUG, end)
asrt.test.accept_jump_if(self, True, end)
self.emit_op_name(ops.LOAD_GLOBAL, self.names, "AssertionError")
if asrt.msg:
diff --git a/pypy/interpreter/test/test_zpy.py b/pypy/interpreter/test/test_zpy.py
--- a/pypy/interpreter/test/test_zpy.py
+++ b/pypy/interpreter/test/test_zpy.py
@@ -84,7 +84,28 @@
# test 3 : additionnal pypy parameters
output = run(sys.executable, pypypath, '-S', "-O", tmpfilepath, "hello")
assert output.splitlines()[-1] == str([tmpfilepath,'hello'])
-
+
+def test_optimize_removes_assert():
+ tmpfilepath = str(udir.join("test_assert.py"))
+ tmpfile = file(tmpfilepath, "w")
+ tmpfile.write("""
+try:
+ assert 0
+except AssertionError:
+ print("AssertionError")
+else:
+ print("nothing")
+""")
+ tmpfile.close()
+
+ # no optimization: crashes
+ output = run(sys.executable, pypypath, '-S', tmpfilepath)
+ assert "AssertionError" in output
+
+ # optimization: just works
+ output = run(sys.executable, pypypath, '-SO', tmpfilepath)
+ assert "nothing" in output
+
TB_NORMALIZATION_CHK= """
class K(object):
More information about the pypy-commit
mailing list