Hi Jeroen, On 2015-03-04, Jeroen Demeyer <jdeme...@cage.ugent.be> wrote: > On 2015-03-04 14:47, Simon King wrote: >> I don't agree with that description. If a Python class has both __cmp__ >> and _cmp_ (or both __add__ and _add_), then of course __cmp__ (resp. >> __add__) are called. > > If a Python class has __add__ and _add_, then the *coercion framework* > will use _add_, not __add__.
No. If a Python class has just *some* __add__, then the coercion framework is out of the game. It must be sage.structure.element.ModuleElement.__add__, or it won't work. Example: sage: from sage.structure.element import ModuleElement sage: class MyClass(ModuleElement): ....: def __add__(self, other): ....: print "no coercion is involved" ....: return self ....: def _add_(self, other): ....: print "we got coercion" ....: return self ....: sage: E = MyClass(ZZ) sage: E+E no coercion is involved Generic element of a structure sage: E+1 no coercion is involved Generic element of a structure sage: class MyClass(ModuleElement): ....: def _add_(self, other): ....: print "we got coercion" ....: return self ....: sage: E = MyClass(ZZ) sage: E+E we got coercion Generic element of a structure sage: E+1 we got coercion Generic element of a structure Unless you mean something else when you say coercion framework. Best regards, Simon -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.