@@ -17,10 +17,15 @@ def split(exc_type, exc, *, match=None):
17
17
match (None or func): predicate function to restict the split process,
18
18
if the argument is not None, only exceptions with match(exception)
19
19
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)
20
23
"""
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 ):
24
29
matches = []
25
30
match_notes = []
26
31
rests = []
@@ -38,13 +43,13 @@ def split(exc_type, exc, *, match=None):
38
43
elif rests and not matches :
39
44
return None , exc
40
45
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
48
53
else :
49
54
if isinstance (exc , exc_type ) and (match is None or match (exc )):
50
55
return exc , None
0 commit comments