|
66 | 66 | >>> g() |
67 | 67 | Traceback (most recent call last): |
68 | 68 | ... |
69 | | - TypeError: g() takes at least 1 positional argument but 0 were given |
| 69 | + TypeError: g() missing 1 required positional argument: 'x' |
70 | 70 |
|
71 | 71 | >>> g(*()) |
72 | 72 | Traceback (most recent call last): |
73 | 73 | ... |
74 | | - TypeError: g() takes at least 1 positional argument but 0 were given |
| 74 | + TypeError: g() missing 1 required positional argument: 'x' |
75 | 75 |
|
76 | 76 | >>> g(*(), **{}) |
77 | 77 | Traceback (most recent call last): |
78 | 78 | ... |
79 | | - TypeError: g() takes at least 1 positional argument but 0 were given |
| 79 | + TypeError: g() missing 1 required positional argument: 'x' |
80 | 80 |
|
81 | 81 | >>> g(1) |
82 | 82 | 1 () {} |
|
263 | 263 | >>> f(**x) |
264 | 264 | 1 2 |
265 | 265 |
|
266 | | -Some additional tests about positional argument errors: |
| 266 | +Too many arguments: |
267 | 267 |
|
268 | | - >>> def f(a, b): |
269 | | - ... pass |
270 | | - >>> f(b=1) |
| 268 | + >>> def f(): pass |
| 269 | + >>> f(1) |
271 | 270 | Traceback (most recent call last): |
272 | 271 | ... |
273 | | - TypeError: f() takes 2 positional arguments but 1 was given |
274 | | -
|
275 | | - >>> def f(a): |
276 | | - ... pass |
277 | | - >>> f(6, a=4, *(1, 2, 3)) |
| 272 | + TypeError: f() takes 0 positional arguments but 1 was given |
| 273 | + >>> def f(a): pass |
| 274 | + >>> f(1, 2) |
278 | 275 | Traceback (most recent call last): |
279 | 276 | ... |
280 | | - TypeError: f() got multiple values for argument 'a' |
281 | | - >>> def f(a, *, kw): |
282 | | - ... pass |
283 | | - >>> f(6, 4, kw=4) |
| 277 | + TypeError: f() takes 1 positional argument but 2 were given |
| 278 | + >>> def f(a, b=1): pass |
| 279 | + >>> f(1, 2, 3) |
284 | 280 | Traceback (most recent call last): |
285 | 281 | ... |
286 | | - TypeError: f() takes 1 positional argument but 2 positional arguments (and 1 keyword-only argument) were given |
287 | | -
|
288 | | - >>> def f(a): |
289 | | - ... pass |
290 | | - >>> f() |
| 282 | + TypeError: f() takes from 1 to 2 positional arguments but 3 were given |
| 283 | + >>> def f(*, kw): pass |
| 284 | + >>> f(1, kw=3) |
291 | 285 | Traceback (most recent call last): |
292 | 286 | ... |
293 | | - TypeError: f() takes 1 positional argument but 0 were given |
294 | | -
|
295 | | - >>> def f(a, b): |
296 | | - ... pass |
297 | | - >>> f(1) |
| 287 | + TypeError: f() takes 0 positional arguments but 1 positional argument (and 1 keyword-only argument) were given |
| 288 | + >>> def f(*, kw, b): pass |
| 289 | + >>> f(1, 2, 3, b=3, kw=3) |
| 290 | + Traceback (most recent call last): |
| 291 | + ... |
| 292 | + TypeError: f() takes 0 positional arguments but 3 positional arguments (and 2 keyword-only arguments) were given |
| 293 | + >>> def f(a, b=2, *, kw): pass |
| 294 | + >>> f(2, 3, 4, kw=4) |
298 | 295 | Traceback (most recent call last): |
299 | 296 | ... |
300 | | - TypeError: f() takes 2 positional arguments but 1 was given |
| 297 | + TypeError: f() takes from 1 to 2 positional arguments but 3 positional arguments (and 1 keyword-only argument) were given |
301 | 298 |
|
302 | | - >>> def f(a, *b): |
303 | | - ... pass |
| 299 | +Too few and missing arguments: |
| 300 | +
|
| 301 | + >>> def f(a): pass |
304 | 302 | >>> f() |
305 | 303 | Traceback (most recent call last): |
306 | 304 | ... |
307 | | - TypeError: f() takes at least 1 positional argument but 0 were given |
308 | | -
|
309 | | - >>> def f(a, *, kw=4): |
310 | | - ... pass |
311 | | - >>> f(kw=4) |
| 305 | + TypeError: f() missing 1 required positional argument: 'a' |
| 306 | + >>> def f(a, b): pass |
| 307 | + >>> f() |
312 | 308 | Traceback (most recent call last): |
313 | 309 | ... |
314 | | - TypeError: f() takes 1 positional argument but 0 positional arguments (and 1 keyword-only argument) were given |
315 | | -
|
316 | | - >>> def f(a, b=2): |
317 | | - ... pass |
| 310 | + TypeError: f() missing 2 required positional arguments: 'a' and 'b' |
| 311 | + >>> def f(a, b, c): pass |
318 | 312 | >>> f() |
319 | 313 | Traceback (most recent call last): |
320 | 314 | ... |
321 | | - TypeError: f() takes from 1 to 2 positional arguments but 0 were given |
322 | | -
|
323 | | - >>> def f(a, *b): |
324 | | - ... pass |
| 315 | + TypeError: f() missing 3 required positional arguments: 'a', 'b', and 'c' |
| 316 | + >>> def f(a, b, c, d, e): pass |
325 | 317 | >>> f() |
326 | 318 | Traceback (most recent call last): |
327 | 319 | ... |
328 | | - TypeError: f() takes at least 1 positional argument but 0 were given |
329 | | -
|
330 | | - >>> def f(*, kw): |
331 | | - ... pass |
332 | | - >>> f(3, kw=4) |
| 320 | + TypeError: f() missing 5 required positional arguments: 'a', 'b', 'c', 'd', and 'e' |
| 321 | + >>> def f(a, b=4, c=5, d=5): pass |
| 322 | + >>> f(c=12, b=9) |
333 | 323 | Traceback (most recent call last): |
334 | 324 | ... |
335 | | - TypeError: f() takes 0 positional arguments but 1 positional argument (and 1 keyword-only argument) were given |
| 325 | + TypeError: f() missing 1 required positional argument: 'a' |
336 | 326 |
|
337 | | - >>> def f(a, c=3, *b, kw): |
338 | | - ... pass |
| 327 | +Same with keyword only args: |
| 328 | +
|
| 329 | + >>> def f(*, w): pass |
339 | 330 | >>> f() |
340 | 331 | Traceback (most recent call last): |
341 | | - ... |
342 | | - TypeError: f() takes at least 1 positional argument but 0 were given |
343 | | - >>> f(kw=3) |
344 | | - Traceback (most recent call last): |
345 | | - ... |
346 | | - TypeError: f() takes at least 1 positional argument but 0 positional arguments (and 1 keyword-only argument) were given |
347 | | - >>> f(kw=3, c=4) |
| 332 | + ... |
| 333 | + TypeError: f() missing 1 required keyword-only argument: 'w' |
| 334 | + >>> def f(*, a, b, c, d, e): pass |
| 335 | + >>> f() |
348 | 336 | Traceback (most recent call last): |
349 | | - ... |
350 | | - TypeError: f() takes at least 1 positional argument but 1 positional argument (and 1 keyword-only argument) were given |
| 337 | + ... |
| 338 | + TypeError: f() missing 5 required keyword-only arguments: 'a', 'b', 'c', 'd', and 'e' |
| 339 | +
|
351 | 340 | """ |
352 | 341 |
|
353 | 342 | import sys |
|
0 commit comments