[Python-Dev] Re: [bug?] UserLong.py - pow(5, UserLong(3), 26) fails
Luke Kenneth Casson Leighton
lkcl@samba-tng.org
Wed, 1 May 2002 19:42:26 +0000
On Wed, May 01, 2002 at 07:14:14PM +0000, Luke Kenneth Casson Leighton wrote:
> as part of the evaluation, i have created UserLong.py,
> and am working my way through the list of all operations.
> one of these - pow(int(5), UserLong(3), 26) - is failing
further preliminary analysis shows that the error message
is being reported from Objects/abstract.c:ternary_op.c.
without doing any debugging, i presume that PyNumber_Coerce
and the macro NEW_STYLE_NUMBER are both failing to identify
"class UserLong" as supporting numerical operations.
now, there _may_ be some way to add an operator to
class UserLong which identifies it as a "number" - i don't
know what it is. anyone know?
PyNumber_Coerce requires that the HOF table
(PyObject*)w->ob_type->tp_as_number be != NULL in
order for it to call tp_as_number->nb_coerce() and
_that_ apparently will give number coercion.
however, that means that _even_ if i define "__coerce__"
in class UserLong, it won't get called because tp_as_number
is an optimisation/speedup HOF table of functions, yes?
so, the check in PyNumber_Coerce needs to also have
"if (tp_as_number == NULL) lookup_function("__coerce__")
and call it"
am i right?
l.
--
----------------------------------------------------------
this message is private, confidential, and is intented for
the specified recipients only. if you received in error,
altered, deleted, modified, destroyed or interfered with
the contents of this message, in whole or in part, please
inform the sender (that's me), immediately.
if you, the recipient, reply to this message, and do not
then receive a response, please consider your reply to have
been lost or deliberately destroyed: i *always* acknowledge
personal email received. please therefore take appropriate
action and use appropriate protocols to ensure effective
communication.
thank you.