@@ -131,67 +131,82 @@ class MyBEG(BaseExceptionGroup):
131131
132132class StrAndReprTests (unittest .TestCase ):
133133 def test_ExceptionGroup (self ):
134+ eg_excs = [ValueError (1 ), TypeError (2 )]
134135 eg = BaseExceptionGroup (
135- 'flat' , [ ValueError ( 1 ), TypeError ( 2 )] )
136+ 'flat' , eg_excs )
136137
137138 self .assertEqual (str (eg ), "flat (2 sub-exceptions)" )
138139 self .assertEqual (repr (eg ),
139- "ExceptionGroup('flat', [ValueError(1), TypeError(2)])" )
140+ "ExceptionGroup('flat', (ValueError(1), TypeError(2)))" )
141+
142+ # Mutate the list of exceptions passed to BaseExceptionGroup.
143+ # This shouldn't change the EG's functionality, nor its repr.
144+ eg_excs .clear ()
140145
141146 eg = BaseExceptionGroup (
142147 'nested' , [eg , ValueError (1 ), eg , TypeError (2 )])
143148
144149 self .assertEqual (str (eg ), "nested (4 sub-exceptions)" )
145150 self .assertEqual (repr (eg ),
146151 "ExceptionGroup('nested', "
147- "[ ExceptionGroup('flat', "
148- "[ ValueError(1), TypeError(2)] ), "
152+ "( ExceptionGroup('flat', "
153+ "( ValueError(1), TypeError(2)) ), "
149154 "ValueError(1), "
150155 "ExceptionGroup('flat', "
151- "[ ValueError(1), TypeError(2)]) , TypeError(2)] )" )
156+ "( ValueError(1), TypeError(2))) , TypeError(2)) )" )
152157
153158 def test_BaseExceptionGroup (self ):
159+ eg_excs = [ValueError (1 ), KeyboardInterrupt (2 )]
154160 eg = BaseExceptionGroup (
155- 'flat' , [ ValueError ( 1 ), KeyboardInterrupt ( 2 )] )
161+ 'flat' , eg_excs )
156162
157163 self .assertEqual (str (eg ), "flat (2 sub-exceptions)" )
158164 self .assertEqual (repr (eg ),
159165 "BaseExceptionGroup("
160166 "'flat', "
161- "[ValueError(1), KeyboardInterrupt(2)])" )
167+ "(ValueError(1), KeyboardInterrupt(2)))" )
168+
169+ # Mutate the list of exceptions passed to BaseExceptionGroup.
170+ # This shouldn't change the EG's functionality, nor its repr.
171+ eg_excs .clear ()
162172
163173 eg = BaseExceptionGroup (
164174 'nested' , [eg , ValueError (1 ), eg ])
165175
166176 self .assertEqual (str (eg ), "nested (3 sub-exceptions)" )
167177 self .assertEqual (repr (eg ),
168178 "BaseExceptionGroup('nested', "
169- "[ BaseExceptionGroup('flat', "
170- "[ ValueError(1), KeyboardInterrupt(2)] ), "
179+ "( BaseExceptionGroup('flat', "
180+ "( ValueError(1), KeyboardInterrupt(2)) ), "
171181 "ValueError(1), "
172182 "BaseExceptionGroup('flat', "
173- "[ ValueError(1), KeyboardInterrupt(2)])] )" )
183+ "( ValueError(1), KeyboardInterrupt(2)))) )" )
174184
175185 def test_custom_exception (self ):
176186 class MyEG (ExceptionGroup ):
177187 pass
178188
189+ eg_excs = [ValueError (1 ), TypeError (2 )]
179190 eg = MyEG (
180- 'flat' , [ ValueError ( 1 ), TypeError ( 2 )] )
191+ 'flat' , eg_excs )
181192
182193 self .assertEqual (str (eg ), "flat (2 sub-exceptions)" )
183- self .assertEqual (repr (eg ), "MyEG('flat', [ValueError(1), TypeError(2)])" )
194+ self .assertEqual (repr (eg ), "MyEG('flat', (ValueError(1), TypeError(2)))" )
195+
196+ # Mutate the list of exceptions passed to BaseExceptionGroup.
197+ # This shouldn't change the EG's functionality, nor its repr.
198+ eg_excs .clear ()
184199
185200 eg = MyEG (
186201 'nested' , [eg , ValueError (1 ), eg , TypeError (2 )])
187202
188203 self .assertEqual (str (eg ), "nested (4 sub-exceptions)" )
189204 self .assertEqual (repr (eg ), (
190205 "MyEG('nested', "
191- "[ MyEG('flat', [ ValueError(1), TypeError(2)] ), "
206+ "( MyEG('flat', ( ValueError(1), TypeError(2)) ), "
192207 "ValueError(1), "
193- "MyEG('flat', [ ValueError(1), TypeError(2)] ), "
194- "TypeError(2)] )" ))
208+ "MyEG('flat', ( ValueError(1), TypeError(2)) ), "
209+ "TypeError(2)) )" ))
195210
196211
197212def create_simple_eg ():
0 commit comments