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
9599: Add missing attributes to fake tracebacks #1684
9599: Add missing attributes to fake tracebacks #1684
Conversation
Having f_globals and f_locals in traceback frames is useful for post mortem debugging. Thus we should provide what we can. If we're constructing a fake traceback then we are doing so for a Failure that has been cleaned and therefore the variables in f_globals and f_locals are the result of _safeReprVars(). The benefit of that is not holding references to the original objects anymore but the downside is that the post mortem debugger only has access to string representations of the variables. That's still a lot better than showing all the variables as not defined in the post mortem debugger.
Fake tracebacks can't be used by code that expects all the attributes of a traceback if they don't have said attributes. An example of this is post mortem debugging.
__builtins__ is not consistent accross Python implementations, specifically Pypy 3.7. Using the builtins module is better.
Thanks for this contribution. The original issue reported talks about how |
I could have a test that compares a fake traceback and a real one I suppose. |
Comparing the attributes of the two types seems like it could work. It doesn't prove the fake traceback will work in all the places a real one does, but if all of the attributes are the same then the only uses I can think of that would break are uses that involve an actual type check.
It might be possible to test the relevant codepath using a
This seems like a slightly safer test to me. It's hard to say why. Maybe because the
Hm. Off the top of my head, I'm not sure either. Perhaps grepping the stdlib for some of these attributes would turn up something? (Or give some confidence that there aren't really any other users) |
Hi @pdunning-xilinx, I thought that this deserved mention in the release notes so I added some chattier news fragments. I also added a test that calls I have reviewed your changes against the stdlib docs and I think they're 👍. We'll need someone else to review what I did. That can be you! If my changes are okay, please comment here and I can merge. Otherwise we'll have to wait for another reviewer to happen along. I hope I'm not stepping on your toes. Thanks for contributing to Twisted! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
Many thanks Tom for the follow up.
I have updated the ticket and PR for https://twistedmatrix.com/trac/ticket/7796 as it looks like a duplicate.
Without an explicit test for Sentry, there is no guarantee that we will not break the API again in the future...but I think that this is safe enough and if we break it, we can fix it in another PR...and if someone cares for regression, then we can have a sentry test :)
Only minor comments
Maybe update the docstring for _Code
.
- A fake code object, used by L{_Traceback} via L{_Frame}.
+ A fake code object, used by L{_Traceback} via L{_Frame}.
+ It should have the same API as stdlib to allow interaction with
+ other tools.
Co-authored-by: Adi Roiban <adiroiban@gmail.com>
Co-authored-by: Adi Roiban <adiroiban@gmail.com>
Co-authored-by: Adi Roiban <adiroiban@gmail.com>
and whitespace cleanup
Scope and purpose
Real tracebacks and related objects (frames and code objects) have an extensive list of attributes. Twisted's fake tracebacks provide a cut down set of these. In Python 3, some of these attributes are used by tools such as post mortem debuggers. Thus it seems most appropriate to provide as full a set as possible (as per Python 3.10 docs), with most of them set to empty values as per the practice for some of the existing attributes.
Contributor Checklist:
tox -e lint
to format my patch to meet the Twisted Coding Standard#
character).review
to the keywords field in Trac, and putting a link to this PR in the comment; it shows up in https://twisted.reviews/ now.The first line is automatically generated by GitHub based on PR ID and branch name.
The other lines generated by GitHub should be replaced.
This patch is based on #1680 to avoid merge conflict issues.