[New-bugs-announce] [issue42803] Traced line number is wrong for "if not __debug__"

Ned Batchelder report at bugs.python.org
Fri Jan 1 09:43:03 EST 2021


New submission from Ned Batchelder <ned at nedbatchelder.com>:

(Using CPython commit 6b1ac809b9)

This program never executes line 4, but the "if not __debug__" is partly attributed to line 4, giving an incorrect trace:

    for value in [True, False]:
        if value:
            if not __debug__:
                1/0 # line 4
        else:
            x = 6

Using a simple trace program (https://github.com/nedbat/coveragepy/blob/master/lab/run_trace.py), it produces this output:

    call <string> 1 @-1
        line <string> 1 @0
        line <string> 2 @8
        line <string> 3 @12
        line <string> 4 @14
        line <string> 1 @4
        line <string> 2 @8
        line <string> 6 @16
        line <string> 1 @4
        return <string> 1 @24

Various simplifications of the program make the problem go away.

----------
components: Interpreter Core
messages: 384178
nosy: Mark.Shannon, nedbat
priority: normal
severity: normal
status: open
title: Traced line number is wrong for "if not __debug__"
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42803>
_______________________________________


More information about the New-bugs-announce mailing list