-
-
Notifications
You must be signed in to change notification settings - Fork 346
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
nursery replaces custom ExceptionGroup subclasses with plain ExceptionGroups #3175
Comments
The problem is that splitting Cancelled from an ExceptionGroup tree converts custom EG subclasses into regular EGs: Lines 641 to 648 in 3de7996
|
Do we need to provide our own >>> class ExampleEG(ExceptionGroup):
... pass
...
>>> eg = ExampleEG("test", [ValueError("bad")])
>>> eg.split(TypeError)
(None, ExceptionGroup('test', [ValueError('bad')]))
>>> eg.split(ValueError)
(ExceptionGroup('test', [ValueError('bad')]), None)
>>> eg
ExampleEG('test', [ValueError('bad')]) Also, is this something we should report upstream to CPython? I think I get the logic for why this doesn't return subtypes though:
This way Python can preserve that ExceptionGroups are the norm unless someone passes in a not-Exception. I don't think this property is worth making every subclass make their own |
I think the fix is using a custom split that doesn't recreate ExceptionGroups if the children aren't changing. Probably it is worth reporting |
For custom subclasses, you need to define derive(), so it knows how to create instances - it's not safe obviously to assume the constructor args are the same. |
Should we warn about that and provide a sane alternative? |
defining an |
output:
expected output:
The text was updated successfully, but these errors were encountered: