[PATCH 1 of 3] util: add any() and all() functions for Python 2.4 compatibility

Benoit Boissinot bboissin at gmail.com
Sun Feb 14 16:00:52 CST 2010


On Sun, Feb 14, 2010 at 10:34 PM, Greg Ward <greg-hg at gerg.ca> wrote:
> On Fri, Feb 12, 2010 at 8:11 PM, Steve Losh <steve at stevelosh.com> wrote:
>> +
>> +def any(iterable):
>> +    for i in iterable:
>> +        if i:
>> +            return True
>> +    return False
>> +
>> +def all(iterable):
>> +    for i in iterable:
>> +        if not i:
>> +            return False
>> +    return True
>
> Shouldn't there be something to use the builtin any() and all() if
> they are present?  E.g.
>
> try:
>    any, all
> except NameError:
>    def any...
>    def all...
>
> I'm assuming the builtins are written in C and therefore faster than
> these implementations.

Indeed.

Steve, can you do that?

regards,

Benoit


More information about the Mercurial-devel mailing list