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 nedbat
Recipients Mark.Shannon, nedbat
Date 2021-08-05.13:11:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1628169100.37.0.353483963834.issue44840@roundup.psfhosted.org>
In-reply-to
Content
Note: this is very similar to https://bugs.python.org/issue42810
This was originally reported against coverage.py: https://github.com/nedbat/coveragepy/issues/1205

---8<-------------
import linecache, sys

def trace(frame, event, arg):
    # The weird globals here is to avoid a NameError on shutdown...
    if frame.f_code.co_filename == globals().get("__file__"):
        lineno = frame.f_lineno
        print("{} {}: {}".format(event[:4], lineno, linecache.getline(__file__, lineno).rstrip()))
    return trace

print(sys.version)
sys.settrace(trace)

def func():
    if A:
        if B:
            if C:
                if D:
                    return False
        else:
            return False
    elif E and F:
        return True

A = B = True
C = False

func()
-------------------------

This produces this trace output:

3.10.0rc1 (default, Aug  3 2021, 15:03:55) [Clang 12.0.0 (clang-1200.0.32.29)]
call 13: def func():
line 14:     if A:
line 15:         if B:
line 16:             if C:
line 21:     elif E and F:
retu 21:     elif E and F:

The elif on line 21 is not executed, and should not be traced.

Also, if I change line 21 to `elif E:`, then the trace changes to:

3.10.0rc1 (default, Aug  3 2021, 15:03:55) [Clang 12.0.0 (clang-1200.0.32.29)]
call 13: def func():
line 14:     if A:
line 15:         if B:
line 16:             if C:
line 22:         return True
retu 22:         return True
History
Date User Action Args
2021-08-05 13:11:40nedbatsetrecipients: + nedbat, Mark.Shannon
2021-08-05 13:11:40nedbatsetmessageid: <1628169100.37.0.353483963834.issue44840@roundup.psfhosted.org>
2021-08-05 13:11:40nedbatlinkissue44840 messages
2021-08-05 13:11:40nedbatcreate