[issue31657] unit test for optimization levels does not cover __debug__ case
diana
report at bugs.python.org
Sun Oct 1 11:08:33 EDT 2017
New submission from diana <diana.joan.clarke at gmail.com>:
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;
----------
messages: 303465
nosy: diana
priority: normal
severity: normal
status: open
title: unit test for optimization levels does not cover __debug__ case
type: enhancement
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31657>
_______________________________________
More information about the Python-bugs-list
mailing list