Skip to content

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

Merged
iritkatriel merged 19 commits into
python:mainfrom
iritkatriel:bpo-45607-exception-note
Dec 3, 2021
Merged

bpo-45607: Make it possible to enrich exception displays via setting their __note__ field#29880
iritkatriel merged 19 commits into
python:mainfrom
iritkatriel:bpo-45607-exception-note

Conversation

@iritkatriel

@iritkatrieliritkatriel commented Dec 1, 2021

Copy link
Copy Markdown
Member

@iritkatriel

Copy link
Copy Markdown
MemberAuthor

Should I add PyException_GetNote and PyException_SetNote to the c api?

@erlend-aaslanderlend-aasland left a comment

Copy link
Copy Markdown
Contributor

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 😕)

Comment threadObjects/exceptions.c Outdated
Comment threadObjects/exceptions.c Outdated
Comment threadObjects/exceptions.c Outdated
Comment threadLib/traceback.py Outdated
Comment threadMisc/NEWS.d/next/Core and Builtins/2021-12-01-15-38-04.bpo-45607.JhuF8b.rst Outdated
Comment threadDoc/library/exceptions.rst Outdated
Comment threadObjects/exceptions.c
iritkatrieland 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
Copy Markdown
MemberAuthor

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.

Comment threadObjects/exceptions.c Outdated
Comment threadObjects/exceptions.c Outdated

@gvanrossumgvanrossum left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
MemberAuthor

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
Copy Markdown
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
Copy Markdown
MemberAuthor

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

gvanrossum commented Dec 3, 2021 via email

Copy link
Copy Markdown
Member

@iritkatriel

Copy link
Copy Markdown
MemberAuthor

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.

@gvanrossumgvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1

Sign up for freeto 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.

6 participants

@iritkatriel@gvanrossum@erlend-aasland@kumaraditya303@the-knights-who-say-ni@bedevere-bot