Skip to content

Commit 2e807d2

Browse files
committed
fix code coverage
1 parent 06874cc commit 2e807d2

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

flake8_async/visitors/visitor123.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ def visit_Assign(self, node: ast.Assign | ast.AnnAssign):
8787
return
8888
targets = (node.target,) if isinstance(node, ast.AnnAssign) else node.targets
8989
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)
9393
elif self._is_exception_list(node.value):
9494
if len(targets) == 1 and isinstance(targets[0], ast.Name):
9595
self.child_exception_list_names.add(targets[0].id)

tests/eval_files/async123.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,41 @@ def any_fun(arg: Exception) -> Exception:
114114
x: Any = object()
115115
x.y = e
116116
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+
...

0 commit comments

Comments
 (0)