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

Guido van Rossum report at bugs.python.org
Sun Apr 3 14:28:42 EDT 2022


Guido van Rossum <guido at python.org> added the comment:

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

I simply don't believe it can always do that correctly, so I believe it should not do it.

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

No, but if they are wrong crashes might happen when they are consulted. At the very least they would confuse users.

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

No. There are a zillion use cases. If you are using .replace() you are taking responsibility for the result.

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

Where would these people get the value that they're using to replace co_code? Surely if they are generating bytecode it will already be broken. Pretty much all instructions are different in 3.11.

----------

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


More information about the Python-bugs-list mailing list