Skip to content

gh-89770: Implement PEP-678 - Exception notes#31317

Merged
iritkatriel merged 23 commits into
python:mainfrom
iritkatriel:pep-678
Apr 16, 2022
Merged

gh-89770: Implement PEP-678 - Exception notes#31317
iritkatriel merged 23 commits into
python:mainfrom
iritkatriel:pep-678

Conversation

@iritkatriel

@iritkatriel iritkatriel commented Feb 13, 2022

Copy link
Copy Markdown
Member

No description provided.

@iritkatriel iritkatriel marked this pull request as draft February 13, 2022 21:45
@iritkatriel iritkatriel added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Feb 13, 2022
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @iritkatriel for commit 1555087 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Feb 13, 2022
@iritkatriel iritkatriel changed the title PEP-678: exception notes are set by add_note(). __notes__ holds a tuple of the assigned notes PEP-678: implementation of exception notes as per PEP discussions Mar 16, 2022
Comment thread Doc/library/exceptions.rst Outdated

@gvanrossum gvanrossum 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.

Where's the descriptor for "__notes__"?

Comment thread Objects/exceptions.c
Comment thread Doc/library/exceptions.rst Outdated
Comment thread Lib/test/test_exceptions.py

@gvanrossum gvanrossum 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.

"Errors should never pass silently."

Comment thread Lib/test/test_exceptions.py Outdated
@gvanrossum

Copy link
Copy Markdown
Member

Yeah, I like this!

@iritkatriel

Copy link
Copy Markdown
Member Author

How about error handling when printing the traceback? Should we print something like "cannot print notes: not a sequence", and similarly if a note is not a str?

@gvanrossum

Copy link
Copy Markdown
Member

How about error handling when printing the traceback? Should we print something like "cannot print notes: not a sequence", and similarly if a note is not a str?

How about printing repr(self.__notes__) if it's not a list, and str(note) if an individual note isn't a string? The former makes it clear what it is, while the latter provides a feature that Barry has been asking for...

If either of those fails, either raise an exception from print_exception() or swallow the error and print a simple message. It probably doesn't really matter, repr() or str() failing should be extremely obscure.

@iritkatriel

Copy link
Copy Markdown
Member Author

How about error handling when printing the traceback? Should we print something like "cannot print notes: not a sequence", and similarly if a note is not a str?

How about printing repr(self.__notes__) if it's not a list, and str(note) if an individual note isn't a string? The former makes it clear what it is, while the latter provides a feature that Barry has been asking for...

If either of those fails, either raise an exception from print_exception() or swallow the error and print a simple message. It probably doesn't really matter, repr() or str() failing should be extremely obscure.

I'll do something like what we do for str(exc).

@Zac-HD

Zac-HD commented Mar 22, 2022

Copy link
Copy Markdown
Contributor

Heya - I think we should have an explicit test that if you .split() an ExceptionGroup which already has __notes__, it's shallow-copied rather than simply assigned to the new instances. It'd be pretty confusing to call .add_note() on one and have it added to other instances too!

@iritkatriel

Copy link
Copy Markdown
Member Author

Heya - I think we should have an explicit test that if you .split() an ExceptionGroup which already has __notes__, it's shallow-copied rather than simply assigned to the new instances. It'd be pretty confusing to call .add_note() on one and have it added to other instances too!

That's a good point. I added the test and fixed the code to copy the notes in split(), so long as they are a sequence (producing a list). If people assign arbitrary objects to notes I don't know how to copy them.
Is there a "copy protocol" we can demand?

@iritkatriel iritkatriel marked this pull request as ready for review April 12, 2022 12:05
@iritkatriel iritkatriel changed the title gh-91479: Implement PEP-678 - Exception notes bpo-45607: Implement PEP-678 - Exception notes Apr 12, 2022
@iritkatriel iritkatriel changed the title bpo-45607: Implement PEP-678 - Exception notes gh-89770: Implement PEP-678 - Exception notes Apr 12, 2022
@iritkatriel iritkatriel reopened this Apr 12, 2022
@iritkatriel iritkatriel added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 14, 2022
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @iritkatriel for commit 95be670 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 14, 2022
Comment thread Objects/exceptions.c Outdated
@iritkatriel

Copy link
Copy Markdown
Member Author

Sorry about the noise (I messed it up multitasking). Getting there now.

@iritkatriel iritkatriel added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 14, 2022
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @iritkatriel for commit 602b4c4 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 14, 2022
@iritkatriel

Copy link
Copy Markdown
Member Author

The buildbots are happy with this. Let me know if you would like to re-review, otherwise I'll merge it tomorrow or so.

@serhiy-storchaka serhiy-storchaka 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.

Opened #106033.

Comment thread Objects/exceptions.c
return NULL;
}

if (!PyObject_HasAttr(self, &_Py_ID(__notes__))) {

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.

Do not use PyObject_HasAttr. It is broken by design.

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.

8 participants