Message159781
| Author |
larry |
| Recipients |
larry |
| Date |
2012年05月02日.09:29:18 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1335950959.73.0.615702363048.issue14705@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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'.) |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2012年05月02日 09:29:19 | larry | set | recipients:
+ larry |
| 2012年05月02日 09:29:19 | larry | set | messageid: <1335950959.73.0.615702363048.issue14705@psf.upfronthosting.co.za> |
| 2012年05月02日 09:29:19 | larry | link | issue14705 messages |
| 2012年05月02日 09:29:18 | larry | create |
|