<html xmlns="http://www.w3.org/1999/xhtml"><head> <title></title> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> </head> <body style="font-family:Helvetica;color:#000000;font-size:13px;"><div id="CanaryBody"> <div> Cc-ing in Travis, because he was the original author of the buffer protocol, and this is most definitely related.</div> <div><br></div> </div> <div id="CanarySig"> <div> <div style="font-family:Helvetica;color:#000;font-size:13px;">Best Regards,<div>Hameer Abbasi</div></div> <div><br></div> </div> </div> <div id="CanaryDropbox"> </div> <blockquote id="CanaryBlockquote"> <div> <div>On Wednesday, Feb 27, 2019 at 9:20 AM, Matti Picus <<a href="mailto:matti.picus@gmail.com">matti.picus@gmail.com</a>> wrote:<br></div> <div>In digging around the code, I found a gem in PyArray_FromBuffer (exposed <br>to python as numpy.frombuffer). If a PyObject* does not have a <br>tp_as_buffer->bf_getbuffer function, we check if the python object has a <br>__buffer__ attribute. If so we use that as buf in <br>PyObject_GetBuffer(buf, ...). <br> <br> <br>This seems to stem back to the original numerics code, where getBuffer <br>would look up the attribute and call it as a method. PyArray_FromBuffer <br>does not call the attribute as a method, it simply passes it on to <br>PyObject_GetBuffer, which will then raise an error saying it cannot <br>convert a method. You can try this out by creating a class with a <br>__buffer__ method and calling numpy.frombuffer on it. <br> <br> <br>I submitted a pull request to remove the code. Since it is undocumented <br>and (as far as I can tell) broken, I do not think we need a deprecation <br>cycle. <br> <br> <br>More details, including links to the original numeric code from 2005, in <br>the PR https://github.com/numpy/numpy/pull/13049 <br> <br> <br>Any thoughts or objections? <br> <br> <br>Matti <br> <br>_______________________________________________ <br>NumPy-Discussion mailing list <br>NumPy-Discussion@python.org <br>https://mail.python.org/mailman/listinfo/numpy-discussion <br></div> </div> </blockquote> <img id="65D7AEDBDFB40570EEA3EDE9EFC4F08D" width="1px" src="http://pixels.canarymail.io:8100/track/977C99C0645380AF45E168B4CDA443F5_65D7AEDBDFB40570EEA3EDE9EFC4F08D.png" height="1px"></body></html>