| 1495 | "" if missing == 1 else "s", s)) |
| 1496 | |
| 1497 | def _too_many(f_name, args, kwonly, varargs, defcount, given, values): |
| 1498 | atleast = len(args) - defcount |
| 1499 | kwonly_given = len([arg for arg in kwonly if arg in values]) |
| 1500 | if varargs: |
| 1501 | plural = atleast != 1 |
| 1502 | sig = "at least %d" % (atleast,) |
| 1503 | elif defcount: |
| 1504 | plural = True |
| 1505 | sig = "from %d to %d" % (atleast, len(args)) |
| 1506 | else: |
| 1507 | plural = len(args) != 1 |
| 1508 | sig = str(len(args)) |
| 1509 | kwonly_sig = "" |
| 1510 | if kwonly_given: |
| 1511 | msg = " positional argument%s (and %d keyword-only argument%s)" |
| 1512 | kwonly_sig = (msg % ("s" if given != 1 else "", kwonly_given, |
| 1513 | "s" if kwonly_given != 1 else "")) |
| 1514 | raise TypeError("%s() takes %s positional argument%s but %d%s %s given" % |
| 1515 | (f_name, sig, "s" if plural else "", given, kwonly_sig, |
| 1516 | "was" if given == 1 and not kwonly_given else "were")) |
| 1517 | |
| 1518 | def getcallargs(func, /, *positional, **named): |
| 1519 | """Get the mapping of arguments to values. |