[issue2677] Argument rules for callables do not apply when function implementation uses PyArg_ParseTuple

Martin v. Löwis report at bugs.python.org
Thu Apr 24 12:50:20 CEST 2008


Martin v. Löwis <martin at v.loewis.de> added the comment:

> I'd believe you when you say "positional parameters are unnamed", but:
> 
> - the language reference contains terms such as "first formal parameter
> name". This means that positional parameters *may* have a name but may
> also have no name?

Correct (although that is actually my interpretation of the
implementation; it's probably not a feature of the language itself).

> - if you define a python function as "def f(a, b, c):" you can call it
> using keyword arguments instead of positional (e.g. f(1, c=3, b=2)).

Unnamed positional parameters are only available in C code. You cannot
write a function with unnamed parameters in Python.

> Could you please explain me what I'm still missing? (I repeat - I met
> python for the first time 2 weeks ago, so it may very well be the case
> that I'm completely wrong)

It's just how PyArg_ParseTuple works: it doesn't receive any parameter
names for the positional parameters, so it can't possibly do the
matching that the language prescribes for positional parameters.
Instead, PyArg_ParseTuple operates *just* by position, hence it
effectively implements unnamed positional parameters.

You are not completely wrong. It's just that this detail is something
most people recognize at some point and accept as a fact, regardless
of what the language specification says (and, as I claim, that text
isn't incorrect - or the implementation isn't incorrect -- it's just
underspecified, failing to mention a detail specific to CPython)

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2677>
__________________________________


More information about the Python-bugs-list mailing list