diff mercurial/patch.py @ 29738:160c829dd5d0

patch: use `iter(callable, sentinel)` instead of while True This is functionally equivalent, but is a little more concise.
author Augie Fackler <augie@google.com>
date Fri, 05 Aug 2016 14:00:14 -0400
parents 40d53d4b5925
children 50f2966f86ca
line wrap: on
line diff
--- a/mercurial/patch.py	Fri Aug 05 14:00:08 2016 -0400
+++ b/mercurial/patch.py	Fri Aug 05 14:00:14 2016 -0400
@@ -410,11 +410,7 @@
         return self.fp.readline()
 
     def __iter__(self):
-        while True:
-            l = self.readline()
-            if not l:
-                break
-            yield l
+        return iter(self.readline, '')
 
 class abstractbackend(object):
     def __init__(self, ui):
@@ -1688,10 +1684,7 @@
     def scanwhile(first, p):
         """scan lr while predicate holds"""
         lines = [first]
-        while True:
-            line = lr.readline()
-            if not line:
-                break
+        for line in iter(lr.readline, ''):
             if p(line):
                 lines.append(line)
             else:
@@ -1699,10 +1692,7 @@
                 break
         return lines
 
-    while True:
-        line = lr.readline()
-        if not line:
-            break
+    for line in iter(lr.readline, ''):
         if line.startswith('diff --git a/') or line.startswith('diff -r '):
             def notheader(line):
                 s = line.split(None, 1)
@@ -1772,10 +1762,7 @@
     context = None
     lr = linereader(fp)
 
-    while True:
-        x = lr.readline()
-        if not x:
-            break
+    for x in iter(lr.readline, ''):
         if state == BFILE and (
             (not context and x[0] == '@')
             or (context is not False and x.startswith('***************'))