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 vstinner
Recipients Mark.Shannon, dom1310df, gregory.p.smith, gvanrossum, vstinner
Date 2022-04-05.22:59:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1649199594.16.0.250703589968.issue47185@roundup.psfhosted.org>
In-reply-to
Content
>>> def f():
...     foo()
...     try:
...         bar()
...     except:
...         pass
... 
>>> def g():
...     try:
...         foo()
...         bar()
...     except:
...         pass
... 

>>> dis.dis(f)
  1           0 RESUME                   0

  2           2 LOAD_GLOBAL              1 (NULL + foo)
             14 PRECALL                  0
             18 CALL                     0
             28 POP_TOP

  3          30 NOP

  4          32 LOAD_GLOBAL              3 (NULL + bar)
             44 PRECALL                  0
             48 CALL                     0
             58 POP_TOP
             60 LOAD_CONST               0 (None)
             62 RETURN_VALUE
        >>   64 PUSH_EXC_INFO

  5          66 POP_TOP

  6          68 POP_EXCEPT
             70 LOAD_CONST               0 (None)
             72 RETURN_VALUE
        >>   74 COPY                     3
             76 POP_EXCEPT
             78 RERAISE                  1
ExceptionTable:
  32 to 58 -> 64 [0]
  64 to 66 -> 74 [1] lasti

>>> dis.dis(g)
  1           0 RESUME                   0

  2           2 NOP

  3           4 LOAD_GLOBAL              1 (NULL + foo)
             16 PRECALL                  0
             20 CALL                     0
             30 POP_TOP

  4          32 LOAD_GLOBAL              3 (NULL + bar)
             44 PRECALL                  0
             48 CALL                     0
             58 POP_TOP
             60 LOAD_CONST               0 (None)
             62 RETURN_VALUE
        >>   64 PUSH_EXC_INFO

  5          66 POP_TOP

  6          68 POP_EXCEPT
             70 LOAD_CONST               0 (None)
             72 RETURN_VALUE
        >>   74 COPY                     3
             76 POP_EXCEPT
             78 RERAISE                  1
ExceptionTable:
  4 to 58 -> 64 [0]
  64 to 66 -> 74 [1] lasti


Oh, I didn't follow recent bytecode changes. Ok, now I see that it is not longer possible to build the exception table just from the bytecode. The purpose of the exception table is to handle exceptions: the opcodes related to exception handles are simply gone in Python 3.11.

I was thinking about looking for things like PUSH_EXC_INFO or POP_EXCEPT, but as Guido shows, it doesn't work: the start of the "try" block cannot be detected in the bytecode anymore in Python 3.11.


> If code.replace() is not updated to recompute co_exceptiontable, at least, it would be nice to document the bpo-40222 changes in What's New in Python 3.11 and in the CodeType documentation

You closed the issue. I understand that you don't want to document CodeType.replace() changes neither. Users of this API should follow Python development and notice that their code no longer works with Python 3.11.
History
Date User Action Args
2022-04-05 22:59:54vstinnersetrecipients: + vstinner, gvanrossum, gregory.p.smith, Mark.Shannon, dom1310df
2022-04-05 22:59:54vstinnersetmessageid: <1649199594.16.0.250703589968.issue47185@roundup.psfhosted.org>
2022-04-05 22:59:54vstinnerlinkissue47185 messages
2022-04-05 22:59:54vstinnercreate