@@ -17,10 +17,15 @@ def split(exc_type, exc, *, match=None):
1717 match (None or func): predicate function to restict the split process,
1818 if the argument is not None, only exceptions with match(exception)
1919 will go into matched part.
20+
21+ Note that if the `exc` is type of ExceptionGroup, then the return
22+ value will be tuple of (ExceptionGroup or None, ExceptionGroup or None)
2023 """
21- if exc is None :
22- return None , None
23- elif isinstance (exc , ExceptionGroup ):
24+ if not isinstance (exc , BaseException ):
25+ raise TypeError (
26+ "Argument `exc` should be an instance of BaseException."
27+ )
28+ if isinstance (exc , ExceptionGroup ):
2429 matches = []
2530 match_notes = []
2631 rests = []
@@ -38,13 +43,13 @@ def split(exc_type, exc, *, match=None):
3843 elif rests and not matches :
3944 return None , exc
4045 else :
41- match = copy .copy (exc )
42- match .exceptions = matches
43- match .sources = match_notes
44- rest = copy .copy (exc )
45- rest .exceptions = rests
46- rest .sources = rest_notes
47- return match , rest
46+ matched_group = copy .copy (exc )
47+ matched_group .exceptions = matches
48+ matched_group .sources = match_notes
49+ rest_group = copy .copy (exc )
50+ rest_group .exceptions = rests
51+ rest_group .sources = rest_notes
52+ return matched_group , rest_group
4853 else :
4954 if isinstance (exc , exc_type ) and (match is None or match (exc )):
5055 return exc , None
0 commit comments