Skip to content

bpo-44569: Decouple frame formatting in traceback.py #27038

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

Merged
merged 1 commit into from
Jul 16, 2021

Conversation

ammaraskar
Copy link
Member

@ammaraskar ammaraskar commented Jul 5, 2021

This allows customization of how individual frames are printed by traceback.py without having to re-implement the recursive/repeated lines handling of traceback.StackSummary.format.

https://bugs.python.org/issue44569

@ammaraskar
Copy link
Member Author

@terryjreedy Is this what you had in mind?

@isidentical / @pablogsal Does this need a NEWS entry?

@pablogsal
Copy link
Member

@isidentical / @pablogsal Does this need a NEWS entry?

If format_frame is a new public API, then yes

@isidentical
Copy link
Member

Does this need a NEWS entry?

I don't see anything worth to NEWS entry, though it depends whether you intend to make this method public or private. I'd say we should make it private for now

@terryjreedy
Copy link
Member

terryjreedy commented Jul 5, 2021

Except for the added '_', this is one version of what I had in mind. However, it was my intention that the possibility of overriding just the frame formatting, the point of this issue, be public. Currently and continuing in the future, could instead can override .format itself. I imagine that this has been done. But that is a lot more to copy-paste, which adds the possibility of missing improvements elsewhere in the function. For instance, the improvements in recursion truncation. The need to format each frame is stable. Moving the code from one public function to another does not eliminate the possibility of changing the details of what is produced, like we are already doing.

I though about adding 'frame_formatter=_whatever' to the .format signature, but rejected it because users do not call .format directly, and a new argument would have to be propagated back to the module functions.

EDIT: I verified that calling the module function that IDLE uses does indeed end up calling the frame formatting within .format, so this is the code I need to modify.

@ammaraskar
Copy link
Member Author

Gotcha, let me switch it back to public and write up some documentation.

@ammaraskar
Copy link
Member Author

@terryjreedy format_frame is now a public function with docs, please take a look.

@ammaraskar ammaraskar force-pushed the traceback_py_refactor branch from 724d179 to 3174eb3 Compare July 8, 2021 16:29
@terryjreedy
Copy link
Member

terryjreedy commented Jul 13, 2021

The address sanitizer failure was a test_mulitprocessing timeout. All works on rerun.

When I updated my local main and made a branch with this pr, there was no merge conflict. I don't know how to make that claim disappear.

Patch looks good to me.

@ammaraskar
Copy link
Member Author

ammaraskar commented Jul 13, 2021

Aah, let me rebase to get rid of the github merge conflict. Thank you for the review, Terry.

@ammaraskar ammaraskar force-pushed the traceback_py_refactor branch from 3174eb3 to bb00d37 Compare July 13, 2021 20:16
@ammaraskar
Copy link
Member Author

Rebased.

@terryjreedy
Copy link
Member

I believe pushing my clean branch would have done the same, except I lacked permission ;-).

@ammaraskar ammaraskar force-pushed the traceback_py_refactor branch from bb00d37 to f136c1e Compare July 16, 2021 02:35
@ammaraskar
Copy link
Member Author

Rebased for #27126

@pablogsal pablogsal merged commit 8ce3008 into python:main Jul 16, 2021
@ammaraskar ammaraskar deleted the traceback_py_refactor branch July 16, 2021 14:36
@@ -449,6 +449,48 @@ def from_list(klass, a_list):
result.append(FrameSummary(filename, lineno, name, line=line))
return result

def format_frame(self, frame):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that this is actually a FrameSummary object rather than a frame.

Since we haven't released it yet, I think we should rename the function and its arg to format_frame_summary(frame_summary). What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think is a good idea. What do you think @ammaraskar @isidentical ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good to me, format frame summary seems more descriptive.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. I see the confusion between frame and frame_summary in local variable names predates this PR. I'll try to fix that as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created bpo 45075 for this.

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

Successfully merging this pull request may close these issues.

7 participants