Commit bff0e5cb authored by Stefan Behnel's avatar Stefan Behnel

Repair slot signature typing for "__richcmp__" special method after adding...

Repair slot signature typing for "__richcmp__" special method after adding synthesis from "__eq__" etc. methods.
Add test for "__richcmp__" override of existing "__eq__" etc. methods.
parent b75d2942
......@@ -402,9 +402,9 @@ class SyntheticSlot(InternalMethodSlot):
return self.default_value
class RichcmpSlot(SlotDescriptor):
class RichcmpSlot(MethodSlot):
def slot_code(self, scope):
entry = scope.lookup_here("__richcmp__")
entry = scope.lookup_here(self.method_name)
if entry and entry.func_cname:
return entry.func_cname
elif scope.defines_any(richcmp_special_methods):
......@@ -836,7 +836,7 @@ slot_table = (
GCDependentSlot("tp_traverse"),
GCClearReferencesSlot("tp_clear"),
RichcmpSlot("tp_richcompare", inherited=False), # Py3 checks for __hash__
RichcmpSlot(richcmpfunc, "tp_richcompare", "__richcmp__", inherited=False), # Py3 checks for __hash__
EmptySlot("tp_weaklistoffset"),
......
......@@ -216,6 +216,31 @@ class ClassEqNeGe(ClassEqNe):
return NotImplemented
@cython.cclass
class ClassRichcmpOverride(ClassEqNeGe):
"""
>>> a = ClassRichcmpOverride(1)
>>> b = ClassRichcmpOverride(1)
>>> a == a
True
>>> a != a
False
>>> a != b if compiled else a == b # Python ignores __richcmp__()
True
>>> a == b if compiled else a != b # Python ignores __richcmp__()
False
>>> if IS_PY2 or not compiled: raise TypeError # doctest: +ELLIPSIS
... else: a >= b # should no longer work when __richcmp__ is overwritten
Traceback (most recent call last):
TypeError...
"""
def __richcmp__(self, other, op):
return NotImplemented
@cython.cclass
class ClassLe(X):
"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment