Cython has moved to github.
cython-devel
view tests/run/starargs.pyx @ 1622:4f0327bdebc9
test for temp allocation bug in call
| author | Robert Bradshaw <robertwb@math.washington.edu> |
|---|---|
| date | Sat Jan 17 01:25:34 2009 -0800 (3 years ago) |
| parents | 90e24d236a55 |
| children | 82d312a9f1fc |
line source
1 __doc__ = u"""
2 >>> spam(1,2,3)
3 (1, 2, 3)
4 >>> spam(1,2)
5 Traceback (most recent call last):
6 TypeError: spam() takes exactly 3 positional arguments (2 given)
7 >>> spam(1,2,3,4)
8 Traceback (most recent call last):
9 TypeError: spam() takes exactly 3 positional arguments (4 given)
10 >>> spam(1,2,3, a=1)
11 Traceback (most recent call last):
12 TypeError: spam() got an unexpected keyword argument 'a'
14 >>> grail(1,2,3)
15 (1, 2, 3, ())
16 >>> grail(1,2,3,4)
17 (1, 2, 3, (4,))
18 >>> grail(1,2,3,4,5,6,7,8,9)
19 (1, 2, 3, (4, 5, 6, 7, 8, 9))
20 >>> grail(1,2)
21 Traceback (most recent call last):
22 TypeError: grail() takes at least 3 positional arguments (2 given)
23 >>> grail(1,2,3, a=1)
24 Traceback (most recent call last):
25 TypeError: grail() got an unexpected keyword argument 'a'
27 >>> swallow(1,2,3)
28 (1, 2, 3, ())
29 >>> swallow(1,2,3,4)
30 Traceback (most recent call last):
31 TypeError: swallow() takes exactly 3 positional arguments (4 given)
32 >>> swallow(1,2,3, a=1, b=2)
33 (1, 2, 3, (('a', 1), ('b', 2)))
34 >>> swallow(1,2,3, x=1)
35 Traceback (most recent call last):
36 TypeError: swallow() got multiple values for keyword argument 'x'
38 >>> creosote(1,2,3)
39 (1, 2, 3, (), ())
40 >>> creosote(1,2,3,4)
41 (1, 2, 3, (4,), ())
42 >>> creosote(1,2,3, a=1)
43 (1, 2, 3, (), (('a', 1),))
44 >>> creosote(1,2,3,4, a=1, b=2)
45 (1, 2, 3, (4,), (('a', 1), ('b', 2)))
46 >>> creosote(1,2,3,4, x=1)
47 Traceback (most recent call last):
48 TypeError: creosote() got multiple values for keyword argument 'x'
50 >>> onlyt(1)
51 (1,)
52 >>> onlyt(1,2)
53 (1, 2)
54 >>> onlyt(a=1)
55 Traceback (most recent call last):
56 TypeError: onlyt() got an unexpected keyword argument 'a'
57 >>> onlyt(1, a=2)
58 Traceback (most recent call last):
59 TypeError: onlyt() got an unexpected keyword argument 'a'
61 >>> onlyk(a=1)
62 (('a', 1),)
63 >>> onlyk(a=1, b=2)
64 (('a', 1), ('b', 2))
65 >>> onlyk(1)
66 Traceback (most recent call last):
67 TypeError: onlyk() takes exactly 0 positional arguments (1 given)
68 >>> onlyk(1, 2)
69 Traceback (most recent call last):
70 TypeError: onlyk() takes exactly 0 positional arguments (2 given)
71 >>> onlyk(1, a=1, b=2)
72 Traceback (most recent call last):
73 TypeError: onlyk() takes exactly 0 positional arguments (1 given)
75 >>> tk(a=1)
76 (('a', 1),)
77 >>> tk(a=1, b=2)
78 (('a', 1), ('b', 2))
79 >>> tk(1)
80 (1,)
81 >>> tk(1, 2)
82 (1, 2)
83 >>> tk(1, a=1, b=2)
84 (1, ('a', 1), ('b', 2))
85 """
87 cdef sorteditems(d):
88 l = list(d.items())
89 l.sort()
90 return tuple(l)
92 def spam(x, y, z):
93 return (x, y, z)
95 def grail(x, y, z, *a):
96 return (x, y, z, a)
98 def swallow(x, y, z, **k):
99 return (x, y, z, sorteditems(k))
101 def creosote(x, y, z, *a, **k):
102 return (x, y, z, a, sorteditems(k))
104 def onlyt(*a):
105 return a
107 def onlyk(**k):
108 return sorteditems(k)
110 def tk(*a, **k):
111 return a + sorteditems(k)
