Patchwork [8,of,9] md5sum: 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 <a5dd8e8ff9e492b2d862.1470495758@imladris.local>
Download mbox | patch
Permalink /patch/16162/
State Accepted
Headers show

Comments

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

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

Patch

diff --git a/tests/md5sum.py b/tests/md5sum.py
--- a/tests/md5sum.py
+++ b/tests/md5sum.py
@@ -34,10 +34,7 @@  for filename in sys.argv[1:]:
 
     m = md5()
     try:
-        while True:
-            data = fp.read(8192)
-            if not data:
-                break
+        for data in iter(lambda: fp.read(8192), ''):
             m.update(data)
     except IOError as msg:
         sys.stderr.write('%s: I/O error: %s\n' % (filename, msg))