Mark Shannon <m...@hotpy.org> added the comment:

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

----------

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

Reply via email to