8000 Submission for SC consideration: PEP 678 -- Enriching Exceptions with Notes · Issue #105 · python/steering-council · GitHub
[go: up one dir, main page]

Skip to content

Submission for SC consideration: PEP 678 -- Enriching Exceptions with Notes #105

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

Closed
Zac-HD opened this issue Feb 9, 2022 · 19 comments
Closed
Labels
PEP Python Enhancement Proposal

Comments

@Zac-HD
Copy link
Zac-HD commented Feb 9, 2022

Please consider PEP 678, https://www.python.org/dev/peps/pep-0678/

This proposal arose out discussions about use of ExceptionGroup, as a way to attach extra information when exception chaining is undesirable (e.g. because a library does not wish to change the exception type). The motivation section discusses use by testing libraries such as Hypothesis and Pytest, with concurrency like Trio or with serial retries, and in teaching environments such as friendly-traceback.

@encukou
Copy link
Member
encukou commented Feb 9, 2022

Thanks! I've added it to the agenda.

@Zac-HD
Copy link
Author
Zac-HD commented Feb 13, 2022

Hi @encukou - following additional discussion in the discuss.python.org thread since I opened this issue, we are planning some minor changes. (storing a sequence of strings rather than a string-or-None incurs a little extra complexity, but makes translation use-cases much easier to support).

Up to you whether that should affect the agenda.

@brettcannon
Copy link
Member

@Zac-HD We will leave it on the agenda but skip over it until you're ready again for us to have a look.

@brettcannon brettcannon added the PEP Python Enhancement Proposal label Feb 16, 2022
@Zac-HD
Copy link
Author
Zac-HD commented Feb 25, 2022

We've settled on an updated design with .add_note(note) and a __notes__ attribute, and are now once again ready for consideration by the Steering Council. Thanks for your patience!

@brettcannon
Copy link
Member

The PEP is back/still in our agenda.

@brettcannon
Copy link
Member

One thing I noticed about the PEP is it doesn't actually say what BaseException.add_note() does. I assume it appends to the tuple, but the PEP actually doesn't say. It also doesn't address whether the tuple is mutated in-place (since you aren't allowing assignment that means Python could cheat and mutate the tuple in-place), or are you constructing a new tuple on every call to add_note()?

I would also suggest tweaking the title of the section https://www.python.org/dev/peps/pep-0678/#store-notes-in-exceptiongroups to say "Store notes in ExceptionGroups only". Otherwise if you didn't know that ExceptionGroup inherits from Exception you might think ExceptionGroup wouldn't be getting __notes__.

@Zac-HD
Copy link
Author
Zac-HD commented Mar 2, 2022

Per python/cpython#31317, it appends to an internal list, we create a new tuple each time - mutating in place seems unsafe when the user might have gotten a reference to the tuple already! I'll update the text to clarify this, and change the title of that section to "Store notes in ExceptionGroups, but not other Exceptions".

@brettcannon
Copy link
Member

mutating in place seems unsafe when the user might have gotten a reference to the tuple already!

I totally agree, hence wanting the clarification. 😁

@Zac-HD
Copy link
Author
Zac-HD commented Mar 4, 2022

Irit and I talked this over; the PEP is now clear that the tuple is replaced each time a note is added (so you get the same object on every access between updates), and the implementing PR has been updated accordingly.

@gvanrossum
Copy link
Member

Why would it matter if a tuple of strings is the same object each time? That's a pure value. (Yes, sure, perf, but that's a quality of implementation issue, shouldn't have to be specified in the PEP. This isn't going to hit O(N^2) territory.

@Zac-HD
Copy link
Author
Zac-HD commented Mar 4, 2022

I don't think it matters or needs to be specified, but since Brett asked above I wrote it in. Happy to take that back out if SC agrees.

@brettcannon
Copy link
Member

My concern is someone is going to store that tuple somewhere thinking it isn't going to change at the moment that they saw it, and then whoops, it does, since tuples are generally viewed as immutable.

@gvanrossum
Copy link
Member

Of course the tuple would be immutable.

@brettcannon
Copy link
Member

Of course the tuple would be immutable.

Then I don't understand your concern. The PEP didn't specify what add_note() explicitly did, so I suggested it be clarified. I assumed part of the clarification would say that __note__ always led to a new tuple after add_note() was called (whether that's on access of __note__ because it's a lazy descriptor or by actually storing a tuple internally I don't care). But my key point was nothing was saying what the semantics were in regards to this and we all know what crazy things one can do at the C level, so I figured being explicit instead of implicit was better.

@iritkatriel
Copy link
Member

This was the actual change in the pep (https://github.com/python/peps/pull/2377/files). Do you think it’s over specifying how notes is updated?

@gvanrossum
Copy link
Member

I put my answer in python/peps#2377 (comment)

@gpshead
Copy link
Member
gpshead commented Mar 21, 2022

Ping us when the PEP text is updated to reflect the simpler version per the current discussions. https://discuss.python.org/t/pep-678-enriching-exceptions-with-notes/13374/74?u=gpshead

@Zac-HD
Copy link
Author
Zac-HD commented Mar 27, 2022

The PEP text has been updated in python/peps#2456. The key changes are to make __notes__ a list, and explicitly decline to specify what should happen if users mess with it directly.

@gpshead
Copy link
Member
gpshead commented Apr 12, 2022

Thanks! Accepted: https://discuss.python.org/t/pep-678-enriching-exceptions-with-notes/13374/100

@gpshead gpshead closed this as completed Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PEP Python Enhancement Proposal
Projects
None yet
Development

No branches or pull requests

6 participants
0