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

Ram Rachum report at bugs.python.org
Thu Oct 16 12:33:37 CEST 2014


New submission from Ram Rachum:

When programming, I just got this exception:

    builtins.TypeError: my_func() takes 1 positional argument but 2 were given

After a couple of minutes of investigation I figured out that the problem is that the function has a `*` in its signature, so arguments must be specified as keyword arguments, not positional arguments.

It would be nice if the exception message would include some text to suggest that, like:

    builtins.TypeError: my_func() takes 1 positional argument but 2 were given. If you were trying to use the keyword-only argument foo, please specify it as foo=value.

It's a little verbose and specific, but maybe it'll help people figure out this problem, especially newbies. We can have logic to show this message only if there are keyword-only arguments.

----------
components: Interpreter Core
messages: 229521
nosy: cool-RR
priority: normal
severity: normal
status: open
title: Add suggestion about keyword arguments to this error message: "builtins.TypeError: my_func() takes 1 positional argument but 2 were given"
versions: Python 3.5

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


More information about the New-bugs-announce mailing list