[Python-ideas] Allow filter(items)

Terry Reedy tjreedy at udel.edu
Wed Aug 7 01:56:29 CEST 2013


On 8/6/2013 3:34 AM, Chris Angelico wrote:
> On Tue, Aug 6, 2013 at 8:28 AM, Peter Otten <__peter__ at web.de> wrote:
>> The implementation already has an optimization to treat bool like None --
>> the former is never called:
>>
>> [Python/bltinmodule.c]
>>
>>          if (lz->func == Py_None || lz->func == (PyObject *)&PyBool_Type) {
>>              ok = PyObject_IsTrue(item);
>>
>> This is done on every next() call, and while my instinct would be to
>> translate PyBool_Type to Py_None once in the constructor I doubt that this
>> has a noticeable impact on performance.
>
> Okay. Sounds like there's already an answer to those who want more
> readability: Just use filter(bool,...).

I think we should change the doc to say that the default is (implicit) 
'bool', which I think it would be if the function were defined today.

-- 
Terry Jan Reedy



More information about the Python-ideas mailing list