From: Serhiy Storchaka Date: Wed, 13 Feb 2013 10:26:58 +0000 (+0200) Subject: Issue #11311: StringIO.readline(0) now returns an empty string as all other X-Git-Tag: v2.7.4rc1~115 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8d7d6bcc2519066ba04f3c63d6ae8d2897a94282;p=thirdparty%2FPython%2Fcpython.git Issue #11311: StringIO.readline(0) now returns an empty string as all other file-like objects. --- diff --git a/Lib/StringIO.py b/Lib/StringIO.py index f74a066773fe..b63525b9bfdc 100644 --- a/Lib/StringIO.py +++ b/Lib/StringIO.py @@ -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] diff --git a/Lib/test/test_StringIO.py b/Lib/test/test_StringIO.py index 84b2b08acb6f..37a825f14e33 100644 --- a/Lib/test/test_StringIO.py +++ b/Lib/test/test_StringIO.py @@ -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) diff --git a/Misc/NEWS b/Misc/NEWS index b7d044a955ec..68f72c216560 100644 --- 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.