bpo-36669: add matmul support to weakref.proxy (GH-12932) · python/cpython@7abb6c0

Original file line numberDiff line numberDiff line change

@@ -285,6 +285,21 @@ def __ifloordiv__(self, other):

285285

p //= 5

286286

self.assertEqual(p, 21)

287287
288+

def test_proxy_matmul(self):

289+

class C:

290+

def __matmul__(self, other):

291+

return 1729

292+

def __rmatmul__(self, other):

293+

return -163

294+

def __imatmul__(self, other):

295+

return 561

296+

o = C()

297+

p = weakref.proxy(o)

298+

self.assertEqual(p @ 5, 1729)

299+

self.assertEqual(5 @ p, -163)

300+

p @= 5

301+

self.assertEqual(p, 561)

302+
288303

# The PyWeakref_* C API is documented as allowing either NULL or

289304

# None as the value for the callback, where either means "no

290305

# callback". The "no callback" ref and proxy objects are supposed