[issue47185] code.replace(co_code=new_code) no longer catch exceptions on Python 3.11

STINNER Victor report at bugs.python.org
Fri Apr 1 16:38:46 EDT 2022


STINNER Victor <vstinner at python.org> added the comment:

Guido (msg416498)
> Surely the bigger issue is that the contents of new_code itself must be totally different? Also there are other tables that need to be adjusted if you really do change co_code, e.g. the debugging tables.

Do you consider that .replace() must reject changing co_code if other tables are not updated?

Debugging tables are not strictly required just to *execute* code, no?

If you consider that the caller *must* update co_exceptiontable, replace() must raise an exception in this case, to prevent creating a code object which would behave in a strange way (broken exception handling).

If someone really wants testing an empty exception table just for fun, it would still be possible to pass co_exceptiontable=b''.

My concern is more about people upgrading to Python 3.11 and who "suddenly" don't get their exceptions handled anymore. I would prefer catching such bug at the replace() call, rather than having to execute the code (and only notice the bug in production? oops).

----------

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


More information about the Python-bugs-list mailing list