Hello,
Something seems really wrong here, maybe with my code. It seems that
the self argument of __richcmp__ is not typed correctly. Before I
file a bug report, is __richcmp__ treated as a static method with the
arguments still being each of the tested objects?
Here's what's happening.
With this code:
{{{
cdef class A:
cdef int _a
def __init__(self, int a):
self._a = a
def __richcmp__(self, b, int t):
if not isinstance(b, A):
return False
if t == 2:
return self._a == (<A>b)._a
def test():
a1 = A(1)
a2 = A(1)
assert a1 == a2
}}}
I get the following results:
{{{
In [1]: import richcmp_self_typing
In [2]: richcmp_self_typing.test()
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (230, 0))
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/home/hoytak/workspace/cython-tests/modloadvars/<ipython console> in <module>()
/home/hoytak/workspace/cython-tests/modloadvars/richcmp_self_typing.so
in richcmp_self_typing.test (richcmp_self_typing.c:515)()
16 def test():
17 a1 = A(1)
18 a2 = A(1)
19
---> 20 assert a1 == a2
/home/hoytak/workspace/cython-tests/modloadvars/richcmp_self_typing.so
in richcmp_self_typing.A.__richcmp__ (richcmp_self_typing.c:404)()
12
13 if t == 2:
---> 14 return self._a == (<A>b)._a
15
16 def test():
AttributeError: 'richcmp_self_typing.A' object has no attribute '_a'
> /home/hoytak/workspace/cython-tests/modloadvars/richcmp_self_typing.pyx(14)richcmp_self_typing.A.__richcmp__
> (richcmp_self_typing.c:404)()
13 if t == 2:
---> 14 return self._a == (<A>b)._a
15
}}}
However, when I explicitly type the self (note last line), it works.
{{{
cdef class A:
cdef int _a
def __init__(self, int a):
self._a = a
def __richcmp__(self, b, int t):
if not isinstance(b, A):
return False
if t == 2:
return (<A>self)._a == (<A>b)._a
}}}
Thanks!
--Hoyt
--
++++++++++++++++++++++++++++++++++++++++++++++++
+ Hoyt Koepke
+ University of Washington Department of Statistics
+ http://www.stat.washington.edu/~hoytak/
+ [email protected]
++++++++++++++++++++++++++++++++++++++++++
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev