Magic methods in extension types

Michael Hudson mwh at python.net
Mon Apr 26 07:21:56 EDT 2004


Jacek Generowicz <jacek.generowicz at cern.ch> writes:

> I am writing an extension type, and wish to add some magic methods
> which are not catered for by the tp_<whatever> slots (eg tp_init ->
> __init__) in PyTypeObject. My methods seem to work correctly when
> invoked explicitly (eg obj.__iadd__(3)) but the method seems not to be
> associated with the corresponding operator (ie obj += 3 does NOT
> work).
> 
> What am I likely to be doing wrong ?

Not finding the tp_as_number->nb_inplace_add field?

I think *all* magic methods correspond to slots in (or near) the type
object -- it's practically the definition of "magic method"!

Cheers,
mwh

-- 
  I sense much distrust in you.  Distrust leads to cynicism, cynicism
  leads to bitterness, bitterness leads to the Awareness Of True
  Reality which is referred to by those-who-lack-enlightenment as
  "paranoia".  I approve.    -- David P. Murphy, alt.sysadmin.recovery



More information about the Python-list mailing list