[Python-Dev] fileobj.read(float): warning or error?

Guido van Rossum guido at python.org
Wed Jul 30 02:11:56 CEST 2008


On Mon, Jul 21, 2008 at 10:37 PM, Cameron Simpson <cs at zip.com.au> wrote:
> Leaving aside the 0.2 => 0 converstion, shouldn't read() raise an
> exception if asked for < 1 bytes? Or is there a legitimate use for read(0)
> with which I was not previously aware?

Indeed. read(0) is quite often generated as an edge case when one is
computing buffer sizes, and returning an empty string is most
definitely the right thing to do here (otherwise some application code
becomes more complex by having to avoid calling read(0) at all).

Of course, read(), read(None), read(-1) and read(<any negative int>)
should all read all data until EOF.

On the main topic here, read(<float>) and read(<anything that supports
__int__ but not __index__>) should definitely raise an exception in
3.0. In 2.6 it should show a warning as it does in 2.5.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list