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
{{ message }}
Repository navigation
Missing error: "parameter without a default follows parameter with a default" with a function that uses *args #129810
I clearly understand the error here as it is not the first time I'm using Python, the thing that eludes me is: why is there no error with the first function ?
changed the title [-]Missing error: "parameter without a default follows parameter" with a default with a function that uses `*args`[/-][+]Missing error: "parameter without a default follows parameter with a default" with a function that uses `*args`[/+]on Feb 7, 2025
Keyword-only arguments are not required to have a default value. Since Python requires that all arguments be bound to a value, and since the only way to bind a value to a keyword-only argument is via keyword, such arguments are therefore ‘required keyword’ arguments. Such arguments must be supplied by the caller, and they must be supplied via keyword.
So a and b are keyword-only arguments - so user should supply them by keyword. But a has default value and can be omitted from the call.
Maybe we should extend the test_positional_only_and_kwonlyargs_invalid_calls test case and add a keyword-only argument with a default value as an example?
Oh ok I get it. It's a bit confusing because we could simply think that b should become a keyword-only argument.
But since there is no varargs, b is just a positional argument with no default.
Activity
[-]Missing error: "parameter without a default follows parameter" with a default with a function that uses `*args`[/-][+]Missing error: "parameter without a default follows parameter with a default" with a function that uses `*args`[/+]sergey-miryanov commentedon Feb 7, 2025
I believe this is a desired behavior according https://peps.python.org/pep-3102/:
So
aandbare keyword-only arguments - so user should supply them by keyword. Butahas default value and can be omitted from the call.sergey-miryanov commentedon Feb 7, 2025
Maybe we should extend the
test_positional_only_and_kwonlyargs_invalid_callstest case and add a keyword-only argument with a default value as an example?adrien-lsh commentedon Feb 7, 2025
Oh ok I get it. It's a bit confusing because we could simply think that
bshould become a keyword-only argument.But since there is no varargs,
bis just a positional argument with no default.Thanks for the explanation !
terryjreedy commentedon Feb 8, 2025
Questions like this should go to https://discuss.python.org/c/help/7, where they are more likely to be found by others.