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

Format python traceback in impl Debug for PyErr. #4900

Merged
merged 1 commit into from
Feb 18, 2025

Conversation

nicolasavru
Copy link
Contributor

Fixes #4863.

@nicolasavru nicolasavru force-pushed the perr-debug-traceback branch 2 times, most recently from 48a7bf4 to a9ec2c0 Compare February 10, 2025 19:14
Copy link
Contributor

@Icxolu Icxolu left a comment

Choose a reason for hiding this comment

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

Thanks! This looks reasonable to me. Just a quick thought before landing this: Does it make sense to keep the inner Result here, or should we flatten it into the outer Option for simplicity?

@davidhewitt
Copy link
Member

I guess if it errors we would try to render the error and maybe get into an infinite descent? I suggest we flatten and use logic similar to the PyAny::display in the case of errors.

@davidhewitt
Copy link
Member

Sorry, I meant impl Display for Bound

fn python_format(

@nicolasavru
Copy link
Contributor Author

Done. I thought about using tb.format().map_err() instead of the match but the match is more readable IMO.

This gives output like "traceback: Some(\"<unformattable <traceback object at 0x7f645f7c18c0>>\")".

Is there a good way to test this?

Copy link

codspeed-hq bot commented Feb 12, 2025

CodSpeed Performance Report

Merging #4900 will not alter performance

Comparing nicolasavru:perr-debug-traceback (9546f5f) with main (5be233c)

Summary

✅ 88 untouched benchmarks

src/err/mod.rs Outdated
Comment on lines 780 to 787
Err(err) => {
err.write_unraisable(py, Some(&tb));
format!("<unformattable {:?}>", tb)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we construct an unraisable traceback in a test to have coverage here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't know, that's what I meant in my last reply with "Is there a good way to test this?". If anyone here knows how I can construct an unformattable traceback, I'm happy to add a test for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could do something like mock out io.StringIO in the python, that should cause the format to fail, not sure if we want to go down that route.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a test with that approach.

Copy link
Contributor

@Icxolu Icxolu left a comment

Choose a reason for hiding this comment

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

Looks good to me now, thank you very much!

@Icxolu Icxolu added this pull request to the merge queue Feb 18, 2025
github-merge-queue bot pushed a commit that referenced this pull request Feb 18, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 18, 2025
@Icxolu Icxolu added this pull request to the merge queue Feb 18, 2025
Merged via the queue into PyO3:main with commit 7e52b6e Feb 18, 2025
48 checks passed
@nicolasavru nicolasavru deleted the perr-debug-traceback branch February 24, 2025 12:55
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.

have PyErr's Debug implementation call traceback.format()
5 participants