| 201 | |
| 202 | @cpython_only |
| 203 | def test_legacy_finalizer_newclass(self): |
| 204 | # A() is uncollectable if it is part of a cycle, make sure it shows up |
| 205 | # in gc.garbage. |
| 206 | @with_tp_del |
| 207 | class A(object): |
| 208 | def __tp_del__(self): pass |
| 209 | class B(object): |
| 210 | pass |
| 211 | a = A() |
| 212 | a.a = a |
| 213 | id_a = id(a) |
| 214 | b = B() |
| 215 | b.b = b |
| 216 | gc.collect() |
| 217 | del a |
| 218 | del b |
| 219 | self.assertNotEqual(gc.collect(), 0) |
| 220 | for obj in gc.garbage: |
| 221 | if id(obj) == id_a: |
| 222 | del obj.a |
| 223 | break |
| 224 | else: |
| 225 | self.fail("didn't find obj in garbage (finalizer)") |
| 226 | gc.garbage.remove(obj) |
| 227 | |
| 228 | def test_function(self): |
| 229 | # Tricky: f -> d -> f, code should call d.clear() after the exec to |