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: IOBase.readlines(0) behaviour is inconsistent with documentation
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: althonos2, andrei.avk, docs@python, lukasz.langa, miss-islington
Priority: normal Keywords: patch

Created on 2021-02-04 14:28 by althonos2, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 27061 merged andrei.avk, 2021-07-08 02:08
PR 27113 merged miss-islington, 2021-07-13 14:08
PR 27114 merged miss-islington, 2021-07-13 14:08
Messages (6)
msg386484 - (view) Author: Martin Larralde (althonos2) Date: 2021-02-04 14:28
The documentation for `IOBase.readlines` states that the `hint` optional argument should be used like so (https://docs.python.org/3/library/io.html#io.IOBase.readlines):

> Read and return a list of lines from the stream. hint can be specified to control the number of lines read: no more lines will be read if the total size (in bytes/characters) of all lines so far exceeds hint.

So in the case where `hint` is null, I would expect `readlines` to return an empty list.

However, this is neither the case for `io.BytesIO` nor for `io.FileIO`:

```
import io

io.BytesIO(b"abc\ndef\nghi\n").readlines(0) 
# this evaluates to [b"abc\n", b"def\n", b"ghi\n"]
```

If this is the intended behaviour, the documentation should be updated, otherwise the code from the `io` module should be fixed.
msg397124 - (view) Author: Andrei Kulakov (andrei.avk) * (Python triager) Date: 2021-07-08 02:11
Thanks for the report!

I agree docs could be improved. Note this method lives in `IOBase` so this behavior also applies to the file pointer returned from `open()` builtin.

I've put up the PR here: https://github.com/python/cpython/pull/27061/files
msg397402 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-07-13 14:08
New changeset 3b5b99da4b256a31933112f4a2385386149c19e1 by andrei kulakov in branch 'main':
bpo-43126: Expand docs on io.IOBase.readlines() method (#27061)
https://github.com/python/cpython/commit/3b5b99da4b256a31933112f4a2385386149c19e1
msg397411 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-07-13 14:41
New changeset 9b369c952cbefb064dda6cb781e66cc1b793fffa by Miss Islington (bot) in branch '3.10':
bpo-43126: Expand docs on io.IOBase.readlines() method (GH-27061) (GH-27113)
https://github.com/python/cpython/commit/9b369c952cbefb064dda6cb781e66cc1b793fffa
msg397412 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-07-13 14:41
New changeset a3d20bfee38c71df88d69064d47fe98a1d59e624 by Miss Islington (bot) in branch '3.9':
bpo-43126: Expand docs on io.IOBase.readlines() method (GH-27061) (#27114)
https://github.com/python/cpython/commit/a3d20bfee38c71df88d69064d47fe98a1d59e624
msg397413 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-07-13 14:42
Thanks, Andrei! ✨ 🍰 ✨
History
Date User Action Args
2022-04-11 14:59:41adminsetgithub: 87292
2021-07-13 14:42:02lukasz.langasetmessages: + msg397413
2021-07-13 14:41:52lukasz.langasetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: + Python 3.10, Python 3.11
2021-07-13 14:41:35lukasz.langasetmessages: + msg397412
2021-07-13 14:41:19lukasz.langasetmessages: + msg397411
2021-07-13 14:08:11miss-islingtonsetpull_requests: + pull_request25661
2021-07-13 14:08:07lukasz.langasetnosy: + lukasz.langa
messages: + msg397402
2021-07-13 14:08:06miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request25660
2021-07-08 02:11:17andrei.avksetmessages: + msg397124
2021-07-08 02:08:03andrei.avksetkeywords: + patch
nosy: + andrei.avk

pull_requests: + pull_request25615
stage: patch review
2021-02-04 14:28:07althonos2create