[issue46637] Incorrect error message: "missing 1 required positional argument"

Anders Hovmöller report at bugs.python.org
Fri Feb 4 12:13:07 EST 2022


Anders Hovmöller <boxed at killingar.net> added the comment:

For `foo(a, /, b)`, it could be:

"TypeError: foo() missing 1 required argument 'a', and one required positional argument 'b'.

If we start on this road there are some more, like for `def foo(a, *, b)` you get the error "TypeError: foo() missing 1 required positional argument: 'a'" which leaves out that the keyword only argument is also required. 

Another solution would be something like:

TypeError: foo() missing 3 required arguments: 'a' (positional only), 'b', 'c' (keyword only)

This solution scales to the worst complex cases, and is a lot clearer imo. Could even be further improved with some nicer formatting:

TypeError: foo() missing 3 required arguments: 
    'a' (positional only)
    'b'
    'c' (keyword only)

But that might be a bit overkill :)

----------

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


More information about the Python-bugs-list mailing list