-
Notifications
You must be signed in to change notification settings - Fork 3
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The more I think about it, the more I believe we should be very careful whenever we're not following Trio's design (either the current MultiError design or the MultiError v2 design from python-trio/trio#611)...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am so glad we don't need a separate tree of tracebacks! I think this is an important simplification of the design. (I should have realized it was too complicated when I tried to draw diagrams of how it worked. :-)
I left two nits to the text.
I have a concern re trackbacks though. We said an ExceptionGroup is iterable so list(eg) is a flat list of the contained exceptions. But the trackbacks of those exceptions are partial. Their cause and context are wrong too, they should be the same as those of the topmost eg. It seems that we need an operation to extract an exception with the correct tb, cause, context. The tb part of the eg needs to be copied. Then something around the iteration api, not sure what. Or just document that the metadata is not reconstructed when you take an exception out of a group. |
We sort of do have that extract operation already - when we extract an exception in the form of a singleton ExceptionGroup via project() then the group has the correct metadata. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Happy we can keep tracebacks simple!
IMO just documenting that would be OK. We can also add some helpers to the |
Co-authored-by: Yury Selivanov <yury@edgedb.com>
Maybe we don't need ExceptionGroup to be iterable at all. The use case of selecting OSError by code (https://github.com/python/exceptiongroups/blob/master/except_star.md#raising-exceptiongroups-manually) can be implemented with something like Is there another use case? How about we provide this Note that the experimental implementation doesn't have the iterate operation, only a flatten helper method in the unit tests (it's not needed other than for the tests). |
Can you add a link to the experimental implementation to the README? |
Agreed, I have been wondering this for a while. Then we wouldn't have to worry about whether an EG with no exceptions is truthy or falsy or a forbidden edge case. You can still access the bare subexceptions using Related, I also wonder whether the constructor should take a list of exceptions instead of being varargs. I.e., |
+1 for the list option. I vaguely recall we already discussed this somewhere else, btw. |
I've added the link in readme. Re list - yes, it was a list initially, then we moved to varargs (before we added the msg arg). Do we want both varargs and sequence? Or just sequence? Or just list? |
Thanks! I'll play with it on the weekend.
My preference would be to go with an iterable/sequence (but no varargs). |
I'm thinking about how to implement raise inside an except* block and came across this question: At the moment, if we do this:
we get
which is what you would expect when an exception is not matched. But if we do this:
we get:
This is because the except* wraps the ValueError in an exception group, and that gets matched and reraised. |
I think it's acceptable. If you were to simplify the exception if the EG has exactly one subexception, you'd have the converse inconsistency, and I don't think adding more hidden state to track this case is a great idea either. Bare |
Added a section on traceback groups.
I assume there will be a section on exception group API before it, so the reference to splitting operations etc make sense.
We'll need some pictures of trees.