[issue39114] Python 3.9.0a2 changed how finally/return is traced

Mark Shannon report at bugs.python.org
Sun Dec 29 13:40:50 EST 2019


Mark Shannon <mark at hotpy.org> added the comment:

Exammining the bytecode for:

def finally_return():
    try:
        return 14
    finally:
        a.append(16)

We have:

  2           0 SETUP_FINALLY           16 (to 18)

  3           2 POP_BLOCK

  5           4 LOAD_GLOBAL              0 (a)
              6 LOAD_METHOD              1 (append)
              8 LOAD_CONST               1 (16)
             10 CALL_METHOD              1
             12 POP_TOP

  3          14 LOAD_CONST               2 (14)

  5          16 RETURN_VALUE
        >>   18 LOAD_GLOBAL              0 (a)
             20 LOAD_METHOD              1 (append)
             22 LOAD_CONST               1 (16)
             24 CALL_METHOD              1
             26 POP_TOP
             28 RERAISE
             30 LOAD_CONST               0 (None)
             32 RETURN_VALUE

Which looks correct, except for the line number of the first RETURN_VALUE.

Looking at the compiler it seems that we aren't preserving the original line number when emitting code for the finally block.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39114>
_______________________________________


More information about the Python-bugs-list mailing list