Support local variables (tb.tb_frame.f_locals)
See original GitHub issueI’m sure there’s a reason for this, but it seems that Traceback objects don’t copy the f_locals
dictionary from the traceback frame. It would be nice to have this so that, for instance, reraised exceptions can be better introspected in an IDE.
For instance:
>>> def func():
... a = 1
... print locals()
... try:
... raise ValueError()
... except Exception as e:
... exc_type, exc_value, exc_tb = sys.exc_info()
>>> exc_tb.tb_frame.f_locals
{'a': 1, e: ValueError()}
>>> tb = Traceback(exc_tb)
>>> tb.as_traceback().tb_frame.f_locals
{}
There might be something obvious here that I’m missing?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Getting More Information from Tracebacks - Python Cookbook ...
This recipe exploits this structure and the rich amount of information held by frame objects, including the dictionary of local variables for the...
Read more >Find local variables in the traceback for an exception
f_locals property and so on up to the top of the stack. I wrote this function to find them: def _find_variables(tb, vars): to_find ......
Read more >Python: sys.exc_info() is missing local variables - Stack Overflow
The problem I'm running into is that the traceback object (exc_info[2]) is non-deterministically missing local variables in the traceback ...
Read more >Local Variables - Crafting Interpreters
Local variables are one of the most-used parts of a language. If locals are ... They typically use the native stack mechanisms supported...
Read more >Local variables created in VOPSOP | Forums - SideFX
But i can't access that variable in for eg. extrude sop (with $). ... If that SOP doesn't support local variables (after looking...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
f_locals
are a can of worms basically, we’d have lots of corner cases like reference loops, unpickleable stuff, overblown pickle result size and such. I’m not saying no but I’m not a fan of the idea either - the primary goal of this library is to be able to display a traceback using stdlib modules (liketraceback
) from a different process.The changes in #59 made by @marcoffee seem fine to me (some tests needed tho, and some docs explaining that repr will be used, and it can create side-effects). Would those changes solve this/the problems on gevent? I’m not a big gevent user.