11import doctest
2- import textwrap
32import traceback
43import unittest
54
151150 ...
152151 UnpackError: too many values to unpack (expected 0, got 1)
153152
154- Unpacking to an empty iterable should raise UnpackError, but it won 't consume the
155- iterable if it doesn't have a pre-determined length
153+ Unpacking a larger iterable should raise UnpackError, but it shouldn 't consume the
154+ iterable entirely
156155
157156 >>> it = iter(range(100))
158157 >>> x, y, z = it
@@ -222,20 +221,15 @@ def test_extended_oparg_not_ignored(self):
222221
223222 def test_exception_context_when_len_fails (self ):
224223 """When `__len__()` raises an Exception, preserve exception context"""
225- code = textwrap .dedent (
226- """
227- class CustomSeq:
228- def __len__(self):
229- raise RuntimeError
230224
231- def __getitem__(self, i):
232- return i*2
225+ class LenRaisesException :
226+ def __len__ (self ):
227+ raise RuntimeError
228+ def __getitem__ (self , i ):
229+ return i * 2
233230
234- x, y, z = CustomSeq()
235- """
236- )
237231 with self .assertRaises (UnpackError ) as cm :
238- exec ( code )
232+ x , y , z = LenRaisesException ( )
239233
240234 traceback_text = '' .join (traceback .format_exception (cm .exception ))
241235 self .assertIn (
@@ -247,19 +241,15 @@ def __getitem__(self, i):
247241
248242 def test_baseexception_propagation_when_len_fails (self ):
249243 """if `__len__()` raises a `BaseException`, propagate that as-is"""
250- code = textwrap .dedent (
251- """
252- class C:
253- def __len__(self):
254- raise KeyboardInterrupt
255- def __getitem__(self, i):
256- return i
257-
258- x, y, z = C()
259- """
260- )
244+
245+ class LenRaisesBaseException :
246+ def __len__ (self ):
247+ raise KeyboardInterrupt
248+ def __getitem__ (self , i ):
249+ return i
250+
261251 with self .assertRaises (UnpackError ) as cm :
262- exec ( code )
252+ x , y , z = LenRaisesBaseException ( )
263253
264254 with self .assertRaises (KeyboardInterrupt ):
265255 traceback .format_exception (cm .exception )
0 commit comments