This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: StringIO.StringIO.readline(-1) returns the wrong result compared to other file-like objects
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, exarkun, terry.reedy
Priority: normal Keywords:

Created on 2009-11-18 18:58 by exarkun, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg95438 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2009-11-18 18:58
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'
  >>>
msg95568 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2009-11-20 21:45
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.
msg95570 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2009-11-20 21:47
Python 2.6, Linux.
msg96339 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-12-13 17:30
Fixed in r76798.
History
Date User Action Args
2022-04-11 14:56:54adminsetgithub: 51597
2009-12-13 17:30:12benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg96339

resolution: fixed
2009-11-20 21:47:12exarkunsetmessages: + msg95570
2009-11-20 21:45:08terry.reedysetnosy: + terry.reedy
messages: + msg95568
2009-11-18 18:58:35exarkuncreate