[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Do not promote `None` as the first argument to `filter` in documentation.

2018-03-06 17:55 GMT+03:00 Chris Angelico <rosuav at gmail.com>:

> If the first argument is None, the identity function is assumed. That
> is, all elements of the iterable that are false are removed; it is
> equivalent to (item for item in iterable if item). It is approximately
> equivalent to (but faster than) filter(bool, iterable).
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list

If you look in C source for `filter_next`
there is a line:

int checktrue = lz->func == Py_None || lz->func == (PyObject

So the only difference between `filter(None, ls`) and `filter(bool, ls)` is
LOAD_NAME vs LOAD_CONST and that `None` is checked before than `bool`.

With kind regards,