Skip to content

Commit

Permalink
fix code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkdl committed Oct 19, 2024
1 parent 06874cc commit 2e807d2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
6 changes: 3 additions & 3 deletions flake8_async/visitors/visitor123.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ def visit_Assign(self, node: ast.Assign | ast.AnnAssign):
return
targets = (node.target,) if isinstance(node, ast.AnnAssign) else node.targets
if self._is_child_exception(node.value):
for target in targets:
if isinstance(target, ast.Name):
self.child_exception_names.add(target.id)
# not normally possible to assign single exception to multiple targets
if len(targets) == 1 and isinstance(targets[0], ast.Name):
self.child_exception_names.add(targets[0].id)
elif self._is_exception_list(node.value):
if len(targets) == 1 and isinstance(targets[0], ast.Name):
self.child_exception_list_names.add(targets[0].id)
Expand Down
38 changes: 38 additions & 0 deletions tests/eval_files/async123.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,41 @@ def any_fun(arg: Exception) -> Exception:
x: Any = object()
x.y = e
raise x.y.exceptions[0]

# coverage
try:
...
except ExceptionGroup:
...

# not implemented
try:
...
except ExceptionGroup as e:
(a, *b), (c, *d) = e.split(bool)
if condition():
raise a
if condition():
raise b[0]
if condition():
raise c
if condition():
raise d[0]

# coverage (skip irrelevant assignments)
x = 0

# coverage (ignore multiple targets when assign target is child exception)
try:
...
except ExceptionGroup as e:
exc = e.exceptions[0]
b, c = exc
if condition():
raise b # not handled, and probably shouldn't raise
else:
raise c # same

# coverage (skip irrelevant loop)
for x in range(5):
...

0 comments on commit 2e807d2

Please sign in to comment.