STINNER Victor <vstin...@python.org> added the comment:

>>> 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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue47185>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to