[Python-Dev] Re: [Patch #100740] gzip: readline(), readlines() patch
Guido van Rossum
guido@beopen.com
Fri, 28 Jul 2000 09:33:32 -0500
> >Almost right. The docs for file objects specifically imply that a
> >negative arg to readline() or a zero arg to readlines() is the same as
> >no args; your defaults are sys.maxint so an explicit -1 or 0 won't do
> >the right thing. (This is important for wrapper classes that want to
>
> Which docs say this? I looked at Doc/lib/libstdtypes.tex to get the
> semantics:
>
> \begin{methoddesc}[file]{readline}{\optional{size}}
> ... If the \var{size} argument is present and
> non-negative, it is a maximum byte count (including the trailing
> newline) and an incomplete line may be returned. ...
> \end{methoddesc}
I read this that any negative argument has the same effect as an
absent argument. I suggested -1 as a typical negative number. The
doc could be more explicit though.
> \begin{methoddesc}[file]{readlines}{\optional{sizehint}}
> ... If the optional \var{sizehint} argument is
> present, instead of reading up to \EOF{}, whole lines totalling
> approximately \var{sizehint} bytes (possibly after rounding up to an
> internal buffer size) are read.
> \end{methoddesc}
Here you're right -- I got the 0 from the code. It should be
documented.
> Neither text mentions the special cases for -1 and 0 in each function.
> Fixing the patch to get this right is trivial, but I think the docs
> need to be updated to mention this.
Agreed.
--Guido van Rossum (home page: http://www.pythonlabs.com/~guido/)