| 1 | n/a | |
|---|
| 2 | n/a | """Doctest for method/function calls. |
|---|
| 3 | n/a | |
|---|
| 4 | n/a | We're going the use these types for extra testing |
|---|
| 5 | n/a | |
|---|
| 6 | n/a | >>> from collections import UserList |
|---|
| 7 | n/a | >>> from collections import UserDict |
|---|
| 8 | n/a | |
|---|
| 9 | n/a | We're defining four helper functions |
|---|
| 10 | n/a | |
|---|
| 11 | n/a | >>> def e(a,b): |
|---|
| 12 | n/a | ... print(a, b) |
|---|
| 13 | n/a | |
|---|
| 14 | n/a | >>> def f(*a, **k): |
|---|
| 15 | n/a | ... print(a, support.sortdict(k)) |
|---|
| 16 | n/a | |
|---|
| 17 | n/a | >>> def g(x, *y, **z): |
|---|
| 18 | n/a | ... print(x, y, support.sortdict(z)) |
|---|
| 19 | n/a | |
|---|
| 20 | n/a | >>> def h(j=1, a=2, h=3): |
|---|
| 21 | n/a | ... print(j, a, h) |
|---|
| 22 | n/a | |
|---|
| 23 | n/a | Argument list examples |
|---|
| 24 | n/a | |
|---|
| 25 | n/a | >>> f() |
|---|
| 26 | n/a | () {} |
|---|
| 27 | n/a | >>> f(1) |
|---|
| 28 | n/a | (1,) {} |
|---|
| 29 | n/a | >>> f(1, 2) |
|---|
| 30 | n/a | (1, 2) {} |
|---|
| 31 | n/a | >>> f(1, 2, 3) |
|---|
| 32 | n/a | (1, 2, 3) {} |
|---|
| 33 | n/a | >>> f(1, 2, 3, *(4, 5)) |
|---|
| 34 | n/a | (1, 2, 3, 4, 5) {} |
|---|
| 35 | n/a | >>> f(1, 2, 3, *[4, 5]) |
|---|
| 36 | n/a | (1, 2, 3, 4, 5) {} |
|---|
| 37 | n/a | >>> f(*[1, 2, 3], 4, 5) |
|---|
| 38 | n/a | (1, 2, 3, 4, 5) {} |
|---|
| 39 | n/a | >>> f(1, 2, 3, *UserList([4, 5])) |
|---|
| 40 | n/a | (1, 2, 3, 4, 5) {} |
|---|
| 41 | n/a | >>> f(1, 2, 3, *[4, 5], *[6, 7]) |
|---|
| 42 | n/a | (1, 2, 3, 4, 5, 6, 7) {} |
|---|
| 43 | n/a | >>> f(1, *[2, 3], 4, *[5, 6], 7) |
|---|
| 44 | n/a | (1, 2, 3, 4, 5, 6, 7) {} |
|---|
| 45 | n/a | >>> f(*UserList([1, 2]), *UserList([3, 4]), 5, *UserList([6, 7])) |
|---|
| 46 | n/a | (1, 2, 3, 4, 5, 6, 7) {} |
|---|
| 47 | n/a | |
|---|
| 48 | n/a | Here we add keyword arguments |
|---|
| 49 | n/a | |
|---|
| 50 | n/a | >>> f(1, 2, 3, **{'a':4, 'b':5}) |
|---|
| 51 | n/a | (1, 2, 3) {'a': 4, 'b': 5} |
|---|
| 52 | n/a | >>> f(1, 2, **{'a': -1, 'b': 5}, **{'a': 4, 'c': 6}) |
|---|
| 53 | n/a | Traceback (most recent call last): |
|---|
| 54 | n/a | ... |
|---|
| 55 | n/a | TypeError: f() got multiple values for keyword argument 'a' |
|---|
| 56 | n/a | >>> f(1, 2, **{'a': -1, 'b': 5}, a=4, c=6) |
|---|
| 57 | n/a | Traceback (most recent call last): |
|---|
| 58 | n/a | ... |
|---|
| 59 | n/a | TypeError: f() got multiple values for keyword argument 'a' |
|---|
| 60 | n/a | >>> f(1, 2, a=3, **{'a': 4}, **{'a': 5}) |
|---|
| 61 | n/a | Traceback (most recent call last): |
|---|
| 62 | n/a | ... |
|---|
| 63 | n/a | TypeError: f() got multiple values for keyword argument 'a' |
|---|
| 64 | n/a | >>> f(1, 2, 3, *[4, 5], **{'a':6, 'b':7}) |
|---|
| 65 | n/a | (1, 2, 3, 4, 5) {'a': 6, 'b': 7} |
|---|
| 66 | n/a | >>> f(1, 2, 3, x=4, y=5, *(6, 7), **{'a':8, 'b': 9}) |
|---|
| 67 | n/a | (1, 2, 3, 6, 7) {'a': 8, 'b': 9, 'x': 4, 'y': 5} |
|---|
| 68 | n/a | >>> f(1, 2, 3, *[4, 5], **{'c': 8}, **{'a':6, 'b':7}) |
|---|
| 69 | n/a | (1, 2, 3, 4, 5) {'a': 6, 'b': 7, 'c': 8} |
|---|
| 70 | n/a | >>> f(1, 2, 3, *(4, 5), x=6, y=7, **{'a':8, 'b': 9}) |
|---|
| 71 | n/a | (1, 2, 3, 4, 5) {'a': 8, 'b': 9, 'x': 6, 'y': 7} |
|---|
| 72 | n/a | |
|---|
| 73 | n/a | >>> f(1, 2, 3, **UserDict(a=4, b=5)) |
|---|
| 74 | n/a | (1, 2, 3) {'a': 4, 'b': 5} |
|---|
| 75 | n/a | >>> f(1, 2, 3, *(4, 5), **UserDict(a=6, b=7)) |
|---|
| 76 | n/a | (1, 2, 3, 4, 5) {'a': 6, 'b': 7} |
|---|
| 77 | n/a | >>> f(1, 2, 3, x=4, y=5, *(6, 7), **UserDict(a=8, b=9)) |
|---|
| 78 | n/a | (1, 2, 3, 6, 7) {'a': 8, 'b': 9, 'x': 4, 'y': 5} |
|---|
| 79 | n/a | >>> f(1, 2, 3, *(4, 5), x=6, y=7, **UserDict(a=8, b=9)) |
|---|
| 80 | n/a | (1, 2, 3, 4, 5) {'a': 8, 'b': 9, 'x': 6, 'y': 7} |
|---|
| 81 | n/a | |
|---|
| 82 | n/a | Examples with invalid arguments (TypeErrors). We're also testing the function |
|---|
| 83 | n/a | names in the exception messages. |
|---|
| 84 | n/a | |
|---|
| 85 | n/a | Verify clearing of SF bug #733667 |
|---|
| 86 | n/a | |
|---|
| 87 | n/a | >>> e(c=4) |
|---|
| 88 | n/a | Traceback (most recent call last): |
|---|
| 89 | n/a | ... |
|---|
| 90 | n/a | TypeError: e() got an unexpected keyword argument 'c' |
|---|
| 91 | n/a | |
|---|
| 92 | n/a | >>> g() |
|---|
| 93 | n/a | Traceback (most recent call last): |
|---|
| 94 | n/a | ... |
|---|
| 95 | n/a | TypeError: g() missing 1 required positional argument: 'x' |
|---|
| 96 | n/a | |
|---|
| 97 | n/a | >>> g(*()) |
|---|
| 98 | n/a | Traceback (most recent call last): |
|---|
| 99 | n/a | ... |
|---|
| 100 | n/a | TypeError: g() missing 1 required positional argument: 'x' |
|---|
| 101 | n/a | |
|---|
| 102 | n/a | >>> g(*(), **{}) |
|---|
| 103 | n/a | Traceback (most recent call last): |
|---|
| 104 | n/a | ... |
|---|
| 105 | n/a | TypeError: g() missing 1 required positional argument: 'x' |
|---|
| 106 | n/a | |
|---|
| 107 | n/a | >>> g(1) |
|---|
| 108 | n/a | 1 () {} |
|---|
| 109 | n/a | >>> g(1, 2) |
|---|
| 110 | n/a | 1 (2,) {} |
|---|
| 111 | n/a | >>> g(1, 2, 3) |
|---|
| 112 | n/a | 1 (2, 3) {} |
|---|
| 113 | n/a | >>> g(1, 2, 3, *(4, 5)) |
|---|
| 114 | n/a | 1 (2, 3, 4, 5) {} |
|---|
| 115 | n/a | |
|---|
| 116 | n/a | >>> class Nothing: pass |
|---|
| 117 | n/a | ... |
|---|
| 118 | n/a | >>> g(*Nothing()) |
|---|
| 119 | n/a | Traceback (most recent call last): |
|---|
| 120 | n/a | ... |
|---|
| 121 | n/a | TypeError: g() argument after * must be an iterable, not Nothing |
|---|
| 122 | n/a | |
|---|
| 123 | n/a | >>> class Nothing: |
|---|
| 124 | n/a | ... def __len__(self): return 5 |
|---|
| 125 | n/a | ... |
|---|
| 126 | n/a | |
|---|
| 127 | n/a | >>> g(*Nothing()) |
|---|
| 128 | n/a | Traceback (most recent call last): |
|---|
| 129 | n/a | ... |
|---|
| 130 | n/a | TypeError: g() argument after * must be an iterable, not Nothing |
|---|
| 131 | n/a | |
|---|
| 132 | n/a | >>> class Nothing(): |
|---|
| 133 | n/a | ... def __len__(self): return 5 |
|---|
| 134 | n/a | ... def __getitem__(self, i): |
|---|
| 135 | n/a | ... if i<3: return i |
|---|
| 136 | n/a | ... else: raise IndexError(i) |
|---|
| 137 | n/a | ... |
|---|
| 138 | n/a | |
|---|
| 139 | n/a | >>> g(*Nothing()) |
|---|
| 140 | n/a | 0 (1, 2) {} |
|---|
| 141 | n/a | |
|---|
| 142 | n/a | >>> class Nothing: |
|---|
| 143 | n/a | ... def __init__(self): self.c = 0 |
|---|
| 144 | n/a | ... def __iter__(self): return self |
|---|
| 145 | n/a | ... def __next__(self): |
|---|
| 146 | n/a | ... if self.c == 4: |
|---|
| 147 | n/a | ... raise StopIteration |
|---|
| 148 | n/a | ... c = self.c |
|---|
| 149 | n/a | ... self.c += 1 |
|---|
| 150 | n/a | ... return c |
|---|
| 151 | n/a | ... |
|---|
| 152 | n/a | |
|---|
| 153 | n/a | >>> g(*Nothing()) |
|---|
| 154 | n/a | 0 (1, 2, 3) {} |
|---|
| 155 | n/a | |
|---|
| 156 | n/a | Check for issue #4806: Does a TypeError in a generator get propagated with the |
|---|
| 157 | n/a | right error message? (Also check with other iterables.) |
|---|
| 158 | n/a | |
|---|
| 159 | n/a | >>> def broken(): raise TypeError("myerror") |
|---|
| 160 | n/a | ... |
|---|
| 161 | n/a | |
|---|
| 162 | n/a | >>> g(*(broken() for i in range(1))) |
|---|
| 163 | n/a | Traceback (most recent call last): |
|---|
| 164 | n/a | ... |
|---|
| 165 | n/a | TypeError: myerror |
|---|
| 166 | n/a | |
|---|
| 167 | n/a | >>> class BrokenIterable1: |
|---|
| 168 | n/a | ... def __iter__(self): |
|---|
| 169 | n/a | ... raise TypeError('myerror') |
|---|
| 170 | n/a | ... |
|---|
| 171 | n/a | >>> g(*BrokenIterable1()) |
|---|
| 172 | n/a | Traceback (most recent call last): |
|---|
| 173 | n/a | ... |
|---|
| 174 | n/a | TypeError: myerror |
|---|
| 175 | n/a | |
|---|
| 176 | n/a | >>> class BrokenIterable2: |
|---|
| 177 | n/a | ... def __iter__(self): |
|---|
| 178 | n/a | ... yield 0 |
|---|
| 179 | n/a | ... raise TypeError('myerror') |
|---|
| 180 | n/a | ... |
|---|
| 181 | n/a | >>> g(*BrokenIterable2()) |
|---|
| 182 | n/a | Traceback (most recent call last): |
|---|
| 183 | n/a | ... |
|---|
| 184 | n/a | TypeError: myerror |
|---|
| 185 | n/a | |
|---|
| 186 | n/a | >>> class BrokenSequence: |
|---|
| 187 | n/a | ... def __getitem__(self, idx): |
|---|
| 188 | n/a | ... raise TypeError('myerror') |
|---|
| 189 | n/a | ... |
|---|
| 190 | n/a | >>> g(*BrokenSequence()) |
|---|
| 191 | n/a | Traceback (most recent call last): |
|---|
| 192 | n/a | ... |
|---|
| 193 | n/a | TypeError: myerror |
|---|
| 194 | n/a | |
|---|
| 195 | n/a | Make sure that the function doesn't stomp the dictionary |
|---|
| 196 | n/a | |
|---|
| 197 | n/a | >>> d = {'a': 1, 'b': 2, 'c': 3} |
|---|
| 198 | n/a | >>> d2 = d.copy() |
|---|
| 199 | n/a | >>> g(1, d=4, **d) |
|---|
| 200 | n/a | 1 () {'a': 1, 'b': 2, 'c': 3, 'd': 4} |
|---|
| 201 | n/a | >>> d == d2 |
|---|
| 202 | n/a | True |
|---|
| 203 | n/a | |
|---|
| 204 | n/a | What about willful misconduct? |
|---|
| 205 | n/a | |
|---|
| 206 | n/a | >>> def saboteur(**kw): |
|---|
| 207 | n/a | ... kw['x'] = 'm' |
|---|
| 208 | n/a | ... return kw |
|---|
| 209 | n/a | |
|---|
| 210 | n/a | >>> d = {} |
|---|
| 211 | n/a | >>> kw = saboteur(a=1, **d) |
|---|
| 212 | n/a | >>> d |
|---|
| 213 | n/a | {} |
|---|
| 214 | n/a | |
|---|
| 215 | n/a | |
|---|
| 216 | n/a | >>> g(1, 2, 3, **{'x': 4, 'y': 5}) |
|---|
| 217 | n/a | Traceback (most recent call last): |
|---|
| 218 | n/a | ... |
|---|
| 219 | n/a | TypeError: g() got multiple values for argument 'x' |
|---|
| 220 | n/a | |
|---|
| 221 | n/a | >>> f(**{1:2}) |
|---|
| 222 | n/a | Traceback (most recent call last): |
|---|
| 223 | n/a | ... |
|---|
| 224 | n/a | TypeError: f() keywords must be strings |
|---|
| 225 | n/a | |
|---|
| 226 | n/a | >>> h(**{'e': 2}) |
|---|
| 227 | n/a | Traceback (most recent call last): |
|---|
| 228 | n/a | ... |
|---|
| 229 | n/a | TypeError: h() got an unexpected keyword argument 'e' |
|---|
| 230 | n/a | |
|---|
| 231 | n/a | >>> h(*h) |
|---|
| 232 | n/a | Traceback (most recent call last): |
|---|
| 233 | n/a | ... |
|---|
| 234 | n/a | TypeError: h() argument after * must be an iterable, not function |
|---|
| 235 | n/a | |
|---|
| 236 | n/a | >>> h(1, *h) |
|---|
| 237 | n/a | Traceback (most recent call last): |
|---|
| 238 | n/a | ... |
|---|
| 239 | n/a | TypeError: h() argument after * must be an iterable, not function |
|---|
| 240 | n/a | |
|---|
| 241 | n/a | >>> h(*[1], *h) |
|---|
| 242 | n/a | Traceback (most recent call last): |
|---|
| 243 | n/a | ... |
|---|
| 244 | n/a | TypeError: h() argument after * must be an iterable, not function |
|---|
| 245 | n/a | |
|---|
| 246 | n/a | >>> dir(*h) |
|---|
| 247 | n/a | Traceback (most recent call last): |
|---|
| 248 | n/a | ... |
|---|
| 249 | n/a | TypeError: dir() argument after * must be an iterable, not function |
|---|
| 250 | n/a | |
|---|
| 251 | n/a | >>> None(*h) |
|---|
| 252 | n/a | Traceback (most recent call last): |
|---|
| 253 | n/a | ... |
|---|
| 254 | n/a | TypeError: NoneType object argument after * must be an iterable, \ |
|---|
| 255 | n/a | not function |
|---|
| 256 | n/a | |
|---|
| 257 | n/a | >>> h(**h) |
|---|
| 258 | n/a | Traceback (most recent call last): |
|---|
| 259 | n/a | ... |
|---|
| 260 | n/a | TypeError: h() argument after ** must be a mapping, not function |
|---|
| 261 | n/a | |
|---|
| 262 | n/a | >>> h(**[]) |
|---|
| 263 | n/a | Traceback (most recent call last): |
|---|
| 264 | n/a | ... |
|---|
| 265 | n/a | TypeError: h() argument after ** must be a mapping, not list |
|---|
| 266 | n/a | |
|---|
| 267 | n/a | >>> h(a=1, **h) |
|---|
| 268 | n/a | Traceback (most recent call last): |
|---|
| 269 | n/a | ... |
|---|
| 270 | n/a | TypeError: h() argument after ** must be a mapping, not function |
|---|
| 271 | n/a | |
|---|
| 272 | n/a | >>> h(a=1, **[]) |
|---|
| 273 | n/a | Traceback (most recent call last): |
|---|
| 274 | n/a | ... |
|---|
| 275 | n/a | TypeError: h() argument after ** must be a mapping, not list |
|---|
| 276 | n/a | |
|---|
| 277 | n/a | >>> h(**{'a': 1}, **h) |
|---|
| 278 | n/a | Traceback (most recent call last): |
|---|
| 279 | n/a | ... |
|---|
| 280 | n/a | TypeError: h() argument after ** must be a mapping, not function |
|---|
| 281 | n/a | |
|---|
| 282 | n/a | >>> h(**{'a': 1}, **[]) |
|---|
| 283 | n/a | Traceback (most recent call last): |
|---|
| 284 | n/a | ... |
|---|
| 285 | n/a | TypeError: h() argument after ** must be a mapping, not list |
|---|
| 286 | n/a | |
|---|
| 287 | n/a | >>> dir(**h) |
|---|
| 288 | n/a | Traceback (most recent call last): |
|---|
| 289 | n/a | ... |
|---|
| 290 | n/a | TypeError: dir() argument after ** must be a mapping, not function |
|---|
| 291 | n/a | |
|---|
| 292 | n/a | >>> None(**h) |
|---|
| 293 | n/a | Traceback (most recent call last): |
|---|
| 294 | n/a | ... |
|---|
| 295 | n/a | TypeError: NoneType object argument after ** must be a mapping, \ |
|---|
| 296 | n/a | not function |
|---|
| 297 | n/a | |
|---|
| 298 | n/a | >>> dir(b=1, **{'b': 1}) |
|---|
| 299 | n/a | Traceback (most recent call last): |
|---|
| 300 | n/a | ... |
|---|
| 301 | n/a | TypeError: dir() got multiple values for keyword argument 'b' |
|---|
| 302 | n/a | |
|---|
| 303 | n/a | Another helper function |
|---|
| 304 | n/a | |
|---|
| 305 | n/a | >>> def f2(*a, **b): |
|---|
| 306 | n/a | ... return a, b |
|---|
| 307 | n/a | |
|---|
| 308 | n/a | |
|---|
| 309 | n/a | >>> d = {} |
|---|
| 310 | n/a | >>> for i in range(512): |
|---|
| 311 | n/a | ... key = 'k%d' % i |
|---|
| 312 | n/a | ... d[key] = i |
|---|
| 313 | n/a | >>> a, b = f2(1, *(2,3), **d) |
|---|
| 314 | n/a | >>> len(a), len(b), b == d |
|---|
| 315 | n/a | (3, 512, True) |
|---|
| 316 | n/a | |
|---|
| 317 | n/a | >>> class Foo: |
|---|
| 318 | n/a | ... def method(self, arg1, arg2): |
|---|
| 319 | n/a | ... return arg1+arg2 |
|---|
| 320 | n/a | |
|---|
| 321 | n/a | >>> x = Foo() |
|---|
| 322 | n/a | >>> Foo.method(*(x, 1, 2)) |
|---|
| 323 | n/a | 3 |
|---|
| 324 | n/a | >>> Foo.method(x, *(1, 2)) |
|---|
| 325 | n/a | 3 |
|---|
| 326 | n/a | >>> Foo.method(*(1, 2, 3)) |
|---|
| 327 | n/a | 5 |
|---|
| 328 | n/a | >>> Foo.method(1, *[2, 3]) |
|---|
| 329 | n/a | 5 |
|---|
| 330 | n/a | |
|---|
| 331 | n/a | A PyCFunction that takes only positional parameters should allow an |
|---|
| 332 | n/a | empty keyword dictionary to pass without a complaint, but raise a |
|---|
| 333 | n/a | TypeError if te dictionary is not empty |
|---|
| 334 | n/a | |
|---|
| 335 | n/a | >>> try: |
|---|
| 336 | n/a | ... silence = id(1, *{}) |
|---|
| 337 | n/a | ... True |
|---|
| 338 | n/a | ... except: |
|---|
| 339 | n/a | ... False |
|---|
| 340 | n/a | True |
|---|
| 341 | n/a | |
|---|
| 342 | n/a | >>> id(1, **{'foo': 1}) |
|---|
| 343 | n/a | Traceback (most recent call last): |
|---|
| 344 | n/a | ... |
|---|
| 345 | n/a | TypeError: id() takes no keyword arguments |
|---|
| 346 | n/a | |
|---|
| 347 | n/a | A corner case of keyword dictionary items being deleted during |
|---|
| 348 | n/a | the function call setup. See <http://bugs.python.org/issue2016>. |
|---|
| 349 | n/a | |
|---|
| 350 | n/a | >>> class Name(str): |
|---|
| 351 | n/a | ... def __eq__(self, other): |
|---|
| 352 | n/a | ... try: |
|---|
| 353 | n/a | ... del x[self] |
|---|
| 354 | n/a | ... except KeyError: |
|---|
| 355 | n/a | ... pass |
|---|
| 356 | n/a | ... return str.__eq__(self, other) |
|---|
| 357 | n/a | ... def __hash__(self): |
|---|
| 358 | n/a | ... return str.__hash__(self) |
|---|
| 359 | n/a | |
|---|
| 360 | n/a | >>> x = {Name("a"):1, Name("b"):2} |
|---|
| 361 | n/a | >>> def f(a, b): |
|---|
| 362 | n/a | ... print(a,b) |
|---|
| 363 | n/a | >>> f(**x) |
|---|
| 364 | n/a | 1 2 |
|---|
| 365 | n/a | |
|---|
| 366 | n/a | Too many arguments: |
|---|
| 367 | n/a | |
|---|
| 368 | n/a | >>> def f(): pass |
|---|
| 369 | n/a | >>> f(1) |
|---|
| 370 | n/a | Traceback (most recent call last): |
|---|
| 371 | n/a | ... |
|---|
| 372 | n/a | TypeError: f() takes 0 positional arguments but 1 was given |
|---|
| 373 | n/a | >>> def f(a): pass |
|---|
| 374 | n/a | >>> f(1, 2) |
|---|
| 375 | n/a | Traceback (most recent call last): |
|---|
| 376 | n/a | ... |
|---|
| 377 | n/a | TypeError: f() takes 1 positional argument but 2 were given |
|---|
| 378 | n/a | >>> def f(a, b=1): pass |
|---|
| 379 | n/a | >>> f(1, 2, 3) |
|---|
| 380 | n/a | Traceback (most recent call last): |
|---|
| 381 | n/a | ... |
|---|
| 382 | n/a | TypeError: f() takes from 1 to 2 positional arguments but 3 were given |
|---|
| 383 | n/a | >>> def f(*, kw): pass |
|---|
| 384 | n/a | >>> f(1, kw=3) |
|---|
| 385 | n/a | Traceback (most recent call last): |
|---|
| 386 | n/a | ... |
|---|
| 387 | n/a | TypeError: f() takes 0 positional arguments but 1 positional argument (and 1 keyword-only argument) were given |
|---|
| 388 | n/a | >>> def f(*, kw, b): pass |
|---|
| 389 | n/a | >>> f(1, 2, 3, b=3, kw=3) |
|---|
| 390 | n/a | Traceback (most recent call last): |
|---|
| 391 | n/a | ... |
|---|
| 392 | n/a | TypeError: f() takes 0 positional arguments but 3 positional arguments (and 2 keyword-only arguments) were given |
|---|
| 393 | n/a | >>> def f(a, b=2, *, kw): pass |
|---|
| 394 | n/a | >>> f(2, 3, 4, kw=4) |
|---|
| 395 | n/a | Traceback (most recent call last): |
|---|
| 396 | n/a | ... |
|---|
| 397 | n/a | TypeError: f() takes from 1 to 2 positional arguments but 3 positional arguments (and 1 keyword-only argument) were given |
|---|
| 398 | n/a | |
|---|
| 399 | n/a | Too few and missing arguments: |
|---|
| 400 | n/a | |
|---|
| 401 | n/a | >>> def f(a): pass |
|---|
| 402 | n/a | >>> f() |
|---|
| 403 | n/a | Traceback (most recent call last): |
|---|
| 404 | n/a | ... |
|---|
| 405 | n/a | TypeError: f() missing 1 required positional argument: 'a' |
|---|
| 406 | n/a | >>> def f(a, b): pass |
|---|
| 407 | n/a | >>> f() |
|---|
| 408 | n/a | Traceback (most recent call last): |
|---|
| 409 | n/a | ... |
|---|
| 410 | n/a | TypeError: f() missing 2 required positional arguments: 'a' and 'b' |
|---|
| 411 | n/a | >>> def f(a, b, c): pass |
|---|
| 412 | n/a | >>> f() |
|---|
| 413 | n/a | Traceback (most recent call last): |
|---|
| 414 | n/a | ... |
|---|
| 415 | n/a | TypeError: f() missing 3 required positional arguments: 'a', 'b', and 'c' |
|---|
| 416 | n/a | >>> def f(a, b, c, d, e): pass |
|---|
| 417 | n/a | >>> f() |
|---|
| 418 | n/a | Traceback (most recent call last): |
|---|
| 419 | n/a | ... |
|---|
| 420 | n/a | TypeError: f() missing 5 required positional arguments: 'a', 'b', 'c', 'd', and 'e' |
|---|
| 421 | n/a | >>> def f(a, b=4, c=5, d=5): pass |
|---|
| 422 | n/a | >>> f(c=12, b=9) |
|---|
| 423 | n/a | Traceback (most recent call last): |
|---|
| 424 | n/a | ... |
|---|
| 425 | n/a | TypeError: f() missing 1 required positional argument: 'a' |
|---|
| 426 | n/a | |
|---|
| 427 | n/a | Same with keyword only args: |
|---|
| 428 | n/a | |
|---|
| 429 | n/a | >>> def f(*, w): pass |
|---|
| 430 | n/a | >>> f() |
|---|
| 431 | n/a | Traceback (most recent call last): |
|---|
| 432 | n/a | ... |
|---|
| 433 | n/a | TypeError: f() missing 1 required keyword-only argument: 'w' |
|---|
| 434 | n/a | >>> def f(*, a, b, c, d, e): pass |
|---|
| 435 | n/a | >>> f() |
|---|
| 436 | n/a | Traceback (most recent call last): |
|---|
| 437 | n/a | ... |
|---|
| 438 | n/a | TypeError: f() missing 5 required keyword-only arguments: 'a', 'b', 'c', 'd', and 'e' |
|---|
| 439 | n/a | |
|---|
| 440 | n/a | """ |
|---|
| 441 | n/a | |
|---|
| 442 | n/a | import sys |
|---|
| 443 | n/a | from test import support |
|---|
| 444 | n/a | |
|---|
| 445 | n/a | def test_main(): |
|---|
| 446 | n/a | support.run_doctest(sys.modules[__name__], True) |
|---|
| 447 | n/a | |
|---|
| 448 | n/a | if __name__ == '__main__': |
|---|
| 449 | n/a | test_main() |
|---|