kwonlyargscall.pyx 5.16 KB
Newer Older
1 2 3 4
# the calls:

def call0ab(f):
    """
5 6 7
    >>> call0ab(b)
    Traceback (most recent call last):
    TypeError: b() takes exactly 3 positional arguments (2 given)
8 9
    >>> call0ab(c)
    1 2 1
10 11 12 13 14 15 16 17
    >>> call0ab(d)
    1 2 88
    """
    f(a=1,b=2)

def call0abc(f):
    """
    >>> call0abc(b)
18
    1 2 3
19
    >>> call0abc(c)
20
    1 2 3
21 22
    >>> call0abc(d)
    1 2 3
23 24 25 26 27 28 29 30 31 32 33 34 35
    >>> call0abc(e)
    1 2 3 []
    >>> call0abc(f)
    1 2 3 42
    >>> call0abc(m)
    1 2 3
    """
    f(a=1,b=2,c=3)

def call2(f):
    """
    >>> call2(c)
    1 2 1
36
    >>> call2(d)
37
    1 2 88
38 39 40 41 42 43 44 45 46 47 48 49 50
    >>> call2(e)
    1 2 88 []
    >>> call2(f)
    Traceback (most recent call last):
    TypeError: f() needs keyword-only argument c
    >>> call2(g)
    Traceback (most recent call last):
    TypeError: g() needs keyword-only argument c
    >>> call2(m)
    Traceback (most recent call last):
    TypeError: m() needs keyword-only argument c
    """
    f(1,2)
51

52 53 54 55 56 57
def call3(f):
    """
    >>> call3(b)
    1 2 3
    >>> call3(c)
    1 2 3
58 59
    >>> call3(d)
    Traceback (most recent call last):
60
    TypeError: d() takes exactly 2 positional arguments (3 given)
61
    >>> call3(e)
62
    1 2 3 []
63 64
    >>> call3(f)
    Traceback (most recent call last):
65
    TypeError: f() takes exactly 2 positional arguments (3 given)
66 67
    >>> call3(g)
    Traceback (most recent call last):
68
    TypeError: g() takes exactly 2 positional arguments (3 given)
69 70
    >>> call3(h)
    Traceback (most recent call last):
71
    TypeError: h() needs keyword-only argument c
72 73
    >>> call3(k)
    Traceback (most recent call last):
74
    TypeError: k() needs keyword-only argument f
75 76 77
    >>> call3(m)
    Traceback (most recent call last):
    TypeError: m() takes at most 2 positional arguments (3 given)
78
    """
79 80 81
    f(1,2,3)

def call4(f):
82 83 84 85 86 87 88 89 90 91 92
    """
    >>> call4(b)
    Traceback (most recent call last):
    TypeError: b() takes exactly 3 positional arguments (4 given)
    >>> call4(c)
    Traceback (most recent call last):
    TypeError: c() takes at most 3 positional arguments (4 given)
    >>> call4(e)
    Traceback (most recent call last):
    TypeError: e() takes at most 3 positional arguments (4 given)
    """
93 94 95
    f(1,2,3,4)

def call2c(f):
96 97 98 99 100 101 102 103 104 105 106 107 108
    """
    >>> call2c(d)
    1 2 1
    >>> call2c(e)
    1 2 1 []
    >>> call2c(f)
    1 2 1 42
    >>> call2c(g)
    Traceback (most recent call last):
    TypeError: g() needs keyword-only argument f
    >>> call2c(m)
    1 2 1
    """
109 110 111
    f(1,2, c=1)

def call2d(f):
112 113 114 115 116 117 118 119 120 121
    """
    >>> call2d(d)
    Traceback (most recent call last):
    TypeError: d() got an unexpected keyword argument 'd'
    >>> call2d(e)
    1 2 88 [('d', 1)]
    >>> call2d(k)
    Traceback (most recent call last):
    TypeError: k() needs keyword-only argument f
    """
122 123 124
    f(1,2, d=1)

def call3d(f):
125 126 127 128 129
    """
    >>> call3d(h)
    Traceback (most recent call last):
    TypeError: h() needs keyword-only argument c
    """
130 131 132
    f(1,2,3, d=1)

def call2cd(f):
133 134 135 136 137 138 139
    """
    >>> call2cd(f)
    1 2 1 2
    >>> call2cd(m)
    Traceback (most recent call last):
    TypeError: m() got an unexpected keyword argument 'd'
    """
140 141 142
    f(1,2, c=1, d=2)

def call2ce(f):
143 144 145 146 147
    """
    >>> call2ce(f)
    Traceback (most recent call last):
    TypeError: f() got an unexpected keyword argument 'e'
    """
148 149 150
    f(1,2, c=1, e=2)

def call2cde(f):
151 152 153 154
    """
    >>> call2cde(e)
    1 2 1 [('d', 2), ('e', 3)]
    """
155 156 157
    f(1,2, c=1, d=2, e=3)

def call2cf(f):
158 159 160 161 162 163 164 165
    """
    >>> call2cf(g)
    1 2 1 42 17 2 []
    >>> call2cf(h)
    1 2 1 42 17 2 () []
    >>> call2cf(k)
    1 2 1 42 17 2 () []
    """
166 167 168
    f(1,2, c=1, f=2)

def call6cf(f):
169 170 171 172
    """
    >>> call6cf(h)
    1 2 1 42 17 2 (3, 4, 5, 6) []
    """
173 174 175
    f(1,2,3,4,5,6, c=1, f=2)

def call6df(f):
176 177 178 179
    """
    >>> call6df(k)
    1 2 3 1 17 2 (4, 5, 6) []
    """
180 181 182
    f(1,2,3,4,5,6, d=1, f=2)

def call2cfe(f):
183 184 185 186 187 188
    """
    >>> call2cfe(h)
    1 2 1 42 3 2 () []
    >>> call2cfe(k)
    1 2 1 42 3 2 () []
    """
189 190 191
    f(1,2, c=1, f=2, e=3)

def call2cefd(f):
192 193 194 195
    """
    >>> call2cefd(g)
    1 2 1 11 0 2 []
    """
196 197 198
    f(1,2, c=1, e=0, f=2, d=11)

def call2cfex(f):
199 200 201 202
    """
    >>> call2cfex(g)
    1 2 1 42 0 2 [('x', 25)]
    """
203 204
    f(1,2, c=1, f=2, e=0, x=25)

205 206 207 208
def call6argscfexy(f):
    args = (1,2,3,4,5,6)
    f(*args, c=1, f=2, e=3, x=25, y=11)

209
def call6cfexy(f):
210 211 212 213
    """
    >>> call6cfexy(h)
    1 2 1 42 3 2 (3, 4, 5, 6) [('x', 25), ('y', 11)]
    """
214 215 216
    f(1,2,3,4,5,6, c=1, f=2, e=3, x=25, y=11)

def call6dfexy(f):
217 218 219 220
    """
    >>> call6dfexy(k)
    1 2 3 1 3 2 (4, 5, 6) [('x', 25), ('y', 11)]
    """
221 222 223 224 225
    f(1,2,3,4,5,6, d=1, f=2, e=3, x=25, y=11)

# the called functions:

def b(a, b, c):
226
    print a,b,c
227 228

def c(a, b, c=1):
229
    print a,b,c
230 231

def d(a, b, *, c = 88):
232
    print a,b,c
233 234

def e(a, b, c = 88, **kwds):
235 236 237
    kwlist = list(kwds.items())
    kwlist.sort()
    print a,b,c, kwlist
238 239

def f(a, b, *, c, d = 42):
240
    print a,b,c,d
241 242

def g(a, b, *, c, d = 42, e = 17, f, **kwds):
243 244 245
    kwlist = list(kwds.items())
    kwlist.sort()
    print a,b,c,d,e,f, kwlist
246 247

def h(a, b, *args, c, d = 42, e = 17, f, **kwds):
248 249 250
    kwlist = list(kwds.items())
    kwlist.sort()
    print a,b,c,d,e,f, args, kwlist
251 252

def k(a, b, c=1, *args, d = 42, e = 17, f, **kwds):
253 254 255
    kwlist = list(kwds.items())
    kwlist.sort()
    print a,b,c,d,e,f, args, kwlist
256 257 258

def m(a, b=1, *, c):
    print a,b,c