Cython has moved to github.
cython-devel
view tests/run/tupleassign.pyx @ 1851:7c9b5a80ccfe
ticket #186: generate more efficient code when tuple-unpacking a typed tuple
| author | Stefan Behnel <scoder@users.berlios.de> |
|---|---|
| date | Fri Mar 13 23:42:09 2009 +0100 (3 years ago) |
| parents | c1d296417c38 |
| children | 82d312a9f1fc |
line source
1 __doc__ = u"""
2 >>> assign3(l)
3 (1, 2, 3)
4 >>> assign3(t)
5 (1, 2, 3)
6 >>> assign3_typed(t)
7 (1, 2, 3)
8 >>> assign3_int(l)
9 (1, 2, 3)
10 >>> assign3_mixed1(l)
11 (1, 2, 3)
12 >>> assign3_mixed2(l)
13 (1, 2, 3)
14 >>> assign3_mixed3(l)
15 (1, 2, 3)
17 >>> assign3_typed(l)
18 Traceback (most recent call last):
19 TypeError: Argument 't' has incorrect type (expected tuple, got list)
21 >>> a,b,c = (1,) # doctest: +ELLIPSIS
22 Traceback (most recent call last):
23 ValueError: ...
24 >>> assign3((1,))
25 Traceback (most recent call last):
26 ValueError: need more than 1 value to unpack
27 >>> assign3_typed((1,))
28 Traceback (most recent call last):
29 ValueError: need more than 1 value to unpack
31 >>> a,b,c = (1,2) # doctest: +ELLIPSIS
32 Traceback (most recent call last):
33 ValueError: ...
34 >>> assign3((1,2))
35 Traceback (most recent call last):
36 ValueError: need more than 2 values to unpack
37 >>> assign3_typed((1,2))
38 Traceback (most recent call last):
39 ValueError: need more than 2 values to unpack
41 >>> a,b,c = (1,2,3,4)
42 Traceback (most recent call last):
43 ValueError: too many values to unpack
44 >>> assign3((1,2,3,4))
45 Traceback (most recent call last):
46 ValueError: too many values to unpack
47 >>> assign3_typed((1,2,3,4))
48 Traceback (most recent call last):
49 ValueError: too many values to unpack
51 >>> a,b = 99,98
52 >>> a,b = t
53 Traceback (most recent call last):
54 ValueError: too many values to unpack
55 >>> a,b
56 (99, 98)
58 >>> test_overwrite(l)
59 (99, 98)
60 >>> test_overwrite(t)
61 (99, 98)
63 >>> test_overwrite_int(l)
64 (99, 98)
65 >>> test_overwrite_int(t)
66 (99, 98)
68 >>> test_overwrite_mixed(l)
69 (99, 98)
70 >>> test_overwrite_mixed(t)
71 (99, 98)
73 >>> test_overwrite_mixed2(l)
74 (99, 98)
75 >>> test_overwrite_mixed2(t)
76 (99, 98)
77 """
79 t = (1,2,3)
80 l = [1,2,3]
82 def assign3(t):
83 a,b,c = t
84 return (a,b,c)
86 def assign3_typed(tuple t):
87 a,b,c = t
88 return (a,b,c)
90 def assign3_int(t):
91 cdef int a,b,c
92 a,b,c = t
93 return (a,b,c)
95 def assign3_mixed1(t):
96 cdef int a
97 a,b,c = t
98 return (a,b,c)
100 def assign3_mixed2(t):
101 cdef int b
102 a,b,c = t
103 return (a,b,c)
105 def assign3_mixed3(t):
106 cdef int c
107 a,b,c = t
108 return (a,b,c)
110 def assign3_mixed4(t):
111 cdef int b,c
112 a,b,c = t
113 return (a,b,c)
115 def test_overwrite(t):
116 a,b = 99,98
117 try:
118 a,b = t
119 except ValueError:
120 pass
121 return (a,b)
123 def test_overwrite_int(t):
124 cdef int a,b
125 a,b = 99,98
126 try:
127 a,b = t
128 except ValueError:
129 pass
130 return (a,b)
132 def test_overwrite_mixed(t):
133 cdef int b
134 a,b = 99,98
135 try:
136 a,b = t
137 except ValueError:
138 pass
139 return (a,b)
141 def test_overwrite_mixed2(t):
142 cdef int a
143 a,b = 99,98
144 try:
145 a,b = t
146 except ValueError:
147 pass
148 return (a,b)
