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 <20110916125702.GA17500@sleipnir.bytereef.org>
In-reply-to <1316174347.72.0.567410783453.issue12974@psf.upfronthosting.co.za>
Content
Mark Dickinson <report@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
>>>
History
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