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.11: except/else/if/raise traced incorrectly
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Mark.Shannon, iritkatriel, nedbat
Priority: normal Keywords: 3.11regression, patch

Created on 2022-01-11 13:10 by nedbat, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30544 merged iritkatriel, 2022-01-11 17:50
Messages (4)
msg410300 - (view) Author: Ned Batchelder (nedbat) * (Python triager) Date: 2022-01-11 13:10
This code shows a raise inside an except/else/if that isn't run, but incorrectly appears in the trace output (see the ***** line):


$ cat arcs_1160.py
def func(x):
    try:
        b = 6
    except ZeroDivisionError:
        pass
    else:
        if x == "raise":
            raise ValueError()
    finally:
        f = 23

func("other")

$ python3.10 -c "import sys; print(sys.version)"
3.10.1 (main, Dec 14 2021, 08:30:13) [Clang 12.0.0 (clang-1200.0.32.29)]

$ python3.10 -m trace --trace arcs_1160.py
 --- modulename: arcs_1160, funcname: <module>
arcs_1160.py(1): def func(x):
arcs_1160.py(12): func("other")
 --- modulename: arcs_1160, funcname: func
arcs_1160.py(2):     try:
arcs_1160.py(3):         b = 6
arcs_1160.py(7):         if x == "raise":
arcs_1160.py(10):         f = 23

$ python3.11 -c "import sys; print(sys.version)"
3.11.0a3+ (heads/main:d24cd49acb, Jan 11 2022, 07:29:41) [Clang 12.0.0 (clang-1200.0.32.29)]

$ python3.11 -m trace --trace arcs_1160.py
 --- modulename: arcs_1160, funcname: <module>
arcs_1160.py(1): def func(x):
arcs_1160.py(12): func("other")
 --- modulename: arcs_1160, funcname: func
arcs_1160.py(2):     try:
arcs_1160.py(3):         b = 6
arcs_1160.py(7):         if x == "raise":
arcs_1160.py(8):             raise ValueError()      <<**********
arcs_1160.py(10):         f = 23
msg410317 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-01-11 17:02
Thanks, I have a fix and will make a PR once I've written the test.
msg410487 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-01-13 12:34
New changeset 9c2ebb906d1c68c3d571b100c92ceb08805b94cd by Irit Katriel in branch 'main':
bpo-46344: Fix trace bug in else of try and try-star blocks (GH-30544)
https://github.com/python/cpython/commit/9c2ebb906d1c68c3d571b100c92ceb08805b94cd
msg410488 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-01-13 12:35
Thank you Ned.
History
Date User Action Args
2022-04-11 14:59:54adminsetgithub: 90502
2022-01-13 12:35:02iritkatrielsetstatus: open -> closed
resolution: fixed
messages: + msg410488

stage: patch review -> resolved
2022-01-13 12:34:41iritkatrielsetmessages: + msg410487
2022-01-11 17:50:25iritkatrielsetkeywords: + patch
stage: patch review
pull_requests: + pull_request28742
2022-01-11 17:02:27iritkatrielsetmessages: + msg410317
2022-01-11 14:07:20Mark.Shannonsetnosy: + iritkatriel
2022-01-11 13:10:52nedbatcreate