From 2e807d2b9cb32884fb3a4ac38082d61b0554061a Mon Sep 17 00:00:00 2001
From: jakkdl
Date: Sat, 19 Oct 2024 15:37:32 +0200
Subject: [PATCH] fix code coverage
---
flake8_async/visitors/visitor123.py | 6 ++---
tests/eval_files/async123.py | 38 +++++++++++++++++++++++++++++
2 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/flake8_async/visitors/visitor123.py b/flake8_async/visitors/visitor123.py
index 0fd99bb..2db28c9 100644
--- a/flake8_async/visitors/visitor123.py
+++ b/flake8_async/visitors/visitor123.py
@@ -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)
diff --git a/tests/eval_files/async123.py b/tests/eval_files/async123.py
index 36c5208..967f78e 100644
--- a/tests/eval_files/async123.py
+++ b/tests/eval_files/async123.py
@@ -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):
+ ...