[Python-checkins] cpython (2.7): Issue #11311: StringIO.readline(0) now returns an empty string as all other
serhiy.storchaka
python-checkins at python.org
Wed Feb 13 11:27:57 CET 2013
http://hg.python.org/cpython/rev/7513bd184a01
changeset: 82194:7513bd184a01
branch: 2.7
parent: 82189:385d982ce641
user: Serhiy Storchaka <storchaka at gmail.com>
date: Wed Feb 13 12:26:58 2013 +0200
summary:
Issue #11311: StringIO.readline(0) now returns an empty string as all other
file-like objects.
files:
Lib/StringIO.py | 2 +-
Lib/test/test_StringIO.py | 2 ++
Misc/NEWS | 3 +++
3 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/Lib/StringIO.py b/Lib/StringIO.py
--- a/Lib/StringIO.py
+++ b/Lib/StringIO.py
@@ -158,7 +158,7 @@
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
--- a/Lib/test/test_StringIO.py
+++ b/Lib/test/test_StringIO.py
@@ -28,6 +28,8 @@
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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -205,6 +205,9 @@
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.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list