Issue #14930: Make memoryview objects weakrefable.

This commit is contained in:
Richard Oudkerk 2012-05-28 21:35:09 +01:00
parent 1cfe7d9a84
commit 3e0a1eb889
5 changed files with 23 additions and 2 deletions

View file

@ -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.