Larry Hastings added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28885>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to