(f_name, args, kwonly, varargs, defcount, given, values)
| 1425 | "" if missing == 1 else "s", s)) |
| 1426 | |
| 1427 | def _too_many(f_name, args, kwonly, varargs, defcount, given, values): |
| 1428 | atleast = len(args) - defcount |
| 1429 | kwonly_given = len([arg for arg in kwonly if arg in values]) |
| 1430 | if varargs: |
| 1431 | plural = atleast != 1 |
| 1432 | sig = "at least %d" % (atleast,) |
| 1433 | elif defcount: |
| 1434 | plural = True |
| 1435 | sig = "from %d to %d" % (atleast, len(args)) |
| 1436 | else: |
| 1437 | plural = len(args) != 1 |
| 1438 | sig = str(len(args)) |
| 1439 | kwonly_sig = "" |
| 1440 | if kwonly_given: |
| 1441 | msg = " positional argument%s (and %d keyword-only argument%s)" |
| 1442 | kwonly_sig = (msg % ("s" if given != 1 else "", kwonly_given, |
| 1443 | "s" if kwonly_given != 1 else "")) |
| 1444 | raise TypeError("%s() takes %s positional argument%s but %d%s %s given" % |
| 1445 | (f_name, sig, "s" if plural else "", given, kwonly_sig, |
| 1446 | "was" if given == 1 and not kwonly_given else "were")) |
| 1447 | |
| 1448 | def getcallargs(func, /, *positional, **named): |
| 1449 | """Get the mapping of arguments to values. |
no test coverage detected
searching dependent graphs…