Author skrah
Recipients mark.dickinson, meador.inge, skrah
Date 2011-09-16.13:00:03
SpamBayes Score 4.25232e-06
Marked as misclassified No
Message-id <>
In-reply-to <>
Mark Dickinson <> 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

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:

>>> struct.pack('P', INT(7))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/stefan/hg/r25/Lib/", line 63, in pack
    return o.pack(*args)
struct.error: cannot convert argument to long
Date User Action Args
2011-09-16 13:00:05skrahsetrecipients: + skrah, mark.dickinson, meador.inge
2011-09-16 13:00:04skrahlinkissue12974 messages
2011-09-16 13:00:03skrahcreate