gh-125825: add subgroup() and split() methods on BaseException
          #125883
        
          
      
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
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 likeexc.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..subgroup()and.split()methods toBaseException#125825📚 Documentation preview 📚: https://cpython-previews--125883.org.readthedocs.build/