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

Keepends param in codec readline(s) #52876

Open
amccampos mannequin opened this issue May 5, 2010 · 9 comments
Open

Keepends param in codec readline(s) #52876

amccampos mannequin opened this issue May 5, 2010 · 9 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@amccampos
Copy link
Mannequin

amccampos mannequin commented May 5, 2010

BPO 8630
Nosy @malemburg, @benjaminp
Files
  • codecs.py: new codecs.py fixing the issue
  • Issue8630.patch: Patch to add missing keepends parameters
  • 45139b30afef.diff: Adds missing parameters to readline and readlines. Adds tests to test_codecs.py
  • 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 = None
    created_at = <Date 2010-05-05.16:38:14.552>
    labels = ['type-bug', 'library']
    title = 'Keepends param in codec readline(s)'
    updated_at = <Date 2019-03-15.23:41:27.662>
    user = 'https://bugs.python.org/amccampos'

    bugs.python.org fields:

    activity = <Date 2019-03-15.23:41:27.662>
    actor = 'BreamoreBoy'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2010-05-05.16:38:14.552>
    creator = 'amccampos'
    dependencies = []
    files = ['17235', '35649', '35729']
    hgrepos = ['259']
    issue_num = 8630
    keywords = ['patch']
    message_count = 8.0
    messages = ['105056', '105128', '105132', '105133', '105140', '105324', '220668', '221291']
    nosy_count = 4.0
    nosy_names = ['lemburg', 'benjamin.peterson', 'amccampos', 'jeffrey.falgout']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue8630'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

    @amccampos
    Copy link
    Mannequin Author

    amccampos mannequin commented May 5, 2010

    Some methods in StreamReaderWriter class (codecs library) has different signatures from StreamReader methods. More precisely it's missing the keepends parameter in readline and readlines methods.

    So, we cannot code:
    fp = codecs.open(fileName, "r", "utf-8")
    lines = fp.readlines(keepends=False)
    or
    line = fp.readline(keepends=False)

    @amccampos amccampos mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels May 5, 2010
    @malemburg
    Copy link
    Member

    We can add those to 3.2. Not sure about 2.7 - it's already in feature freeze.

    @malemburg
    Copy link
    Member

    Benjamin: Would the added parameter be a new feature or not ?

    It looks like an oversight when adding the parameter to the standard codec classes, so could be viewed as a bug.

    @malemburg
    Copy link
    Member

    André: Could you provide a patch ?

    Thanks.

    @amccampos
    Copy link
    Mannequin Author

    amccampos mannequin commented May 6, 2010

    The parameter would not be a new feature since the codecs docs states that:
    "The StreamReaderWriter allows wrapping streams which work in both
    read and write modes".

    The reader (StreamReader) accepts the parameter, so it's expected that
    StreamReaderWriter does the same.

    I'm not sure how to submit a patch.
    So, I'm submitting a new codecs.py file through the issue track
    interface (bpo-8630).
    If it's not that in that way, could you please tell me the path?
    André.

    2010/5/6 Marc-Andre Lemburg <report@bugs.python.org>:

    Marc-Andre Lemburg <mal@egenix.com> added the comment:

    André: Could you provide a patch ?

    Thanks.

    ----------
    assignee: benjamin.peterson ->


    Python tracker <report@bugs.python.org>
    <http://bugs.python.org/issue8630\>


    @benjaminp
    Copy link
    Contributor

    I think this can qualify as a bug fix.

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jun 15, 2014

    As codecs.py has changed I've generated a patch file which adds the missing parameters. I looked at test_codecs.py but could only find one reference to the StreamReaderWriter class in WithStmtTest. I'm sorry but I'll have to leave writing tests for StreamReaderWriter to somebody that's better qualified than myself.

    @jeffreyfalgout
    Copy link
    Mannequin

    jeffreyfalgout mannequin commented Jun 22, 2014

    Wrote tests

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @bhaible
    Copy link

    bhaible commented Mar 25, 2024

    I stumbled across this too: I have an input file with contents

    
    This is line 2.
    
    
    
    And line 6.
    
    

    I want to get the contents of this file, as a list of lines, with the trailing newlines removed. There is only one reference to a readlines method in the current documentation, namely at https://docs.python.org/3.12/library/codecs.html#codecs.StreamReader.readlines , and it shows the signature

    readlines(sizehint=None, keepends=True)
    

    But I cannot find how to invoke this method with keepends=False:

    >>> import codecs
    
    >>> codecs.open('input.txt', 'rb', 'UTF-8').readlines()
    ['\n', 'This is line 2.\n', '\n', '\n', '\n', 'And line 6.\n', '\n']
    
    >>> codecs.open('input.txt', 'rb', 'UTF-8').readlines(False)
    ['\n', 'This is line 2.\n', '\n', '\n', '\n', 'And line 6.\n', '\n']
    
    >>> codecs.open('input.txt', 'rb', 'UTF-8').readlines(None,False)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: StreamReaderWriter.readlines() takes from 1 to 2 positional arguments but 3 were given
    
    >>> codecs.open('input.txt', 'rb', 'UTF-8').readlines(keepends=False)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: StreamReaderWriter.readlines() got an unexpected keyword argument 'keepends'
    
    >>> codecs.open('input.txt', 'rb', 'UTF-8').readlines(sizehint=None, keepends=False)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: StreamReaderWriter.readlines() got an unexpected keyword argument 'keepends'
    

    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
    Development

    No branches or pull requests

    3 participants