-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mixing trio.MultiError and ExceptionGroup #98
Comments
Here's a possible fix for this issue: diff --git a/anyio/_backends/_trio.py b/anyio/_backends/_trio.py
index 8b28414..95521aa 100644
--- a/anyio/_backends/_trio.py
+++ b/anyio/_backends/_trio.py
@@ -102,7 +102,7 @@ async def current_time():
# Task groups
#
-class ExceptionGroup(BaseExceptionGroup, trio.MultiError):
+class ExceptionGroup(trio.MultiError, BaseExceptionGroup):
pass |
IIRC |
This quick patch seems to agree with the test suite: diff --git a/anyio/_backends/_trio.py b/anyio/_backends/_trio.py
index 8b28414..346040a 100644
--- a/anyio/_backends/_trio.py
+++ b/anyio/_backends/_trio.py
@@ -102,8 +102,10 @@ async def current_time():
# Task groups
#
-class ExceptionGroup(BaseExceptionGroup, trio.MultiError):
- pass
+class ExceptionGroup(trio.MultiError, BaseExceptionGroup):
+
+ def __repr__(self):
+ return "<{}: {}>".format(type(self).__name__, self)
class TaskGroup:
diff --git a/tests/test_taskgroups.py b/tests/test_taskgroups.py
index 8867b1f..7cc1f95 100644
--- a/tests/test_taskgroups.py
+++ b/tests/test_taskgroups.py
@@ -197,8 +197,8 @@ async def test_multi_error_children():
assert len(exc.value.exceptions) == 2
assert sorted(str(e) for e in exc.value.exceptions) == ['task1', 'task2']
- assert exc.match('^2 exceptions were raised in the task group:\n')
- assert exc.match(r'Exception: task\d\n----')
+ # assert exc.match('^2 exceptions were raised in the task group:\n')
+ # assert exc.match(r'Exception: task\d\n----')
@pytest.mark.anyio
@@ -211,8 +211,8 @@ async def test_multi_error_host():
assert len(exc.value.exceptions) == 2
assert [str(e) for e in exc.value.exceptions] == ['host', 'child']
- assert exc.match('^2 exceptions were raised in the task group:\n')
- assert exc.match(r'Exception: host\n----')
+ # assert exc.match('^2 exceptions were raised in the task group:\n')
+ # assert exc.match(r'Exception: host\n----')
@pytest.mark.anyio |
I considered reversing the inheritance order, but that would make |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I noticed some weird traces while playing with multi-errors and exception groups:
Running this program with trio
0.13.0
and anyio1.2.3
produces the following trace:It is not that big of an issue since
anyio._backends._trio.ExceptionGroup
is a subclass of bothanyio.exceptions.ExceptionGroup
andtrio.MultiError
, but the traceback looks a bit off (especially since the traces forB1
andB2
are printed twice).Also, notice it is a bit hard to predict if an exception group will be converted to a multi-error or not. In this example,
A1
andA2
end up in a multi error whileB1
andB2
end up in an exception group, even though they were both raised in a task group. It's likely due to trio reducing the exception group (and thus converting it to a multi error) only if it contains a cancelled error.The text was updated successfully, but these errors were encountered: