[docs] Error in Python 3 docs for PyMethodDef

Michael Welsh Duggan mwd at cert.org
Fri Apr 6 18:31:12 CEST 2012


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.

-- 
Michael Welsh Duggan
(mwd at cert.org)


More information about the docs mailing list