Skip to content

Commit 4d089ff

Browse files
author
Michael Howitz
committed
Unwrap other if it is a proxy, so the proxy can compare equal to itself.
1 parent 024cb9a commit 4d089ff

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/zope/security/_proxy.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@ proxy_richcompare(SecurityProxy* self, PyObject* other, int op)
361361
{
362362
PyObject *result = NULL;
363363

364+
if (Proxy_Check(other)) {
365+
other = ((SecurityProxy*)(other))->proxy.proxy_object;
366+
}
367+
364368
result = PyObject_RichCompare(self->proxy.proxy_object, other, op);
365369
if (result == Py_True || result == Py_False)
366370
return result;

src/zope/security/tests/test_proxy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1864,7 +1864,8 @@ def testRichCompareProxyWithObjectOK(self):
18641864
self.assertTrue(self.p == self.x)
18651865

18661866
def testRichCompareObjectWithProxyOK(self):
1867-
self.assertTrue(self.x == self.p)
1867+
# Proxy does not get unwrapped as `Something` class defines `__eq__`.
1868+
self.assertFalse(self.x == self.p)
18681869

18691870
def testRichCompareWithProxyWithProxyOK(self):
18701871
self.assertTrue(self.p == self.p)

0 commit comments

Comments
 (0)