[issue29159] Regression in bytes constructor
Alexander Belopolsky
report at bugs.python.org
Wed Jan 4 16:38:21 EST 2017
Alexander Belopolsky added the comment:
I don't think we should put too much effort into preserving numpy behavior. Consider this python 3.5 session:
>>> import numpy
>>> a = numpy.array([1])
>>> bytes(a)
__main__:1: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future
b'\x00'
>>> a = numpy.array([2, 2])
>>> bytes(a)
b'\x02\x00\x00\x00\x02\x00\x00\x00'
It looks like this behavior is just an artifact of ndarray providing both __index__ and buffer protocol and not something thought out by numpy developers.
I wonder if we could check for buffer protocol support before detecting an integer argument? I also recall a discussion of deprecating bytes(int) altogether. See <https://mail.python.org/pipermail/python-ideas/2014-March/027295.html>.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29159>
_______________________________________
More information about the Python-bugs-list
mailing list