classification
Title: StringIO.readline(0) returns incorrect results
Type: behavior Stage: resolved
Components: IO, Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: alex, python-dev, scop, serhiy.storchaka
Priority: normal Keywords: easy, patch

Created on 2011-02-24 21:32 by scop, last changed 2013-02-13 10:40 by serhiy.storchaka. This issue is now closed.

Files
File name Uploaded Description Edit
StringIO_readline0.patch serhiy.storchaka, 2013-02-06 13:37 review
Messages (5)
msg129314 - (view) Author: Ville Skyttä (scop) * Date: 2011-02-24 21:32
Python 2.7 (r27:82500, Sep 16 2010, 18:02:00) 
[GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import StringIO
>>> StringIO.StringIO("foo").readline(0)
'foo'

I don't think this is the correct behavior, or at least it is not consistent with other file objects' readline() which return an empty string with .readline(0).

For example:

>>> import cStringIO
>>> cStringIO.StringIO("foo").readline(0)
''

...or:

>>> file("/usr/bin/python").readline(0)
''
msg129331 - (view) Author: Alex Gaynor (alex) * (Python committer) Date: 2011-02-25 04:26
Fun fact: io.StringIO does the right thing, but _io and _pyio.
msg181523 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-02-06 13:37
Here is a very simple patch.
msg182013 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-02-13 10:27
New changeset 7513bd184a01 by Serhiy Storchaka in branch '2.7':
Issue #11311: StringIO.readline(0) now returns an empty string as all other
http://hg.python.org/cpython/rev/7513bd184a01
msg182016 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-02-13 10:40
Fixed. Thank you for the report, Ville.
History
Date User Action Args
2013-02-13 10:40:40serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg182016

stage: patch review -> resolved
2013-02-13 10:27:56python-devsetnosy: + python-dev
messages: + msg182013
2013-02-12 23:44:32serhiy.storchakasetassignee: serhiy.storchaka
2013-02-06 13:37:11serhiy.storchakasetfiles: + StringIO_readline0.patch
keywords: + patch
messages: + msg181523

stage: needs patch -> patch review
2013-02-06 09:44:39serhiy.storchakasetkeywords: + easy
nosy: + serhiy.storchaka

components: + IO
stage: needs patch
2011-02-25 04:26:51alexsetnosy: + alex
messages: + msg129331
2011-02-24 21:32:21scopcreate