gh-125825: add `subgroup()` and `split()` methods on `BaseException`
This is the simplest implementation I could think of. Another alternative I had in mind was to specialize the code for leaf exceptions but this would need to move around some prototypes and definitions, making the diff much harder to review. One the other hand, I think we don't really need to bother about critical performances when handling exception groups so converting it into an exception group and directly calling the method on that group felt simpler.
@Zac-HD Did you maybe have a different implementation in mind? One alternative is to expose some wraps() method on exception classes which convert them into exception groups if this is not already the case, so that you have something like exc.wraps().split().
By the way, I found a small bug in an existing test where a callable predicate is not being tested. It's in test_basics_subgroup_by_predicate__match.
- Issue: gh-125825
📚 Documentation preview 📚: https://cpython-previews--125883.org.readthedocs.build/
This is what I had in mind!
I'd rather not add .wraps() or similar because I don't think exc.wraps() is useful separately from then splitting or taking a subgroup often enough to justify a new method, when BaseExceptionGroup("", [exc]) is already pretty short.
Closing since the original issue was closed in favor of an alternative.