[issue12974] array module: deprecate '__int__' conversion support for array elements
Stefan Krah
report at bugs.python.org
Fri Sep 16 15:00:05 CEST 2011
Stefan Krah <stefan-usenet at bytereef.org> added the comment:
Mark Dickinson <report at bugs.python.org> wrote:
> Yes, that's intentional. When use of __int__ was deprecated, a bug
> report popped up from someone who wanted to be able to have their own
> objects treated as integers for the purposes of struct.pack.
> (I don't recall which issue; Meador, do you remember?)
> So we added use of __index__ at that point.
Yes, I think that's #1530559, and the bug report was about PyCUDA. I can
see why 'bBhHiIlLqQ' allow __index__(), since they previously allowed
__int__().
I specifically meant the 'P' format. As far as I can see, PyLong_AsVoidPtr()
never allowed __int__(), but now index objects can be packed as pointers.
It isn't a big deal, I just have to know for features/pep-3118.
To illustrate, this is python2.5.0; INT is an object with an __int__() method:
'\x07\x00\x00\x00\x00\x00\x00\x00'
>>> struct.pack('P', INT(7))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/stefan/hg/r25/Lib/struct.py", line 63, in pack
return o.pack(*args)
struct.error: cannot convert argument to long
>>>
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12974>
_______________________________________
More information about the Python-bugs-list
mailing list