classification
Title: Error in Python 3 docs for PyMethodDef
Type: Stage: patch review
Components: Documentation Versions: Python 3.4, Python 3.3, Python 3.2
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: asvetlov, barry, docs@python, jcea, md5i, sandro.tosi
Priority: normal Keywords:

Created on 2012-08-14 19:02 by sandro.tosi, last changed 2013-04-12 20:31 by barry.

Messages (4)
msg168226 - (view) Author: Sandro Tosi (sandro.tosi) * (Python committer) Date: 2012-08-14 19:02
Hello,
it has been reported at http://mail.python.org/pipermail/docs/2012-April/008215.html but given it raises some question whether it's a bug in the doc or in the code, i'd rather report the issue here and hear what other think:

>>>
In the Python 3.2.2 documentation (and earlier Python 3 versions), in
the Python/C API Reference Manual, chapter Object Implementation
Support, the documentation for PyMethodDef says:

  The ml_flags field is a bitfield which can include the following
  flags. The individual flags indicate either a calling convention or a
  binding convention. Of the calling convention flags, only METH_VARARGS
  and METH_KEYWORDS can be combined (but note that METH_KEYWORDS alone
  is equivalent to METH_VARARGS | METH_KEYWORDS).

The bit in the parenthetical is incorrect.  If you take a look at
PyCFunction_Call in Objects/methodobject.c, you will find a switch for
METH_VARARGS | METH_KEYWORDS, but no switch for METH_KEYWORDS.  Hence,
using METH_KEYWORDS will land you with a SystemError that complains
about METH_OLDARGS.

This is either a bug in the documentation, or a bug in Python.  In this
case, since the code has persisted through three major revisions of
Python 3, I suggest that the bug _is_ in the documentation (whether it
should be or not), since changing the code for this at this late date
means a programmer has to use METH_VARARGS | METH_KEYWORDS anyway for
compatibility.

It may be work pointing out specifically in the documentation that just
using METH_KEYWORDS will not work.
<<<
msg168463 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2012-08-17 18:41
I think we can change PyCFunction_Call to accept METH_KEYWORDS as alias for METH_VARARGS | METH_KEYWORDS.
It cannot make incompatibility with existing code base.
msg186676 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2013-04-12 20:26
I just ran into this too.
msg186679 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2013-04-12 20:31
We should fix the code for 3.2 through 3.4, but change the docs for 3.2 and 3.3 to remove the parenthetical note.  For 3.4 we can leave the parenthetical note but say this is new in 3.4 (or maybe, that it doesn't actually work in some versions < 3.4).  I agree that for code to work consistently across all Python 3.2 and 3.3 microversions, extension code is going to have to include both flags anyway.
History
Date User Action Args
2013-04-12 20:31:58barrysetmessages: + msg186679
versions: + Python 3.4
2013-04-12 20:26:08barrysetnosy: + barry
messages: + msg186676
2012-08-17 18:41:35asvetlovsetmessages: + msg168463
2012-08-17 16:39:29asvetlovsetnosy: + asvetlov
2012-08-15 02:51:26jceasetnosy: + jcea
2012-08-14 19:42:18md5isetnosy: + md5i
2012-08-14 19:02:45sandro.tosicreate