]> granicus.if.org Git - python/commitdiff
Issue #11311: StringIO.readline(0) now returns an empty string as all other
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 13 Feb 2013 10:26:58 +0000 (12:26 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 13 Feb 2013 10:26:58 +0000 (12:26 +0200)
file-like objects.

Lib/StringIO.py
Lib/test/test_StringIO.py
Misc/NEWS

index f74a066773fec986cc39acc9bdd8bebbd2bcc0b5..b63525b9bfdcef6a146dea47cfd61d8683bfeb31 100644 (file)
@@ -158,7 +158,7 @@ class StringIO:
             newpos = self.len
         else:
             newpos = i+1
-        if length is not None and length > 0:
+        if length is not None and length >= 0:
             if self.pos + length < newpos:
                 newpos = self.pos + length
         r = self.buf[self.pos:newpos]
index 84b2b08acb6fa5ee18ae38b929503091d24c3011..37a825f14e33d973558d58a90da210c377713679 100644 (file)
@@ -28,6 +28,8 @@ class TestGenericStringIO(unittest.TestCase):
         eq = self.assertEqual
         self.assertRaises(TypeError, self._fp.seek)
         eq(self._fp.read(10), self._line[:10])
+        eq(self._fp.read(0), '')
+        eq(self._fp.readline(0), '')
         eq(self._fp.readline(), self._line[10:] + '\n')
         eq(len(self._fp.readlines(60)), 2)
         self._fp.seek(0)
index b7d044a955ece35ca7a6b95edd02a716f5a71a6d..68f72c216560c95367026cbdabb3fad57101706a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -205,6 +205,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #11311: StringIO.readline(0) now returns an empty string as all other
+  file-like objects.
+
 - Issue #16800: tempfile.gettempdir() no longer left temporary files when
   the disk is full.  Original patch by Amir Szekely.