1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
t = (1,2,3)
l = [1,2,3]
def assign3(t):
"""
>>> assign3(l)
(1, 2, 3)
>>> assign3(t)
(1, 2, 3)
>>> assign3((1,))
Traceback (most recent call last):
ValueError: need more than 1 value to unpack
>>> assign3((1,2))
Traceback (most recent call last):
ValueError: need more than 2 values to unpack
>>> assign3((1,2,3,4))
Traceback (most recent call last):
ValueError: too many values to unpack (expected 3)
"""
a,b,c = t
return (a,b,c)
def assign3_typed(tuple t):
"""
>>> assign3_typed(t)
(1, 2, 3)
>>> assign3_typed(l)
Traceback (most recent call last):
TypeError: Argument 't' has incorrect type (expected tuple, got list)
>>> a,b,c = (1,) # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: ...
>>> assign3_typed((1,))
Traceback (most recent call last):
ValueError: need more than 1 value to unpack
>>> a,b,c = (1,2) # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: ...
>>> assign3_typed((1,2))
Traceback (most recent call last):
ValueError: need more than 2 values to unpack
>>> a,b,c = (1,2,3,4) # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: ...
>>> assign3_typed((1,2,3,4))
Traceback (most recent call last):
ValueError: too many values to unpack (expected 3)
>>> a,b = 99,98
>>> a,b = t # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: ...
>>> a,b
(99, 98)
"""
a,b,c = t
return (a,b,c)
def assign3_int(t):
"""
>>> assign3_int(l)
(1, 2, 3)
"""
cdef int a,b,c
a,b,c = t
return (a,b,c)
def assign3_mixed1(t):
"""
>>> assign3_mixed1(l)
(1, 2, 3)
"""
cdef int a
a,b,c = t
return (a,b,c)
def assign3_mixed2(t):
"""
>>> assign3_mixed2(l)
(1, 2, 3)
"""
cdef int b
a,b,c = t
return (a,b,c)
def assign3_mixed3(t):
"""
>>> assign3_mixed3(l)
(1, 2, 3)
"""
cdef int c
a,b,c = t
return (a,b,c)
def assign3_mixed4(t):
cdef int b,c
a,b,c = t
return (a,b,c)
def test_overwrite(t):
"""
>>> test_overwrite(l)
(99, 98)
>>> test_overwrite(t)
(99, 98)
"""
a,b = 99,98
try:
a,b = t
except ValueError:
pass
return (a,b)
def test_overwrite_int(t):
"""
>>> test_overwrite_int(l)
(99, 98)
>>> test_overwrite_int(t)
(99, 98)
"""
cdef int a,b
a,b = 99,98
try:
a,b = t
except ValueError:
pass
return (a,b)
def test_overwrite_mixed(t):
"""
>>> test_overwrite_mixed(l)
(99, 98)
>>> test_overwrite_mixed(t)
(99, 98)
"""
cdef int b
a,b = 99,98
try:
a,b = t
except ValueError:
pass
return (a,b)
def test_overwrite_mixed2(t):
"""
>>> test_overwrite_mixed2(l)
(99, 98)
>>> test_overwrite_mixed2(t)
(99, 98)
"""
cdef int a
a,b = 99,98
try:
a,b = t
except ValueError:
pass
return (a,b)
|