Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_TracebackFrame objects do not have "tb_lasti" attribute #9599

Closed
twisted-trac opened this issue Mar 23, 2019 · 4 comments
Closed

_TracebackFrame objects do not have "tb_lasti" attribute #9599

twisted-trac opened this issue Mar 23, 2019 · 4 comments

Comments

@twisted-trac
Copy link

Delgan's avatar @Delgan reported
Trac ID trac#9599
Type enhancement
Created 2019-03-23 09:31:16Z

Hi.

Built-in "traceback" objects are expected to have a "tb_lasti" attribute: https://docs.python.org/3/library/inspect.html#types-and-members

However, "_TracebackFrame" objects in Twister "failure.py" are missing this attribute:

class _TracebackFrame(object):
"""
Fake traceback object which can be passed to functions in the standard
library L{traceback} module.
"""
def __init__(self, frame):
"""
@param frame: _Frame object
"""
self.tb_frame = frame
self.tb_lineno = frame.f_lineno
self.tb_next = None

Hence, the assertion "Fake traceback object which can be passed to functions in the standard library" is erroneous, it may raises an exception with dis.distb for example: https://github.com/python/cpython/blob/master/Lib/dis.py#L96

Would this be possible for the _TracebackFrame objects to better match the expected standard API and don't raise AttributeError?

Searchable metadata
trac-id__9599 9599
type__enhancement enhancement
reporter__Delgan Delgan
priority__normal normal
milestone__None None
branch__ 
branch_author__ 
status__closed closed
resolution__fixed fixed
component__core core
keywords__None None
time__1553333476945733 1553333476945733
changetime__1655063365544509 1655063365544509
version__None None
owner__None None

@twisted-trac
Copy link
Author

pdunning-xilinx's avatar @pdunning-xilinx commented

I've hit this trying to pass the fake traceback object to pdb.post_mortem().
I can see which attributes it's after, and it works if I set them to the correct empty values.
Should I just set them to these empty values (fairly easy to do) or should I try to get the correct values from the original stack frames? The latter is more difficult as the stack frames are passed around as 5-tuples at some points and that tuple would need extending (I'd probably make it a named tuple and add attributes).

On a related note, I've discovered that the f_locals and f_globals on the fake stack frames are set to empty even if captureVars is set. It's relatively simple to correct. Does that need another ticket?

@twisted-trac
Copy link
Author

pdunning-xilinx's avatar @pdunning-xilinx commented

Also, should the fake traceback have all the attributes that a real one would or should it only have the ones we know it needs? If it needs all of them, do any of them need sanitising the way we do for the locals and globals?

@twisted-trac
Copy link
Author

pdunning-xilinx's avatar @pdunning-xilinx commented

Patch for review: #1684

@twisted-trac
Copy link
Author

twm's avatar @twm set status to closed

Merged in f28b36d, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant