mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Issue #14930: Make memoryview objects weakrefable.
This commit is contained in:
parent
1cfe7d9a84
commit
3e0a1eb889
5 changed files with 23 additions and 2 deletions
|
@ -336,6 +336,21 @@ class AbstractMemoryTests:
|
|||
m = self._view(b)
|
||||
self.assertRaises(ValueError, hash, m)
|
||||
|
||||
def test_weakref(self):
|
||||
# Check memoryviews are weakrefable
|
||||
for tp in self._types:
|
||||
b = tp(self._source)
|
||||
m = self._view(b)
|
||||
L = []
|
||||
def callback(wr, b=b):
|
||||
L.append(b)
|
||||
wr = weakref.ref(m, callback)
|
||||
self.assertIs(wr(), m)
|
||||
del m
|
||||
test.support.gc_collect()
|
||||
self.assertIs(wr(), None)
|
||||
self.assertIs(L[0], b)
|
||||
|
||||
# Variations on source objects for the buffer: bytes-like objects, then arrays
|
||||
# with itemsize > 1.
|
||||
# NOTE: support for multi-dimensional objects is unimplemented.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue