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!
Can you please suggest a temporary workaround?

Thank you very much!

Kornel Jahn

-- 
Kornél JAHN
engineering physicist, PhD student
Budapest University of Technology and Economics, Hungary
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to