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 larry
Recipients larry
Date 2012-05-02.09:29:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Currently functions that parse their arguments with the PyArg_ParseTuple family which want to take a boolean-ish parameter face two choices:
  * take an "int", then test whether or not the int is 0, or
  * take an "object", then call PyObject_IsTrue themselves.

The former is foolish; though it works with ints and bools, it doesn't work with any other type (float, str, list, etc) which strictly speaking are valid for boolean fields.  And this is common enough that the latter should not be necessary.

I propose to add support for a new format character to the PyArg_ParseTuple family: 'b', which specifies 'boolean'.  Its
implementation would be much the same as that of 'd' except:
  * the output type would be "int" instead of "double",
  * it would check for a -1 instead of calling PyErr_Occured, and
  * it would call PyObject_IsTrue instead of PyFloat_AsDouble.

If we cared, I could also add 'B', which would only accept
either Py_True or Py_False.  But I see no reason why we'd ever want
to strictly enforce the type... do you?  (I can see MvL's argument now:
"We've lived this long without it.  YAGNI.")

If there's interest I'll knock out a patch.  I expect it to be less than ten lines not counting documentation and test.  (Less than twenty if
folks actually want 'B'.)
Date User Action Args
2012-05-02 09:29:19larrysetrecipients: + larry
2012-05-02 09:29:19larrysetmessageid: <>
2012-05-02 09:29:19larrylinkissue14705 messages
2012-05-02 09:29:18larrycreate