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.

classification
Title: 3.10.0b3 doesn't trace line events for return in some cases
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Mark.Shannon Nosy List: Mark.Shannon, Sergey.Kirpichev, nedbat, pablogsal
Priority: Keywords: 3.10regression, patch

Created on 2021-07-05 22:29 by nedbat, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 27066 closed Mark.Shannon, 2021-07-08 13:21
PR 27067 merged Mark.Shannon, 2021-07-08 14:13
PR 27068 merged Mark.Shannon, 2021-07-08 14:19
Messages (9)
msg397024 - (view) Author: Ned Batchelder (nedbat) * (Python triager) Date: 2021-07-05 22:29
(from https://github.com/nedbat/coveragepy/issues/1184)

This code runs the return statement on line 17 twice.  The second time, there is a "line" event and then a "return" event for that line.  But the first time, there is only a "return" event:

--- 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 foo(x):
    if x:
        try:
            1/(x - 1)
        except ZeroDivisionError:
            pass

    return x

def test_foo():
    for i in range(2):
        foo(i)

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

I get this output with 3.10.0b3:

3.10.0b3 (default, Jun 18 2021, 06:43:38) [Clang 12.0.0 (clang-1200.0.32.29)]
call 19: def test_foo():
line 20:     for i in range(2):
line 21:         foo(i)
call 10: def foo(x):
line 11:     if x:
retu 17:     return x
line 20:     for i in range(2):
line 21:         foo(i)
call 10: def foo(x):
line 11:     if x:
line 12:         try:
line 13:             1/(x - 1)
exce 13:             1/(x - 1)
line 14:         except ZeroDivisionError:
line 15:             pass
line 17:     return x
retu 17:     return x
line 20:     for i in range(2):
retu 20:     for i in range(2):


Shouldn't there be a "line" event for both invocations?
msg397087 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-07-07 14:24
Mark, please take a look as beta4 is this week
msg397136 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-07-08 10:57
Gentle ping as beta 4 is in 2 days
msg397141 - (view) Author: Sergey B Kirpichev (Sergey.Kirpichev) * Date: 2021-07-08 13:25
Pablo, it seems: the 3.10 branch as for https://github.com/nedbat/coveragepy/issues/1184#issuecomment-873506523 still has this issue - I can reproduce one.
msg397148 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-07-08 16:23
Ned, 

I am reviewing today PR 27068 and PR 27067 but it would be a great help if you can confirm that **both** work for your cases and don't break anything else
msg397158 - (view) Author: Ned Batchelder (nedbat) * (Python triager) Date: 2021-07-08 17:59
I can confirm that those two pull requests fix the problem reported here.
msg397160 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-07-08 18:21
New changeset da6414f0acf5ec9ea3b07e4b3907bc49c2a61e2f by Mark Shannon in branch 'main':
bpo-44570: Fix line tracing for forwards jumps to duplicated tails (GH-27068)
https://github.com/python/cpython/commit/da6414f0acf5ec9ea3b07e4b3907bc49c2a61e2f
msg397161 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-07-08 18:21
New changeset 9f2c63b258846a95393b556fee5e1090173ea717 by Mark Shannon in branch '3.10':
bpo-44570: Fix line tracing for forward jumps to duplicated tails (GH-27067)
https://github.com/python/cpython/commit/9f2c63b258846a95393b556fee5e1090173ea717
msg397162 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-07-08 18:21
Awesome, thanks a lot for the quick resolution, Mark!
History
Date User Action Args
2022-04-11 14:59:47adminsetgithub: 88736
2021-07-13 13:25:58Mark.Shannonsetpull_requests: - pull_request25653
2021-07-13 13:23:06Mark.Shannonsetpull_requests: + pull_request25653
2021-07-08 18:21:46pablogsalsetmessages: + msg397162
2021-07-08 18:21:35pablogsalsetpriority: release blocker ->
status: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-07-08 18:21:26pablogsalsetmessages: + msg397161
2021-07-08 18:21:16pablogsalsetmessages: + msg397160
2021-07-08 17:59:37nedbatsetmessages: + msg397158
2021-07-08 16:23:05pablogsalsetmessages: + msg397148
2021-07-08 14:19:59Mark.Shannonsetpull_requests: + pull_request25621
2021-07-08 14:13:52Mark.Shannonsetpull_requests: + pull_request25620
2021-07-08 13:25:22Sergey.Kirpichevsetmessages: + msg397141
2021-07-08 13:21:36Mark.Shannonsetkeywords: + patch
stage: patch review
pull_requests: + pull_request25619
2021-07-08 12:56:43Mark.Shannonsetassignee: Mark.Shannon
2021-07-08 10:57:13pablogsalsetmessages: + msg397136
2021-07-07 14:24:09pablogsalsetmessages: + msg397087
2021-07-07 14:23:54pablogsalsetpriority: normal -> release blocker
nosy: + pablogsal
2021-07-06 02:57:20Sergey.Kirpichevsetnosy: + Sergey.Kirpichev
2021-07-05 22:29:38nedbatcreate