Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit afcee8b

Browse files
committed
count keyword only arguments as part of the total
1 parent f3b7a25 commit afcee8b

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

Lib/test/test_extcall.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@
280280
Traceback (most recent call last):
281281
...
282282
TypeError: f() takes exactly 1 argument (5 given)
283+
>>> def f(a, *, kw):
284+
... pass
285+
>>> f(6, 4, kw=4)
286+
Traceback (most recent call last):
287+
...
288+
TypeError: f() takes exactly 2 arguments (3 given)
283289
"""
284290

285291
import sys

Python/ceval.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,8 +3078,8 @@ PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
30783078
"argument%s (%d given)",
30793079
co->co_name,
30803080
defcount ? "at most" : "exactly",
3081-
co->co_argcount,
3082-
co->co_argcount == 1 ? "" : "s",
3081+
total_args,
3082+
total_args == 1 ? "" : "s",
30833083
argcount + kwcount);
30843084
goto fail;
30853085
}

0 commit comments

Comments
 (0)