[issue22652] Add suggestion about keyword arguments to this error message: "builtins.TypeError: my_func() takes 1 positional argument but 2 were given"

Terry J. Reedy report at bugs.python.org
Thu May 14 19:29:00 EDT 2020


Terry J. Reedy <tjreedy at udel.edu> added the comment:

Serhiy, I am nosying you because you have worked on argument issues in the last year.

Minimal example: def f(a, *, b): pass.  In 3.9.0a6,

>>> f(1,2) # ... Same as 5 years ago.
  TypeError: f() takes 1 positional argument but 2 were given

My first inclination was that this is sufficient information.  But ...

>>> f(1,2,b=3) # ...
  TypeError: f() takes 1 positional argument but 2 positional arguments (and 1 keyword-only argument) were given

The simple message is equally sufficiant here, but more is given, and it seems strange to not then give the equivalent for for 'takes'.  So the patch to add more seems plausible (but I am not one to carefully review C code).

Jesse, if you still want your patch, possibly updated, considered, please make a PR.

We now also have positional-only arguments, and I am not sure how that affects my view on this issue.

----------
nosy: +serhiy.storchaka, terry.reedy
versions: +Python 3.9 -Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue22652>
_______________________________________


More information about the Python-bugs-list mailing list