prevent their use as dictionary keys. *callback* is the same as the parameter
of the same name to the :func:`ref` function.
+ .. versionchanged:: 3.8
+ Extended the operator support on proxy objects to include the matrix
+ multiplication operators ``@`` and ``@=``.
+
.. function:: getweakrefcount(object)
activating virtual environments under PowerShell Core 6.1.
(Contributed by Brett Cannon in :issue:`32718`.)
+weakref
+-------
+
+* The proxy objects returned by :func:`weakref.proxy` now support the matrix
+ multiplication operators ``@`` and ``@=`` in addition to the other
+ numeric operators. (Contributed by Mark Dickinson in :issue:`36669`.)
+
xml
---
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
--- /dev/null
+Add missing matrix multiplication operator support to weakref.proxy.
WRAP_BINARY(proxy_ixor, PyNumber_InPlaceXor)
WRAP_BINARY(proxy_ior, PyNumber_InPlaceOr)
WRAP_UNARY(proxy_index, PyNumber_Index)
+WRAP_BINARY(proxy_matmul, PyNumber_MatrixMultiply)
+WRAP_BINARY(proxy_imatmul, PyNumber_InPlaceMatrixMultiply)
static int
proxy_bool(PyWeakReference *proxy)
proxy_ifloor_div, /*nb_inplace_floor_divide*/
proxy_itrue_div, /*nb_inplace_true_divide*/
proxy_index, /*nb_index*/
+ proxy_matmul, /*nb_matrix_multiply*/
+ proxy_imatmul, /*nb_inplace_matrix_multiply*/
};
static PySequenceMethods proxy_as_sequence = {