ipdb icon indicating copy to clipboard operation
ipdb copied to clipboard

Adding a parameter to return command to enable returning custom object

Open kajbaf opened this issue 4 years ago • 1 comments

I extensively use ipdb for debugging in the most strange situations, and many times I come across cases in which a specific function requires a predefined setup in prod to work as expected, which is hard to do during debugging. In such cases I usually have to patch the mentioned function to behave as intended just to be able to continue debugging.

The suggestion is to add a parameter to the r(turn) command to patch the return value of the function. In this case, the current code will continue until returns, BUT it will return the INTENDED value.

    150 def very_complex_setup(**kwargs):
    151     # Make sure all dependencies are set up.
--> 152     result = other_setups(**kwargs)
    153     return result
ipdb> injected_result = True
ipdb> return injected_result

This command is expected to ignore the result and instead return injected_result as the value of the very_complex_setup function.

kajbaf avatar Oct 23 '21 08:10 kajbaf

I would suggest to try sthing like explained here: https://maurcz.github.io/posts/002-customizing-the-python-debugger/

Iow, I think that you can subclass ipdb yourself.

gotcha avatar Oct 25 '21 21:10 gotcha