[Python-Dev] TypeError: f() missing 1 required positional argument: 'x'

Steven D'Aprano steve at pearwood.info
Thu Sep 20 21:02:09 CEST 2012


On 21/09/12 00:49, Antoine Pitrou wrote:
> On Thu, 20 Sep 2012 10:12:04 -0400
> Benjamin Peterson<benjamin at python.org>  wrote:
>> 2012/9/20 Mark Dickinson<dickinsm at gmail.com>:
>>> Thoughts?
>>
>> I tried to define the error messages in terms of the callee's
>> signature. I call the formals that are not variadic, keyword variadic,
>> or keyword-only, positional. For example, in
>>
>> def f(a, b, c, *args, d):
>>       pass
>>
>> a, b, and c are positional. Hence the "positional" in error messages.
>
> But since the error message gives the name of the parameter, there
> doesn't seem to be a point to add that it's "positional": it can be
> trivially deduced from the function signature.

Furthermore, since the parameter has a name, it can be given as a
keyword argument. Describing positional-or-keyword as "positional"
is misleading, although I admit that I often do that too. I think that
"positional or keyword argument" is too wordy, and is ambiguous as to
whether the argument can be given as either positional or keyword, or
we're unsure which of the two it is.

"Named positional argument" is more accurate, but also too wordy, and
it relies on the reader knowing enough about Python's calling semantics
to infer that therefore it can be given as positional or keyword style.

Since this is way too complicated to encapsulate in a short error
message, I'm with Nick and Mark that "positional" should be dropped
unless the argument is positional-only.



-- 
Steven


More information about the Python-Dev mailing list