[PATCH] util: use the built-in any() and all() methods if they are available

Steve Losh steve at stevelosh.com
Tue Feb 16 08:31:59 CST 2010


# HG changeset patch
# User Steve Losh <steve at stevelosh.com>
# Date 1266330695 18000
# Node ID 14dcf8e565cfa823e9250a3404c99861de0f10d2
# Parent  ed4de30e16c5b6efb67a2a5edabb424cd4deda7d
util: use the built-in any() and all() methods if they are available

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1336,21 +1336,24 @@
         while not condfn():
             if ((pid in terminated or not testpid(pid))
                 and not condfn()):
                 return -1
             time.sleep(0.1)
         return pid
     finally:
         if prevhandler is not None:
             signal.signal(signal.SIGCHLD, prevhandler)
 
-def any(iterable):
-    for i in iterable:
-        if i:
-            return True
-    return False
+try:
+    any, all = any, all
+except NameError:
+    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
+    def all(iterable):
+        for i in iterable:
+            if not i:
+                return False
+        return True


More information about the Mercurial-devel mailing list