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

bpo-45607: Make it possible to enrich exception displays via setting their __note__ field #29880

Merged
merged 19 commits into from
Dec 3, 2021

Conversation

iritkatriel
Copy link
Member

@iritkatriel iritkatriel commented Dec 1, 2021

@iritkatriel
Copy link
Member Author

Should I add PyException_GetNote and PyException_SetNote to the c api?

Copy link
Contributor

@erlend-aasland erlend-aasland left a comment

Choose a reason for hiding this comment

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

Nice feature! LGTM. I found one path not covered by the test suite. I of course also left some pedantic PEP-7 comments 🤓

(BTW, I still find the error handling in pythonrun.c hard to read... and it generates so many indent levels 😕)

Objects/exceptions.c Outdated Show resolved Hide resolved
Objects/exceptions.c Outdated Show resolved Hide resolved
Objects/exceptions.c Outdated Show resolved Hide resolved
Lib/traceback.py Outdated Show resolved Hide resolved
Doc/library/exceptions.rst Outdated Show resolved Hide resolved
Objects/exceptions.c Show resolved Hide resolved
iritkatriel and others added 5 commits December 2, 2021 10:07
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
@iritkatriel
Copy link
Member Author

Thanks.

(BTW, I still find the error handling in pythonrun.c hard to read... and it generates so many indent levels 😕)

I'm working on it. I made a patch that changed so much it would take a year to review. I'll break it up.

Objects/exceptions.c Outdated Show resolved Hide resolved
Objects/exceptions.c Outdated Show resolved Hide resolved
Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

Nice! LGTM, but please fix the issues Erlend brought up.

@iritkatriel
Copy link
Member Author

Nice! LGTM, but please fix the issues Erlend brought up.

I did all of them except the test coverage for the error when passing NULL to the setter. This would only come into play if I add PyException_GetNote and PyException_SetNote to the C api. I think we need those, right?

@gvanrossum
Copy link
Member

I did all of them except the test coverage for the error when passing NULL to the setter. This would only come into play if I add PyException_GetNote and PyException_SetNote to the C api. I think we need those, right?

I think we should not add to the C API. If people want to access the note from C, they can use the __note__ attribute (like you do in the exception-printing C code). Even so, what happens when you try del err.__note__?

@iritkatriel
Copy link
Member Author

Ah yes, very good:

>>> del e.__note__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __note__ may not be deleted

@gvanrossum
Copy link
Member

gvanrossum commented Dec 3, 2021 via email

@iritkatriel
Copy link
Member Author

That behavior is fine. So do you have a unit test for that? If not, it should be easy to add one.

I don’t, I’ll add one.

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

+1

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.

None yet

6 participants