Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StringIO.StringIO.readline(-1) returns the wrong result compared to other file-like objects #51597

Closed
exarkun mannequin opened this issue Nov 18, 2009 · 4 comments
Closed
Labels
stdlib Python modules in the Lib dir

Comments

@exarkun
Copy link
Mannequin

exarkun mannequin commented Nov 18, 2009

BPO 7348
Nosy @terryjreedy, @benjaminp

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 = None
closed_at = <Date 2009-12-13.17:30:12.653>
created_at = <Date 2009-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 = <Date 2009-12-13.17:30:12.614>
user = 'https://bugs.python.org/exarkun'

bugs.python.org fields:

activity = <Date 2009-12-13.17:30:12.614>
actor = 'benjamin.peterson'
assignee = 'none'
closed = True
closed_date = <Date 2009-12-13.17:30:12.653>
closer = 'benjamin.peterson'
components = ['Library (Lib)']
creation = <Date 2009-11-18.18:58:35.581>
creator = 'exarkun'
dependencies = []
files = []
hgrepos = []
issue_num = 7348
keywords = []
message_count = 4.0
messages = ['95438', '95568', '95570', '96339']
nosy_count = 3.0
nosy_names = ['terry.reedy', 'exarkun', 'benjamin.peterson']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue7348'
versions = []

@exarkun
Copy link
Mannequin Author

exarkun mannequin commented 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'
  >>>

@exarkun exarkun mannequin added the stdlib Python modules in the Lib dir label Nov 18, 2009
@terryjreedy
Copy link
Member

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.

@exarkun
Copy link
Mannequin Author

exarkun mannequin commented Nov 20, 2009

Python 2.6, Linux.

@benjaminp
Copy link
Contributor

Fixed in r76798.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

2 participants