Commits

Amaury Forgeot d'Arc  committed b82a4b6

Make memoryview objects weakrefable

  • Participants
  • Parent commits 02025d9
  • Branches py3.3

Comments (0)

Files changed (2)

File pypy/objspace/std/memoryobject.py

 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.error import OperationError, oefmt
 from pypy.interpreter.gateway import interp2app
-from pypy.interpreter.typedef import TypeDef, GetSetProperty
+from pypy.interpreter.typedef import TypeDef, GetSetProperty,  make_weakref_descr
 
 
 def _buffer_setitem(space, buf, w_index, w_obj):
     __repr__    = interp2app(W_MemoryView.descr_repr),
     __enter__   = interp2app(W_MemoryView.descr_enter),
     __exit__    = interp2app(W_MemoryView.descr_exit),
+    __weakref__ = make_weakref_descr(W_MemoryView),
     tobytes     = interp2app(W_MemoryView.descr_tobytes),
     tolist      = interp2app(W_MemoryView.descr_tolist),
     release     = interp2app(W_MemoryView.descr_release),

File pypy/objspace/std/test/test_memoryobject.py

     def test_hash(self):
         raises(TypeError, "hash(memoryview(b'hello'))")
 
+    def test_weakref(self):
+        import weakref
+        m = memoryview(b'hello')
+        weakref.ref(m)
+
     def test_getitem_only_ints(self):
         class MyInt(object):
           def __init__(self, x):