Support changing return value of a function in sys.monitoring
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
Description
Feature or enhancement
Proposal:
gdb has a command return for users to immediately return from the function. It basically does two things:
- stop the execution of the function
- return an arbitrary value
In Python, 1. might not be that simple as we have all the references to the stack value (it should be doable, but may or may not worth it), but 2. should be pretty straightforward. We can allow the callback for PY_RETURN function to return something specific (like sys.monitoring.RETURN, retval) to replace the value we are about to return. It should only need to swap the value on the stack and the impact should be contained. Some of the instrumentation structure needs to be refactored a bit but I don't think it's too much work.
With this feature, we can "mock" the return value in the debugger. We can even expand our existing return command - we may not able to return immediately, but we can run until it returns and secretly swap the return value, so we can call this command from anywhere.
Does this sound like a reasonable feature or I'm missing something? @markshannon
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the sys.monitoring PY_RETURN callback and the instrumentation structure discussed in the proposal. Compare this with the existing debugger return command, then determine how a callback-supplied value could replace the pending return value. Done means the behavior is specified, implemented, and covered by tests for changing a function's return value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100