summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-02-13 10:26:58 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-02-13 10:26:58 (GMT)
commit8d7d6bcc2519066ba04f3c63d6ae8d2897a94282 (patch)
tree03622015920e98f626e439d72941ecdb6480b4b8
parent34fe1b7a3db61ee1b92f495488b08532b6126450 (diff)
downloadcpython-8d7d6bcc2519066ba04f3c63d6ae8d2897a94282.zip
cpython-8d7d6bcc2519066ba04f3c63d6ae8d2897a94282.tar.gz
cpython-8d7d6bcc2519066ba04f3c63d6ae8d2897a94282.tar.bz2
Issue #11311: StringIO.readline(0) now returns an empty string as all other
file-like objects.
-rw-r--r--Lib/StringIO.py2
-rw-r--r--Lib/test/test_StringIO.py2
-rw-r--r--Misc/NEWS3
3 files changed, 6 insertions, 1 deletions
diff --git a/Lib/StringIO.py b/Lib/StringIO.py
index f74a066..b63525b 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 84b2b08..37a825f 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 b7d044a..68f72c2 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.