[issue14705] Add 'bool' format character to PyArg_ParseTuple*

Larry Hastings report at bugs.python.org
Wed May 2 13:23:20 CEST 2012


Larry Hastings <larry at hastings.org> added the comment:

> For this purpose it is appropriate to use a special converter
> (with 'O&').

The converter works--but, then, a similar converter would also work
for double, and float, and long long and many others.  If long long
is special enough to merit explicit support in PyArg_ParseTuple,
then bool definitely is, as I strongly suspect bool is used much more
frequently.


> I suppose it must be a strict сonverter; there is no point
> in specifying followlinks=[1, 2, 3].

I don't see a need for that either, but--where would you draw the line?  What is the principle that says "ints are okay, floats are... okay, lists are not"?

Python has a long-established concept of the "truthiness" of an expression.  I *strongly* suggest we stick with that unless we have a *very* good reason why not.


> note that 'b' and 'B' are already used.

I'm a moron!  I must have looked right at it and it didn't register.

't' (truth) and 'f' (false) are also taken.  As is 'c' (conditional).
The only thing I can come up with that's remotely related and
isn't already taken is 'p' for predicate.


> It is better first to use the сonverter, and expand the format
> only when the enough number of uses.

I suspect there are already loads of places in the standard library
that should be using this rather than abusing 'i'.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14705>
_______________________________________


More information about the Python-bugs-list mailing list