[Python-ideas] Break the dominance of boolean values in boolean context
Alexander Belopolsky
alexander.belopolsky at gmail.com
Thu Sep 15 19:55:31 CEST 2011
On Thu, Sep 15, 2011 at 1:45 PM, Guido van Rossum <guido at python.org> wrote:
..
> Considering the use cases, and Python's pervasive use of
> any-object-as-Boolean, I think it would have been fine if they had
> been defined as follows:
>
> def any(xs):
> x = False
> for x in xs:
> if x: break
> return x
Did you consider that in a typical "if any(S):" construct,
x.__bool__() will be called twice on the found object? It is not
unheard of to have expensive __bool__(). For example in a vector
library a vector may be considered "false" if all its components are
zero.
More information about the Python-ideas
mailing list