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

patch to make io.StringIO consistent with open with respect to newlines #49701

Closed
erickt mannequin opened this issue Mar 9, 2009 · 4 comments
Closed

patch to make io.StringIO consistent with open with respect to newlines #49701

erickt mannequin opened this issue Mar 9, 2009 · 4 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@erickt
Copy link
Mannequin

erickt mannequin commented Mar 9, 2009

BPO 5451
Nosy @benjaminp
Files
  • 0001-Make-StringIO-consistent-with-open-wrt-newlines.patch
  • 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-03-09.00:16:24.760>
    created_at = <Date 2009-03-09.00:09:53.705>
    labels = ['type-bug', 'library']
    title = 'patch to make io.StringIO consistent with open with respect to newlines'
    updated_at = <Date 2009-03-09.01:04:09.555>
    user = 'https://bugs.python.org/erickt'

    bugs.python.org fields:

    activity = <Date 2009-03-09.01:04:09.555>
    actor = 'erickt'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-03-09.00:16:24.760>
    closer = 'benjamin.peterson'
    components = ['Library (Lib)']
    creation = <Date 2009-03-09.00:09:53.705>
    creator = 'erickt'
    dependencies = []
    files = ['13276']
    hgrepos = []
    issue_num = 5451
    keywords = ['patch']
    message_count = 4.0
    messages = ['83341', '83343', '83344', '83346']
    nosy_count = 2.0
    nosy_names = ['benjamin.peterson', 'erickt']
    pr_nums = []
    priority = 'normal'
    resolution = 'rejected'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue5451'
    versions = ['Python 3.1']

    @erickt
    Copy link
    Mannequin Author

    erickt mannequin commented Mar 9, 2009

    I noticed that io.StringIO is inconsistent with open on how newlines are
    handled. The default approach open uses is universal newlines:

    >>> with open('foo', 'w') as f:
    ...   f.write('hello hi\r\nla la\r\n')
    ... 
    17
    >>> open('foo').readlines()
    ['hello hi\n', 'la la\n']

    io.StringIO, however, defaults to just treating \n as newlines:

    >>> io.StringIO('hello hi\r\nla la \r\n').readlines()
    ['hello hi\r\n', 'la la \r\n']

    The attached patch changes this so that if the newline keyword isn't
    specified, then StringIO will act just like open with respect to
    keywords. It will then produce this:

    >>> io.StringIO('hello hi\r\nla la \r\n').readlines()
    ['hello hi\n', 'la la \n']

    @erickt erickt mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Mar 9, 2009
    @benjaminp
    Copy link
    Contributor

    This is the intended behavior. It is consist with 2.x's
    StringIO.StringIO behavior.

    @erickt
    Copy link
    Mannequin Author

    erickt mannequin commented Mar 9, 2009

    Thanks Benjamin. Could the documentation for StringIO be updated then? The
    docs for io.StringIO 1 says that io.TextIOWrapper implements the
    constructor, but TextIOWrapper defaults newline to None 2, and there's
    nothing that states that io.StringIO changes the default to newline='\n'.

    @erickt
    Copy link
    Mannequin Author

    erickt mannequin commented Mar 9, 2009

    Moving this to a documentation bug here: http://bugs.python.org/issue5452

    @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 type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant