Patchwork [7,of,9] util: use `iter(callable, sentinel)` instead of while True

login
register
mail settings
Submitter Augie Fackler
Date Aug. 6, 2016, 3:02 p.m.
Message ID <d121b305f9bec087d568.1470495757@imladris.local>
Download mbox | patch
Permalink /patch/16161/
State Accepted
Headers show

Comments

Augie Fackler - Aug. 6, 2016, 3:02 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1470420046 14400
#      Fri Aug 05 14:00:46 2016 -0400
# Node ID d121b305f9bec087d568f1f53a8808e951e6d4ba
# Parent  cfdfe5d1d84a5cbcd59575f0344fbc52863bf801
util: use `iter(callable, sentinel)` instead of while True

This is functionally equivalent, but is a little more concise.

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1012,10 +1012,7 @@  def system(cmd, environ=None, cwd=None, 
             proc = subprocess.Popen(cmd, shell=True, close_fds=closefds,
                                     env=env, cwd=cwd, stdout=subprocess.PIPE,
                                     stderr=subprocess.STDOUT)
-            while True:
-                line = proc.stdout.readline()
-                if not line:
-                    break
+            for line in iter(proc.stdout.readline, ''):
                 out.write(line)
             proc.wait()
             rc = proc.returncode