I’d like to do some sort of tracing of function calls that involve storing an arbitrary object between when the function gets called and when it returns or raises an exception.
All of the above methods rely on callbacks and as such there’s no obvious place to store information.
sys.settrace I believe I can create a closure and return that as the next tracing function, that seems like it should work. But with the others as far as I can tell I have to either (1) keep the state myself or (2) keep my state in the locals of the function in question, which could change how code executes (e.g. if something calls locals()). Keeping state myself seems error-prone. Any suggestions?