classification
Title: IOBase.readlines(0) behaviour is inconsistent with documentation
Type: behavior Stage:
Components: Documentation Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: althonos2, docs@python
Priority: normal Keywords:

Created on 2021-02-04 14:28 by althonos2, last changed 2021-02-04 14:28 by althonos2.

Messages (1)
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.
History
Date User Action Args
2021-02-04 14:28:07althonos2create