mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-36669: add matmul support to weakref.proxy (GH-12932)
This commit is contained in:
parent
3cde440f20
commit
7abb6c05af
5 changed files with 31 additions and 0 deletions
|
@ -285,6 +285,21 @@ class ReferencesTestCase(TestBase):
|
|||
p //= 5
|
||||
self.assertEqual(p, 21)
|
||||
|
||||
def test_proxy_matmul(self):
|
||||
class C:
|
||||
def __matmul__(self, other):
|
||||
return 1729
|
||||
def __rmatmul__(self, other):
|
||||
return -163
|
||||
def __imatmul__(self, other):
|
||||
return 561
|
||||
o = C()
|
||||
p = weakref.proxy(o)
|
||||
self.assertEqual(p @ 5, 1729)
|
||||
self.assertEqual(5 @ p, -163)
|
||||
p @= 5
|
||||
self.assertEqual(p, 561)
|
||||
|
||||
# The PyWeakref_* C API is documented as allowing either NULL or
|
||||
# None as the value for the callback, where either means "no
|
||||
# callback". The "no callback" ref and proxy objects are supposed
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue