Author: Ronan Lamy <[email protected]>
Branch: py3.6
Changeset: r97246:7b9b2790269b
Date: 2019-08-22 17:45 +0100
http://bitbucket.org/pypy/pypy/changeset/7b9b2790269b/

Log:    CPython compatibility: IOBase.readlines() should rely on the
        iterator protocol instead of calling readline() directly

diff --git a/pypy/module/_io/interp_iobase.py b/pypy/module/_io/interp_iobase.py
--- a/pypy/module/_io/interp_iobase.py
+++ b/pypy/module/_io/interp_iobase.py
@@ -266,24 +266,16 @@
 
     def readlines_w(self, space, w_hint=None):
         hint = convert_size(space, w_hint)
-
         if hint <= 0:
             return space.newlist(space.unpackiterable(self))
 
+        length = 0
         lines_w = []
-        length = 0
-        while True:
-            w_line = space.call_method(self, "readline")
-            line_length = space.len_w(w_line)
-            if line_length == 0: # done
-                break
-
+        for w_line in space.iteriterable(self):
             lines_w.append(w_line)
-
-            length += line_length
+            length += space.len_w(w_line)
             if length > hint:
                 break
-
         return space.newlist(lines_w)
 
     def writelines_w(self, space, w_lines):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to