[pypy-svn] r49532 - in pypy/branch/pypy-interp-file/module/_file: . test

arigo at codespeak.net arigo at codespeak.net
Fri Dec 7 20:12:06 CET 2007


Author: arigo
Date: Fri Dec  7 20:12:04 2007
New Revision: 49532

Modified:
   pypy/branch/pypy-interp-file/module/_file/interp_file.py
   pypy/branch/pypy-interp-file/module/_file/test/test_file_extra.py
Log:
Files are weakrefable.


Modified: pypy/branch/pypy-interp-file/module/_file/interp_file.py
==============================================================================
--- pypy/branch/pypy-interp-file/module/_file/interp_file.py	(original)
+++ pypy/branch/pypy-interp-file/module/_file/interp_file.py	Fri Dec  7 20:12:04 2007
@@ -6,7 +6,7 @@
 from pypy.interpreter.error import OperationError
 from pypy.interpreter.gateway import ObjSpace, W_Root, Arguments
 from pypy.interpreter.typedef import TypeDef, GetSetProperty
-from pypy.interpreter.typedef import interp_attrproperty
+from pypy.interpreter.typedef import interp_attrproperty, make_weakref_descr
 from pypy.interpreter.gateway import interp2app
 
 
@@ -466,6 +466,7 @@
                               doc="Support for 'print'."),
     __repr__ = interp2app(W_File.file__repr__),
     readinto = interp2app(W_File.file_readinto),
+    __weakref__ = make_weakref_descr(W_File),
     **dict([(name, interp2app(getattr(W_File, 'file_' + name)))
                 for name in W_File._exposed_method_names])
     )

Modified: pypy/branch/pypy-interp-file/module/_file/test/test_file_extra.py
==============================================================================
--- pypy/branch/pypy-interp-file/module/_file/test/test_file_extra.py	(original)
+++ pypy/branch/pypy-interp-file/module/_file/test/test_file_extra.py	Fri Dec  7 20:12:04 2007
@@ -498,3 +498,13 @@
         assert n == 6
         assert len(a) == 10
         assert a.tostring() == 'foobar6789'
+
+    def test_weakref(self):
+        """Files are weakrefable."""
+        import weakref
+        fn = self.temptestfile
+        f = open(fn, 'wb')
+        ref = weakref.ref(f)
+        ref().write('hello')
+        assert f.tell() == 5
+        f.close()



More information about the Pypy-commit mailing list