You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
StringIO.StringIO.readline(-1) returns the wrong result compared to other file-like objects #51597
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2009-12-13.17:30:12.653>created_at=<Date2009-11-18.18:58:35.581>labels= ['library']
title='StringIO.StringIO.readline(-1) returns the wrong result compared to other file-like objects'updated_at=<Date2009-12-13.17:30:12.614>user='https://bugs.python.org/exarkun'
cStringIO and file both accept -1 to readline to mean the same thing as
not passing any argument at all. StringIO, on the other hand, gets
totally confused:
>>> from StringIO import StringIO
>>> StringIO('a\nb\nfoo').readline(-1)
'a\nb\nfo'
>>>
You specified neither version nor system.
On 3.1, Windows
>>> from io import StringIO as s
>>> s('a\nb\nfoo').readline(-1)
'a\n'
which, I gather, is what you describe as expected, although using -1 to
mean None is rather weird.
The 3.1 doc says only
"readline(limit=-1)
Read and return one line from the stream. If limit is specified, at most
limit bytes will be read."
which would imply that negative numbers are the same as 0.
So even in 3.1, either the behavior is wrong or the doc is incomplete.
Activity
exarkun commentedon Nov 18, 2009
cStringIO and file both accept -1 to readline to mean the same thing as
not passing any argument at all. StringIO, on the other hand, gets
totally confused:
>>> from StringIO import StringIO >>> StringIO('a\nb\nfoo').readline(-1) 'a\nb\nfo' >>>terryjreedy commentedon Nov 20, 2009
'a\n'
which, I gather, is what you describe as expected, although using -1 to
mean None is rather weird.
The 3.1 doc says only
"readline(limit=-1)
Read and return one line from the stream. If limit is specified, at most
limit bytes will be read."
which would imply that negative numbers are the same as 0.
So even in 3.1, either the behavior is wrong or the doc is incomplete.
exarkun commentedon Nov 20, 2009
Python 2.6, Linux.
benjaminp commentedon Dec 13, 2009
Fixed in r76798.