Skip to content

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

Closed

Description

@exarkun
mannequin
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 = []

Activity

  1. exarkun commented on Nov 18, 2009

    exarkunmannequin
    MannequinAuthor

    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'
      >>>
  2. added
    stdlib
    on Nov 18, 2009
  3. terryjreedy commented on Nov 20, 2009

    @terryjreedy
    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.

  4. exarkun commented on Nov 20, 2009

    exarkunmannequin
    MannequinAuthor

    Python 2.6, Linux.

  5. benjaminp commented on Dec 13, 2009

    @benjaminp
    Contributor

    Fixed in r76798.

  6. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions