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 arigo, brett.cannon, gregory.p.smith, larry, serhiy.storchaka, vstinner, yselivanov
Date 2016-12-07.03:36:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1481081791.58.0.783473078284.issue28885@psf.upfronthosting.co.za>
In-reply-to
Content
I assert that Argument Clinic's / PyArg_ParseTuple's handling of bool is correct.

* Python has a well-established concept of "truth":

  https://docs.python.org/3/library/stdtypes.html#truth-value-testing

  The C equivalent is, indeed, PyObject_IsTrue().

* When we added the 'p' format unit to PyArg_ParseTuple, I originally had a second format unit 'P' that would only accept boolean literal values.  But nobody could come up with a use case for it.  So we removed it.  See #14705 for the discussion.

* Existing code often does something half-assed here.  eg. stat_float_times uses the PyArg_ParseTuple "i" format unit for its boolean parameter, which accepts booleans and integers but not strings.  This is strange and inconsistent.  (Of course, you can do this with Argument Clinic, just specify the parameter as an int.  But, yuck.)

If you have a counter-proposal for how it should behave, I'd be interested to hear it.  But as far as I'm concerned, the two legitimate answers for "how to handle integers" are either a) accept literally only True and False--an approach which nobody has a use case for--or b) PyObject_IsTrue(), which behaves exactly like Python.
History
Date User Action Args
2016-12-07 03:36:31larrysetrecipients: + larry, brett.cannon, arigo, gregory.p.smith, vstinner, serhiy.storchaka, yselivanov
2016-12-07 03:36:31larrysetmessageid: <1481081791.58.0.783473078284.issue28885@psf.upfronthosting.co.za>
2016-12-07 03:36:31larrylinkissue28885 messages
2016-12-07 03:36:30larrycreate