This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add trimend option to readline() and readlines()
Type: Stage:
Components: IO Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: methane, serhiy.storchaka
Priority: normal Keywords:

Created on 2020-03-05 12:37 by methane, last changed 2022-04-11 14:59 by admin.

Messages (3)
msg363430 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2020-03-05 12:37
str.splitlines() has `keepends` option.
Like that, `IOBase.readline([trimend=False])` and `IOBase.readlines([trimends=False])` would be useful.
msg363444 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-03-05 18:22
It would be better to name it keepends and set it True by default.

I wanted this feature. The problem is that it is not just concrete implementation, it is an interface. Adding new parameters for IOBase methods will break all IOBase subclasses. And there are IOBase subclasses in third-party code.

It is also not good for file-like classes which do not inherit IOBase, but implement a part of methods. You can't start to use new arguments in your code if you accepted arbitrary file-like objects that have methods read() and readline().
msg363485 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2020-03-06 05:35
> It would be better to name it keepends and set it True by default.

.readline() returns only one line.  Should we use plural form for consistency?

> It is also not good for file-like classes which do not inherit IOBase, but implement a part of methods. You can't start to use new arguments in your code if you accepted arbitrary file-like objects that have methods read() and readline().

OK.  It should be added to only concrete types.
History
Date User Action Args
2022-04-11 14:59:27adminsetgithub: 84044
2020-03-06 05:35:01methanesetmessages: + msg363485
2020-03-05 18:22:59serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg363444
2020-03-05 12:37:08methanecreate