Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
bpo-31299: Make it possible to filter out frames from tracebacks#26772
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
iritkatriel commented Jun 17, 2021 • edited by bedevere-bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by bedevere-bot
Uh oh!
There was an error while loading. Please reload this page.
terryjreedy left a comment
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.
The new parameter must be added to most or all of the format/print functions that call TracebackException.
I did not look at tests.
Uh oh!
There was an error while loading. Please reload this page.
bedevere-bot commented Jun 22, 2021
When you're done making the requested changes, leave the comment: |
Uh oh!
There was an error while loading. Please reload this page.
iritkatriel commented Jun 23, 2021
Apart from adding the new arg to the module level wrapper functions (which I'm unsure about - see #26772 (comment)) ... I have made the requested changes; please review again |
bedevere-bot commented Jun 23, 2021
Thanks for making the requested changes! @terryjreedy: please review the changes made to this pull request. |
Uh oh!
There was an error while loading. Please reload this page.
iritkatriel commented Jul 3, 2021
Do you think we should change those functions to take any **kwargs and forward them to the TracebackException constructor? So to change the signature from to something like ? (file and chain go into print() rather than init). |
iritkatriel commented Jul 16, 2021 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
I changed this to use the refactor of #27038 |
Uh oh!
There was an error while loading. Please reload this page.
| def__init__(self, exc_type, exc_value, exc_traceback, *, limit=None, | ||
| lookup_lines=True, capture_locals=False, compact=False, | ||
| _seen=None): | ||
| stack_summary_cls=None, _seen=None): |
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.
This seems like a good approach to customizing the behavior while reusing most of the exception printing code. There's precedent for this style of expansion with JSONEncoder and cls in the json module. Any thoughts @terryjreedy?
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.
See general review comment.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Ammar Askar <ammar_askar@hotmail.com>
terryjreedy left a comment
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.
This PR does two things: 1. Expand the API of new format_frame function by handing None returns. Returning '' and appending it to result does not completely work as it adds a blank line to the end output. 2. Expand API of Traceback Exception to allow using a custom format_frame in a subclass of StackSummary rather than monkeypatching it into the original. This is generally preferable.
I regard this PR as completing what we started in #27038. When I proposed extracting format_frame, I was hoping that it could be an alternative to adding yet another keyword parameter* to multiple module-level convenience functions, as was originally considered here. I am delighted to see this happen. I am OK with not adding the parameter to the functions. I have since decided that people with idiosyncratic needs should learn to call TracebackException (starting with me ;-).
- For this issue, there was discussion about whether the new parameter should be general -- a boolean filter function (called with what?) -- or specific, a filter set used by a hard-coded filter function.
I presume that the new last_line_displayed code was shown to be necessary and sufficient by the tests. This time, I read the new tests and they look good. My only suggestion is the one about the doc.
| If *stack_summary_cls* is not ``None``, it is a class to be used instead of | ||
| the default :class:`~traceback.StackSummary` to format the stack (typically | ||
| a subclass that overrides :meth:`~traceback.StackSummary.format_frame`). | ||
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.
Consider adding a code example, in particular, class SkipG from the test, which skips frames for a function named 'g'.
| def__init__(self, exc_type, exc_value, exc_traceback, *, limit=None, | ||
| lookup_lines=True, capture_locals=False, compact=False, | ||
| _seen=None): | ||
| stack_summary_cls=None, _seen=None): |
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.
See general review comment.
iritkatriel commented Jul 18, 2021
Thank you @ammaraskar and @terryjreedy for the reviews.
Actually no, it was from my reading of the code - I wanted to prevent printing something about "the previous line" when the previous line was not printed. But I should have added a test for this, and I will do that shortly.
I agree, in fact the are no examples at all for using TracebackException directly, and there is an open issue regarding that (Issue27597). I want to tackle that next and rewrite the TracebackException part of the doc to explain why and how it should be used. I'll send it for you to review once I have it. |
iritkatriel commented Jul 19, 2021
I added some more tests, and found two bugs in the process.
|
iritkatriel commented Jul 19, 2021
I made the doc updates as part of PR iritkatriel#19 (which is against the current branch). I have made the requested changes; please review again |
bedevere-bot commented Jul 19, 2021
Thanks for making the requested changes! @terryjreedy: please review the changes made to this pull request. |
…one' and then we don't need the last_line_displayed flag
iritkatriel commented Aug 30, 2021
It seems that this got overly complicated. I've created PR28067 to just handle the Non return (without adding this to the TracebackException API). That will allow us to use this for the unittest bug, and we can decide later about the external API. |
https://bugs.python.org/issue31299