On Sun, Dec 19, 2010 at 1:47 AM, Kornél JAHN <corn...@gmail.com> wrote: > Thank you for your quick reply, you are right, I ought to have read it. > Sorry for bothering.
No problem, you're not the first to be bitten by that. It's an unfortunate wart in the language, but fortunately one of the few. > On Sun, Dec 19, 2010 at 10:40 AM, Robert Bradshaw > <rober...@math.washington.edu> wrote: >> >> On Sun, Dec 19, 2010 at 1:31 AM, Kornél JAHN <corn...@gmail.com> wrote: >> > Hello, >> > I have been experiencing strange behavior regarding overloaded operators >> > for >> > cdef classes, using Cython 0.14. I think it can be regarded as a bug. >> > See >> > the example code below: >> > # File: opoverload.pyx >> > class Test1: >> > def __rmul__(self, other): >> > print "Calling Test1.__rmul__() with", type(self), type(other) >> > def __mul__(self, other): >> > print "Calling Test1.__mul__() with", type(self), type(other) >> > cdef class Test2: >> > def __rmul__(self, other): >> > print "Calling Test2.__rmul__() with", type(self), type(other) >> > def __mul__(self, other): >> > print "Calling Test2.__mul__() with", type(self), type(other) >> > Python console: >> >>>> from opoverload import * >> >>>> Test1() * 2.0 >> > Calling Test1.__mul__() with <type 'instance'> <type 'float'> >> >>>> 2.0 * Test1() >> > Calling Test1.__rmul__() with <type 'instance'> <type 'float'> >> >>>> Test2() * 2.0 >> > Calling Test2.__mul__() with <type 'opoverload.Test2'> <type 'float'> >> >>>> 2.0 * Test2() >> > Calling Test2.__mul__() with <type 'float'> <type 'opoverload.Test2'> >> > Test2.__rmul__() should be called and type(self) should not become >> > float! >> >> Have you read http://docs.cython.org/src/userguide/special_methods.html ? >> >> > Can you please suggest a temporary workaround? >> >> Manually check the types in your arithmetic functions. (Yes, I know >> that's not as nice as it could be, it's just a reflection of the >> underlying C API that we haven't glossed over.) >> >> - Robert >> _______________________________________________ >> Cython-dev mailing list >> Cython-dev@codespeak.net >> http://codespeak.net/mailman/listinfo/cython-dev > > > > -- > Kornél JAHN > engineering physicist, PhD student > Budapest University of Technology and Economics, Hungary > > _______________________________________________ > Cython-dev mailing list > Cython-dev@codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > > _______________________________________________ Cython-dev mailing list Cython-dev@codespeak.net http://codespeak.net/mailman/listinfo/cython-dev