[Python-ideas] Allow filter(items)

Chris Angelico rosuav at gmail.com
Tue Aug 6 09:34:32 CEST 2013


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,...). Maybe I'm just not seeing the
obvious problem with this version?

ChrisA


More information about the Python-ideas mailing list