This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author diana
Recipients diana
Date 2017-10-01.15:08:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1506870513.15.0.213398074469.issue31657@psf.upfronthosting.co.za>
In-reply-to
Content
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;
History
Date User Action Args
2017-10-01 15:08:33dianasetrecipients: + diana
2017-10-01 15:08:33dianasetmessageid: <1506870513.15.0.213398074469.issue31657@psf.upfronthosting.co.za>
2017-10-01 15:08:33dianalinkissue31657 messages
2017-10-01 15:08:32dianacreate