This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author garden
Recipients garden
Date 2008-04-24.10:01:21
SpamBayes Score 6.0627376e-06
Marked as misclassified No
Message-id <1209031286.77.0.288825613693.issue2677@psf.upfronthosting.co.za>
In-reply-to
Content
(It seems strange to me that this issue hasn't been raised in the past,
maybe I just failed to find it in the BTS. In that case please excuse me
and please point me to the original discussion.)

The Language Reference, section 5.3.4, states that, for every callable
object:

"[...] If keyword arguments are present, they are first converted to
positional arguments, as follows. First, a list of unfilled slots is
created for the formal parameters. [...] Next, for each keyword
argument, the identifier is used to determine the corresponding slot (if
the identifier is the same as the first formal parameter name, the first
slot is used, and so on). [...]"

This is not true if the function is defined using the C function
PyArg_ParseTuple, and this happens a lot in the standard library. I
discovered it trying to call os.open("filename", flag=os.O_RDONLY), just
to make an example. In this case it seems useless to specify the
keyword, but I have to write a generic "wrapping" function that takes a
function name and its arguments (as keyword arguments) and call the
original function after having changed the content of some of the arguments.

Apart from the reason, I believe that this behavior is inconsistent with
the language definition and should be fixed. I'm very new to Python, but
maybe the format string of ParseTuple should be extended in order to
accept also the name of the positional arguments? Or something like
ParseTupleAndKeywords should be used instead?

I tried only on Python 2.4 and 2.5 but I took a look at the source code
of 2.6 and 3.0 and I believe the issue is still there.
History
Date User Action Args
2008-04-24 10:01:27gardensetspambayes_score: 6.06274e-06 -> 6.0627376e-06
recipients: + garden
2008-04-24 10:01:26gardensetspambayes_score: 6.06274e-06 -> 6.06274e-06
messageid: <1209031286.77.0.288825613693.issue2677@psf.upfronthosting.co.za>
2008-04-24 10:01:23gardenlinkissue2677 messages
2008-04-24 10:01:22gardencreate