[issue18524] BufferedReader.read1() documentation/implementation difference

Nikolaus Rath report at bugs.python.org
Mon Jul 22 06:56:15 CEST 2013


New submission from Nikolaus Rath:

The read1() docstring says: "Reads up to n bytes, with at most one read() system call."

However, in the implementation read1() calls peek() to refill the buffer if necessary, and then returns whatever is available in the buffer.

This means that read1() will only return up to n bytes if n is smaller than the buffer size, otherwise it will return at most <buffer-size> bytes.


With the current implementation, running a loop that calls obj.read1(n) for large n is therefore much less performant than a loop that calls obj.raw.read(n). 

I think a call to read1(n) with empty buffer should always attempt to read n bytes from the raw stream, i.e. the implementation should be changed to match the documentation.

----------
components: IO
messages: 193496
nosy: Nikratio
priority: normal
severity: normal
status: open
title: BufferedReader.read1() documentation/implementation difference
versions: Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18524>
_______________________________________


More information about the Python-bugs-list mailing list