_revancestors: use 'next' to remove the verbose try except clauses
authorPierre-Yves David <pierre-yves.david@fb.com>
Sun, 17 May 2015 17:54:58 -0700
changeset 25143 91c49621b2b8
parent 25142 24140873ca4c
child 25144 81a395447b34
_revancestors: use 'next' to remove the verbose try except clauses The 'next()' built-in can return a default value, making the final iteration case simpler and clearer.
mercurial/revset.py
--- a/mercurial/revset.py	Sun May 17 17:47:42 2015 -0700
+++ b/mercurial/revset.py	Sun May 17 17:54:58 2015 -0700
@@ -28,21 +28,18 @@
         revs.sort(reverse=True)
         irevs = iter(revs)
         h = []
-        try:
-            inputrev = irevs.next()
+
+        inputrev = next(irevs, None)
+        if inputrev is not None:
             heapq.heappush(h, -inputrev)
-        except StopIteration:
-            return
 
         seen = set()
         while h:
             current = -heapq.heappop(h)
             if current == inputrev:
-                try:
-                    inputrev = irevs.next()
+                inputrev = next(irevs, None)
+                if inputrev is not None:
                     heapq.heappush(h, -inputrev)
-                except StopIteration:
-                    pass
             if current not in seen:
                 seen.add(current)
                 yield current