You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think dropping "positional" doesn't increase the precision of the error message, but I'll admit I can't think of anything better. And lacking something better I don't think we should change this.
boxed commented on Feb 4, 2022
boxedmannequin
MannequinAuthor
More actions
Just dropping the word "positional" is very good. That word is a lie, and just removing it makes it true.
>>> deffoo(a, /, b): pass
...
>>> foo()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: foo() missing 2 required positional arguments: 'a' and 'b'
What would you suggest?
I agree the current messages aren't perfect.
boxed commented on Feb 4, 2022
boxedmannequin
MannequinAuthor
More actions
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.
I think the incorrect qualification should be dropped, if sanely feasible.
More misleading are hidden positional-only args. Doc:
min(iterable, *[, key, default])
min(arg1, arg2, *args[, key])
>>> min(iterator=(1,3))
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
min(iterator=(1,3))
TypeError: min expected at least 1 argument, got 0
1 was passed, but 0 were gotten, as the 1 passed was silently ignored.
Activity
boxed commentedon Feb 4, 2022
This error is incorrect. It says "positional argument", but it's just "argument". The proof is that if you call it with
it works fine.
ericvsmith commentedon Feb 4, 2022
I guess the technically correct term is positional-or-keyword, but that seems like too much: https://docs.python.org/3/glossary.html
I think dropping "positional" doesn't increase the precision of the error message, but I'll admit I can't think of anything better. And lacking something better I don't think we should change this.
boxed commentedon Feb 4, 2022
Just dropping the word "positional" is very good. That word is a lie, and just removing it makes it true.
ericvsmith commentedon Feb 4, 2022
Given this current behavior:
What would you suggest?
I agree the current messages aren't perfect.
boxed commentedon Feb 4, 2022
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 :)
terryjreedy commentedon Feb 4, 2022
I think the incorrect qualification should be dropped, if sanely feasible.
More misleading are hidden positional-only args. Doc:
min(iterable, *[, key, default])
min(arg1, arg2, *args[, key])
1 was passed, but 0 were gotten, as the 1 passed was silently ignored.