[issue20423] io.StringIO newline param has wrong default

New submission from couplewavylines: In io.StringIO, the newline argument's default is currently documented as "newline=None" in the section header. However, it's described this way: "The default is to do no newline translation." The behavior of io.StringIO is consistent with this description (NO newline translation). The header should actually read "newline=''". "newline=None" would mean there IS newline translation by default, which is not the case. Code sample attached as no_translation.py. ---------- assignee: docs@python components: Documentation files: no_translation.py messages: 209577 nosy: couplewavylines, docs@python priority: normal severity: normal status: open title: io.StringIO newline param has wrong default type: behavior versions: Python 3.3, Python 3.4 Added file: http://bugs.python.org/file33779/no_translation.py _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue20423> _______________________________________

Changes by couplewavylines <couplewavylines@gmail.com>: Added file: http://bugs.python.org/file33780/no_translation_output.txt _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue20423> _______________________________________

Serhiy Storchaka added the comment: No, actual default is '\n'.
io.StringIO('abc\r\ndef\nghi\rklm').readlines() ['abc\r\n', 'def\n', 'ghi\rklm'] io.StringIO('abc\r\ndef\nghi\rklm', newline=None).readlines() ['abc\n', 'def\n', 'ghi\n', 'klm'] io.StringIO('abc\r\ndef\nghi\rklm', newline='').readlines() ['abc\r\n', 'def\n', 'ghi\r', 'klm'] io.StringIO('abc\r\ndef\nghi\rklm', newline='\n').readlines() ['abc\r\n', 'def\n', 'ghi\rklm'] io.StringIO('abc\r\ndef\nghi\rklm', newline='\r').readlines() ['abc\r', '\r', 'def\r', 'ghi\r', 'klm'] io.StringIO('abc\r\ndef\nghi\rklm', newline='\r\n').readlines() ['abc\r\r\n', 'def\r\n', 'ghi\rklm']
---------- keywords: +easy nosy: +serhiy.storchaka stage: -> needs patch versions: +Python 2.7 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue20423> _______________________________________

couplewavylines added the comment: Serhiy, you're right, I now see the default behavior is "newline='\n'". So, the header is still wrong, and the text is "The default is to do no newline translation" may be incorrect too? Or just unclear (to me anyway)? ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue20423> _______________________________________

Serhiy Storchaka added the comment: On other hand, may be the behavior of io.StringIO is wrong. Because it is different from io.TextIOWrapper.
io.TextIOWrapper(io.BytesIO(b'abc\r\ndef\nghi\rklm')).readlines() ['abc\n', 'def\n', 'ghi\n', 'klm'] io.TextIOWrapper(io.BytesIO(b'abc\r\ndef\nghi\rklm'), newline=None).readlines() ['abc\n', 'def\n', 'ghi\n', 'klm'] io.TextIOWrapper(io.BytesIO(b'abc\r\ndef\nghi\rklm'), newline='').readlines() ['abc\r\n', 'def\n', 'ghi\r', 'klm'] io.TextIOWrapper(io.BytesIO(b'abc\r\ndef\nghi\rklm'), newline='\n').readlines() ['abc\r\n', 'def\n', 'ghi\rklm'] io.TextIOWrapper(io.BytesIO(b'abc\r\ndef\nghi\rklm'), newline='\r').readlines() ['abc\r', '\ndef\nghi\r', 'klm'] io.TextIOWrapper(io.BytesIO(b'abc\r\ndef\nghi\rklm'), newline='\r\n').readlines() ['abc\r\n', 'def\nghi\rklm']
---------- nosy: +benjamin.peterson, hynek, pitrou, stutzbach _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue20423> _______________________________________

Antoine Pitrou added the comment: Using '\n' as default is normal: StringIOs are not stored on disk so there's no point in converting newlines by default (it's only slower while not improving interoperability). '\n' is the default line separator in Python. So we should just fix the docs here. The bug when using '\r' or '\r\n' should probably be fixed though (that would be a separate issue). ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue20423> _______________________________________

Roundup Robot added the comment: New changeset 82cfab2ad98d by Antoine Pitrou in branch '3.3': Issue #20423: fix documentation of io.StringIO's newline parameter http://hg.python.org/cpython/rev/82cfab2ad98d New changeset 69a2cc048c80 by Antoine Pitrou in branch '2.7': Issue #20423: fix documentation of io.StringIO's newline parameter http://hg.python.org/cpython/rev/69a2cc048c80 New changeset df2efd48227e by Antoine Pitrou in branch 'default': Issue #20423: fix documentation of io.StringIO's newline parameter http://hg.python.org/cpython/rev/df2efd48227e ---------- nosy: +python-dev _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue20423> _______________________________________

Antoine Pitrou added the comment: The docs are now fixed, thank you! ---------- resolution: -> fixed stage: needs patch -> committed/rejected status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue20423> _______________________________________
participants (4)
-
Antoine Pitrou
-
couplewavylines
-
Roundup Robot
-
Serhiy Storchaka