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, pablogsal, serhiy.storchaka, xtreak
Date 2019-12-30.12:39:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1577709594.35.0.153744629745.issue39114@roundup.psfhosted.org>
In-reply-to
Content
Thanks, that fixes the original case in this issue.

Here is another problem which seems related enough to append here instead of opening a new issue:

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

def trace(frame, event, arg):
    lineno = frame.f_lineno
    print("{} {}: {}".format(event[:4], lineno, linecache.getline(__file__, lineno).rstrip()))
    return trace

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

def b(exc):
    print("exc is {!r}".format(exc))
    try:
        raise Exception(exc)
    except Exception as e:
        if exc != 'expected':
            raise                   # line 17
        q = "removing this line changes the behavior"
        r = "is this executed?"     # line 19
    return

b('expected')
try:
    b('unexpected')
except:
    pass
--- 8< ----------------------------------------------------

With your fix, it reports that the raise on line 17 is followed by line 19, which can't be right:

3.9.0a2+ (heads/pr/17737:f2545467fa, Dec 29 2019, 15:38:57)
[Clang 10.0.0 (clang-1000.10.44.4)]
call 11: def b(exc):
line 12:     print("exc is {!r}".format(exc))
exc is 'expected'
line 13:     try:
line 14:         raise Exception(exc)
exce 14:         raise Exception(exc)
line 15:     except Exception as e:
line 16:         if exc != 'expected':
line 18:         q = "removing this line changes the behavior"
line 19:         r = "is this executed?"
line 20:     return
retu 20:     return
call 11: def b(exc):
line 12:     print("exc is {!r}".format(exc))
exc is 'unexpected'
line 13:     try:
line 14:         raise Exception(exc)
exce 14:         raise Exception(exc)
line 15:     except Exception as e:
line 16:         if exc != 'expected':
line 17:             raise
line 19:         r = "is this executed?"
retu 19:         r = "is this executed?"


Python 3.8 reported this:

3.8.1 (default, Dec 19 2019, 08:38:38)
[Clang 10.0.0 (clang-1000.10.44.4)]
call 11: def b(exc):
line 12:     print("exc is {!r}".format(exc))
exc is 'expected'
line 13:     try:
line 14:         raise Exception(exc)
exce 14:         raise Exception(exc)
line 15:     except Exception as e:
line 16:         if exc != 'expected':
line 18:         q = "removing this line changes the behavior"
line 19:         r = "is this executed?"
line 20:     return
retu 20:     return
call 11: def b(exc):
line 12:     print("exc is {!r}".format(exc))
exc is 'unexpected'
line 13:     try:
line 14:         raise Exception(exc)
exce 14:         raise Exception(exc)
line 15:     except Exception as e:
line 16:         if exc != 'expected':
line 17:             raise
retu 17:             raise
History
Date User Action Args
2019-12-30 12:39:54nedbatsetrecipients: + nedbat, Mark.Shannon, serhiy.storchaka, pablogsal, xtreak
2019-12-30 12:39:54nedbatsetmessageid: <1577709594.35.0.153744629745.issue39114@roundup.psfhosted.org>
2019-12-30 12:39:54nedbatlinkissue39114 messages
2019-12-30 12:39:54nedbatcreate