[New-bugs-announce] [issue43126] IOBase.readlines(0) behaviour is inconsistent with documentation

Martin Larralde report at bugs.python.org
Thu Feb 4 09:28:07 EST 2021


New submission from Martin Larralde <martin.larralde at embl.de>:

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.

----------
assignee: docs at python
components: Documentation
messages: 386484
nosy: althonos2, docs at python
priority: normal
severity: normal
status: open
title: IOBase.readlines(0) behaviour is inconsistent with documentation
type: behavior
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43126>
_______________________________________


More information about the New-bugs-announce mailing list