File tree Expand file tree Collapse file tree 2 files changed +41
-3
lines changed Expand file tree Collapse file tree 2 files changed +41
-3
lines changed Original file line number Diff line number Diff line change @@ -87,9 +87,9 @@ def visit_Assign(self, node: ast.Assign | ast.AnnAssign):
87
87
return
88
88
targets = (node .target ,) if isinstance (node , ast .AnnAssign ) else node .targets
89
89
if self ._is_child_exception (node .value ):
90
- for target in targets :
91
- if isinstance (target , ast .Name ):
92
- self .child_exception_names .add (target .id )
90
+ # not normally possible to assign single exception to multiple targets
91
+ if len ( targets ) == 1 and isinstance (targets [ 0 ] , ast .Name ):
92
+ self .child_exception_names .add (targets [ 0 ] .id )
93
93
elif self ._is_exception_list (node .value ):
94
94
if len (targets ) == 1 and isinstance (targets [0 ], ast .Name ):
95
95
self .child_exception_list_names .add (targets [0 ].id )
Original file line number Diff line number Diff line change @@ -114,3 +114,41 @@ def any_fun(arg: Exception) -> Exception:
114
114
x : Any = object ()
115
115
x .y = e
116
116
raise x .y .exceptions [0 ]
117
+
118
+ # coverage
119
+ try :
120
+ ...
121
+ except ExceptionGroup :
122
+ ...
123
+
124
+ # not implemented
125
+ try :
126
+ ...
127
+ except ExceptionGroup as e :
128
+ (a , * b ), (c , * d ) = e .split (bool )
129
+ if condition ():
130
+ raise a
131
+ if condition ():
132
+ raise b [0 ]
133
+ if condition ():
134
+ raise c
135
+ if condition ():
136
+ raise d [0 ]
137
+
138
+ # coverage (skip irrelevant assignments)
139
+ x = 0
140
+
141
+ # coverage (ignore multiple targets when assign target is child exception)
142
+ try :
143
+ ...
144
+ except ExceptionGroup as e :
145
+ exc = e .exceptions [0 ]
146
+ b , c = exc
147
+ if condition ():
148
+ raise b # not handled, and probably shouldn't raise
149
+ else :
150
+ raise c # same
151
+
152
+ # coverage (skip irrelevant loop)
153
+ for x in range (5 ):
154
+ ...
You can’t perform that action at this time.
0 commit comments