Skip to content
This repository was archived by the owner on Nov 2, 2022. It is now read-only.

Commit ffe3bf1

Browse files
committed
remember to copy __suppress_context__ for ExceptionGroup.
1 parent d680bfd commit ffe3bf1

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

exceptiongroup/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def __copy__(self):
5050
new_group.__traceback__ = self.__traceback__
5151
new_group.__context__ = self.__context__
5252
new_group.__cause__ = self.__cause__
53+
new_group.__suppress_context__ = self.__suppress_context__
5354
return new_group
5455

5556
def __str__(self):

exceptiongroup/_tests/test_exceptiongroup.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
import copy
12
import pytest
23

34
from exceptiongroup import ExceptionGroup
45

56

7+
def raise_group():
8+
try:
9+
1 / 0
10+
except Exception as e:
11+
raise ExceptionGroup("ManyError", [e], [str(e)]) from e
12+
13+
614
def test_exception_group_init():
715
memberA = ValueError("A")
816
memberB = RuntimeError("B")
@@ -47,3 +55,19 @@ def test_exception_group_str():
4755
assert "ExceptionGroup: " in repr(group)
4856
assert "memberA" in repr(group)
4957
assert "memberB" in repr(group)
58+
59+
60+
def test_exception_group_copy():
61+
try:
62+
raise_group()
63+
except BaseException as e:
64+
group = e
65+
group.__suppress_context__ = False
66+
another_group = copy.copy(group)
67+
assert group.message == another_group.message
68+
assert group.exceptions == another_group.exceptions
69+
assert group.sources == another_group.sources
70+
assert group.__traceback__ is another_group.__traceback__
71+
assert group.__context__ is another_group.__context__
72+
assert group.__cause__ is another_group.__cause__
73+
assert group.__suppress_context__ == another_group.__suppress_context__

0 commit comments

Comments
 (0)