Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7abb6c05
Commit
7abb6c05
authored
Apr 26, 2019
by
Mark Dickinson
Committed by
GitHub
Apr 26, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-36669: add matmul support to weakref.proxy (GH-12932)
parent
3cde440f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
0 deletions
+31
-0
Doc/library/weakref.rst
Doc/library/weakref.rst
+4
-0
Doc/whatsnew/3.8.rst
Doc/whatsnew/3.8.rst
+7
-0
Lib/test/test_weakref.py
Lib/test/test_weakref.py
+15
-0
Misc/NEWS.d/next/Library/2019-04-24-17-08-45.bpo-36669.X4g0fu.rst
...S.d/next/Library/2019-04-24-17-08-45.bpo-36669.X4g0fu.rst
+1
-0
Objects/weakrefobject.c
Objects/weakrefobject.c
+4
-0
No files found.
Doc/library/weakref.rst
View file @
7abb6c05
...
...
@@ -139,6 +139,10 @@ Extension types can easily be made to support weak references; see
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)
...
...
Doc/whatsnew/3.8.rst
View file @
7abb6c05
...
...
@@ -450,6 +450,13 @@ venv
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
---
...
...
Lib/test/test_weakref.py
View file @
7abb6c05
...
...
@@ -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
...
...
Misc/NEWS.d/next/Library/2019-04-24-17-08-45.bpo-36669.X4g0fu.rst
0 → 100644
View file @
7abb6c05
Add missing matrix multiplication operator support to weakref.proxy.
Objects/weakrefobject.c
View file @
7abb6c05
...
...
@@ -525,6 +525,8 @@ WRAP_BINARY(proxy_iand, PyNumber_InPlaceAnd)
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
)
...
...
@@ -642,6 +644,8 @@ static PyNumberMethods proxy_as_number = {
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
=
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment