Unwanted function evaluations in debug mode

May 12 at 8:22 AM
Hi,

Another little bug report for you. My Python code includes a lot of computationally expensive function calls. When I'm stepping through code in debug mode, hovering over the end bracket of one of these function calls will attempt to evaluate the function so that the result can be shown in a tooltip. This is very useful for quick functions that return a value and don't modify any objects in-place, but in many other cases it's unwanted and means the debugging session has to be started again (or I have to wait for the function to finish and then manually undo what it's done).

The safest and most obvious solution for this that I can think of is an option to disable the evaluation of functions while hovering over them in debug mode. Other solutions could be to only execute functions that return something other than None (although this is still potentially dangerous as they could modify objects in-place and/or take a long time to compute), or only execute standard Python library functions and not user functions (as these are generally fast to compute - but again, might modify objects). Alternatively, it could be left up to the user to declare in a "magic comment" that a function (or all functions in a module) should never be evaluated in the background by the debugger. However, as always I'm sure someone else can come up with a better solution!

I should also point out that the problem is also not confined to function evaluations - things like list comprehensions that invoke a function can also have unwanted effects!

Cheers,


Sam
Coordinator
May 12 at 4:33 PM
The safest and most obvious solution for this that I can think of is an option to disable the evaluation of functions while hovering over them in debug mode.
Yup. We actually have this exact thing for code completion in Interactive windows (because there, it works by inspecting live objects, so to e.g. compute completion list for a function result it needs to run that function).

This problem is more generic than debugger data tips - it also exists for the Watch window, where expressions are re-evaluated on every step. There is a bug for that:
https://pytools.codeplex.com/workitem/2078

Feel free to add any other scenarios that this affects, or suggestions on how to make this controllable, in the comments there.
Other solutions could be to only execute functions that return something other than None
This is rather tricky to determine in advance without running the function :)
Alternatively, it could be left up to the user to declare in a "magic comment" that a function (or all functions in a module) should never be evaluated in the background by the debugger.
It would be nice to have some standard annotation for this, like @pure. We'd like to avoid something that is PTVS-specific, though.