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

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

Merged
merged 23 commits into from
Apr 16, 2022

Conversation

iritkatriel
Copy link
Member

@iritkatriel iritkatriel commented Feb 13, 2022

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

🤖 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
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.

Where's the descriptor for "__notes__"?

Objects/exceptions.c Show resolved Hide resolved
Doc/library/exceptions.rst Outdated Show resolved Hide resolved
Lib/test/test_exceptions.py 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.

"Errors should never pass silently."

Lib/test/test_exceptions.py Outdated Show resolved Hide resolved
@gvanrossum
Copy link
Member

Yeah, I like this!

@iritkatriel
Copy link
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
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
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
Copy link
Contributor

Zac-HD commented Mar 22, 2022

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

🤖 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
Objects/exceptions.c Outdated Show resolved Hide resolved
@iritkatriel
Copy link
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

🤖 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
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.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Opened #106033.

return NULL;
}

if (!PyObject_HasAttr(self, &_Py_ID(__notes__))) {
Copy link
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