Extending: overloading operators (e.g. for a vector class)
Chris Liechti
cliechti at gmx.net
Thu May 23 14:08:38 EDT 2002
thank you Greg and Bernhard. i'll try that
can you give me a hint where such thing as the NEW_STYLE_NUMBER flags are
documented?
chris
Greg Ewing <look at replyto.address.invalid> wrote in
news:3CEC5A54.F6EA2C82 at replyto.address.invalid:
> Chris Liechti wrote:
>>
>> it seems to me tp_as_number supports __mul__ for numbers, but only for
>> instances of the same type,
>
> Looking at the interpreter code, it looks like if you set
> the NEW_STYLE_NUMBER flag in the type object, the object's
> binary operator methods are called directly, regardless of
> the other operand type, and without any coercion.
>
>> and there seems so be an other place where a __mul__ can be emulated:
>> sq_repeat for sequences. can/must i define both, or none?
>
> It also seems that the sq_repeat slot is never called
> from interpreted code any more.
>
> So, it appears that if you:
>
> 1) set the NEW_STYLE_NUMBER flag
> 2) put your method in the tp_as_number->nb_multiply slot
>
> you will get the same result as you did with the
> Python version.
>
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list