Author: Armin Rigo <[email protected]>
Branch: gc-del
Changeset: r63612:038c24c72b90
Date: 2013-04-25 17:46 +0200
http://bitbucket.org/pypy/pypy/changeset/038c24c72b90/

Log:    Now attaching a __del__ to a class after its creation works.

diff --git a/pypy/objspace/std/test/test_typeobject.py 
b/pypy/objspace/std/test/test_typeobject.py
--- a/pypy/objspace/std/test/test_typeobject.py
+++ b/pypy/objspace/std/test/test_typeobject.py
@@ -58,7 +58,7 @@
             """)
         finally:
             space.warn = prev_warn
-        assert len(warnings) == 2
+        assert len(warnings) == 0     # should not give warnings any longer
 
     def test_metaclass_typedef(self):
         py.test.skip("Not implemented yet")
@@ -1062,6 +1062,18 @@
         A.__dict__['x'] = 5
         assert A.x == 5
 
+    def test_late_del(self):
+        seen = []
+        class A(object):
+            pass
+        A.__del__ = lambda self: seen.append(1)
+        A()
+        for i in range(5):
+            if seen:
+                break
+            import gc; gc.collect()
+        assert seen
+
 
 class AppTestWithMethodCacheCounter:
     spaceconfig = {"objspace.std.withmethodcachecounter": True}
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -293,6 +293,8 @@
         if not w_self.is_heaptype():
             msg = "can't set attributes on type object '%s'"
             raise operationerrfmt(space.w_TypeError, msg, w_self.name)
+        if name == "__del__":
+            w_self.has_del = True
         if space.config.objspace.std.withtypeversion:
             version_tag = w_self.version_tag()
             if version_tag is not None:
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to