7 >>> a == 1 and b == 2 and c == 3
14 >>> a == 4 and b == 5 and c == 6
20 >>> a == 7 and b == 8 and c == 9
26 >>> a == 'o' and b == 'n' and c == 'e'
29 Unpack generic sequence
32 ... def __getitem__(self, i):
33 ... if i >= 0 and i < 3: return i
37 >>> a == 0 and b == 1 and c == 2
40 Single element unpacking, with extra syntax
53 Unpacking non-sequence
56 Traceback (most recent call last):
58 TypeError: 'int' object is not iterable
60 Unpacking tuple of wrong size
63 Traceback (most recent call last):
65 ValueError: too many values to unpack
67 Unpacking tuple of wrong size
70 Traceback (most recent call last):
72 ValueError: too many values to unpack
74 Unpacking sequence too short
76 >>> a, b, c, d = Seq()
77 Traceback (most recent call last):
79 ValueError: need more than 3 values to unpack
81 Unpacking sequence too long
84 Traceback (most recent call last):
86 ValueError: too many values to unpack
88 Unpacking a sequence where the test for too long raises a different kind of
91 >>> class BozoError(Exception):
95 ... def __getitem__(self, i):
96 ... if i >= 0 and i < 3:
104 Trigger code while not expecting an IndexError (unpack sequence too long, wrong
107 >>> a, b, c, d, e = BadSeq()
108 Traceback (most recent call last):
112 Trigger code while expecting an IndexError (unpack sequence too short, wrong
115 >>> a, b, c = BadSeq()
116 Traceback (most recent call last):
122 __test__
= {'doctests' : doctests
}
124 def test_main(verbose
=False):
125 from test
import test_support
126 from test
import test_unpack
127 test_support
.run_doctest(test_unpack
, verbose
)
129 if __name__
== "__main__":
130 test_main(verbose
=True)