[Python-Dev] Buffer protocol for io.BytesIO?

Antoine Pitrou solipsis at pitrou.net
Fri Sep 3 10:54:23 CEST 2010

On Fri, 03 Sep 2010 10:04:12 +0200
Stefan Behnel <stefan_ml at behnel.de> wrote:
> Antoine Pitrou, 02.09.2010 22:35:
> > In issue #5506, I originally proposed that io.BytesIO objects support
> > the buffer protocol, to make it possible to access the internal buffer
> > without intermediate copies.
> >
> > Then it came to me then perhaps it would be too automatic. So I'm
> > currently floating between:
> > - add implicit buffer protocol support to BytesIO objects
> Hmm, given that you actually have to *explicitly* call the getbuffer 
> operation on the BytesIO object, I don't have the impression that this 
> would be *implicit* support.

That's the other alternative, precisely.

> What would be the advantage of having to do two operations? Is it just that 
> you want to make the internal buffer joining step more visible?

I was just wondering if it's a good thing to let people, e.g.,
concatenate a bytes object and a BytesIO by using '+'.

> Also, note that the BytesIO object must not be modified while someone reads 
> the buffer. That would be a less obvious side effect if the returned buffer 
> object was different from the BytesIO object itself.

It could not be resized, but it could be modified (same as what happens
with bytearrays today). Actually, the buffer itself would be writable,
and allow modifying the BytesIO contents.



More information about the Python-Dev mailing list