Message357175
Fabio,
Can you give me a specific example where changing the bytecode via the `__code__` attribute of a function does not work as expected?
I am assuming that adding a breakpoint on a line is equivalent to adding `breakpoint();` at the beginning of that line. If the bytecode of a function is modified dynamically, say by a decorator, then it is unclear what should be done, and it is hard to claim that any particular approach is more correct.
However, assuming that the change is well defined and keeps the mapping to the original code, then adding a breakpoint to the modified code should work just as well before or after modification.
As an example, consider http://code.activestate.com/recipes/277940-decorator-for-bindingconstants-at-compile-time/ which provides a means of converting global variable reads to constants. In that case the order in which the decorator and breakpoint insertion are applied shouldn't matter.
I propose a new method on code objects `withCallAtLine(callable: Callable[], line:int)` which returns a new code object with calls to the given callable at the given line.
A breakpoint can then be inserted at line L in function f with `f.__code__ = f.__code__.withCallAtLine(sys.breakpoint, L)`. |
|
Date |
User |
Action |
Args |
2019-11-21 15:08:06 | Mark.Shannon | set | recipients:
+ Mark.Shannon, brett.cannon, vstinner, fabioz, dino.viehland, eric.snow |
2019-11-21 15:08:06 | Mark.Shannon | set | messageid: <1574348886.05.0.765635897291.issue38500@roundup.psfhosted.org> |
2019-11-21 15:08:06 | Mark.Shannon | link | issue38500 messages |
2019-11-21 15:08:05 | Mark.Shannon | create | |
|