Message303465
There are currently three supported optimization levels (0, 1, and 2). Briefly summarized, they do the following.
0: no optimizations
1: remove assert statements and __debug__ blocks
2: remove docstrings, assert statements, and __debug__ blocks
The current compile() tests for optimization levels in Lib/test/test_builtin.py covers the assert and docstring cases, but it doesn't test that __debug__ code blocks are included or excluded based on the optimization level.
For example, if you change Python/compile.c to always include __debug__ blocks regardless of the optimization level, the existing compile() tests will continue to pass.
$ git diff Python/compile.c
diff --git a/Python/compile.c b/Python/compile.c
index 280ddc39e3..d65df098bb 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -4143,7 +4143,7 @@ expr_constant(struct compiler *c, expr_ty e)
/* optimize away names that can't be reassigned */
id = PyUnicode_AsUTF8(e->v.Name.id);
if (id && strcmp(id, "__debug__") == 0)
- return !c->c_optimize;
+ return 1;
return -1;
case NameConstant_kind: {
PyObject *o = e->v.NameConstant.value; |
|
Date |
User |
Action |
Args |
2017-10-01 15:08:33 | diana | set | recipients:
+ diana |
2017-10-01 15:08:33 | diana | set | messageid: <1506870513.15.0.213398074469.issue31657@psf.upfronthosting.co.za> |
2017-10-01 15:08:33 | diana | link | issue31657 messages |
2017-10-01 15:08:32 | diana | create | |
|