diff --git a/src/zope/security/_proxy.c b/src/zope/security/_proxy.c index d38eaeb..4a953db 100644 --- a/src/zope/security/_proxy.c +++ b/src/zope/security/_proxy.c @@ -326,6 +326,10 @@ proxy_richcompare(SecurityProxy* self, PyObject* other, int op) { PyObject *result = NULL; + if (Proxy_Check(other)) { + other = ((SecurityProxy*)(other))->proxy.proxy_object; + } + result = PyObject_RichCompare(self->proxy.proxy_object, other, op); if (result == Py_True || result == Py_False) return result; diff --git a/src/zope/security/proxy.py b/src/zope/security/proxy.py index 66a4cb7..a4df5ae 100644 --- a/src/zope/security/proxy.py +++ b/src/zope/security/proxy.py @@ -177,32 +177,32 @@ def __delattr__(self, name): def __lt__(self, other): # no check wrapped = super().__getattribute__('_wrapped') - return wrapped < other + return wrapped < getObjectPy(other) def __le__(self, other): # no check wrapped = super().__getattribute__('_wrapped') - return wrapped <= other + return wrapped <= getObjectPy(other) def __eq__(self, other): # no check wrapped = super().__getattribute__('_wrapped') - return wrapped == other + return wrapped == getObjectPy(other) def __ne__(self, other): # no check wrapped = super().__getattribute__('_wrapped') - return wrapped != other + return wrapped != getObjectPy(other) def __ge__(self, other): # no check wrapped = super().__getattribute__('_wrapped') - return wrapped >= other + return wrapped >= getObjectPy(other) def __gt__(self, other): # no check wrapped = super().__getattribute__('_wrapped') - return wrapped > other + return wrapped > getObjectPy(other) def __hash__(self): # no check diff --git a/src/zope/security/tests/test_proxy.py b/src/zope/security/tests/test_proxy.py index 90e9fc3..669a519 100644 --- a/src/zope/security/tests/test_proxy.py +++ b/src/zope/security/tests/test_proxy.py @@ -1638,9 +1638,16 @@ def testCallOK(self): def testCallFail(self): self.shouldFail(self.p, None) - def testRichCompareOK(self): + def testRichCompareProxyWithObjectOK(self): self.assertTrue(self.p == self.x) + def testRichCompareObjectWithProxyOK(self): + # Proxy does not get unwrapped as `Something` class defines `__eq__`. + self.assertFalse(self.x == self.p) + + def testRichCompareWithProxyWithProxyOK(self): + self.assertTrue(self.p == self.p) + # def testRichCompareFail(self): # self.shouldFail(lambda: self.p == self.x)