[Numpy-discussion] Removing undocumented __buffer__ attribute lookup

Hameer Abbasi einstein.edison at gmail.com
Wed Feb 27 03:37:32 EST 2019

Cc-ing in Travis, because he was the original author of the buffer protocol, and this is most definitely related.

Best Regards,
Hameer Abbasi

> On Wednesday, Feb 27, 2019 at 9:20 AM, Matti Picus <matti.picus at gmail.com (mailto:matti.picus at gmail.com)> wrote:
> In digging around the code, I found a gem in PyArray_FromBuffer (exposed
> to python as numpy.frombuffer). If a PyObject* does not have a
> tp_as_buffer->bf_getbuffer function, we check if the python object has a
> __buffer__ attribute. If so we use that as buf in
> PyObject_GetBuffer(buf, ...).
> This seems to stem back to the original numerics code, where getBuffer
> would look up the attribute and call it as a method. PyArray_FromBuffer
> does not call the attribute as a method, it simply passes it on to
> PyObject_GetBuffer, which will then raise an error saying it cannot
> convert a method. You can try this out by creating a class with a
> __buffer__ method and calling numpy.frombuffer on it.
> I submitted a pull request to remove the code. Since it is undocumented
> and (as far as I can tell) broken, I do not think we need a deprecation
> cycle.
> More details, including links to the original numeric code from 2005, in
> the PR https://github.com/numpy/numpy/pull/13049
> Any thoughts or objections?
> Matti
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20190227/e2cf94d9/attachment.html>

More information about the NumPy-Discussion mailing list