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-07-19.12:03:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1626696193.12.0.565896913641.issue44672@roundup.psfhosted.org>
In-reply-to
Content
A simple function with a last "pass" statement gets traced incorrectly, attributing the return to the pass instead of the actual last statement executed:

--- 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

def wrong_loop(x):
    if x:
        if x:
            print(4)
    else:
        pass

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

wrong_loop(8)
----------------------------------

On 3.9 and before, this produces:

3.9.5 (default, May  5 2021, 06:50:43)
[Clang 12.0.0 (clang-1200.0.32.29)]
call 10: def wrong_loop(x):
line 11:     if x:
line 12:         if x:
line 13:             print(4)
4
line 15:         pass
retu 15:         pass

Partly I'm writing this issue to record the problem, but partly to get a decision: will there be fixes made to 3.9 (or before) for issues like this?
History
Date User Action Args
2021-07-19 12:03:13nedbatsetrecipients: + nedbat, Mark.Shannon
2021-07-19 12:03:13nedbatsetmessageid: <1626696193.12.0.565896913641.issue44672@roundup.psfhosted.org>
2021-07-19 12:03:13nedbatlinkissue44672 messages
2021-07-19 12:03:12nedbatcreate