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

Stefan Behnel stefan_ml at behnel.de
Fri Sep 3 10:04:12 CEST 2010

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.

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? (thinking 
in terms of good-old Py2 StringIO here, not sure how io.BytesIO works these 

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.


More information about the Python-Dev mailing list