mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
allow cycles throught the __dict__ slot to be cleared (closes #1469629)
Patch from Armin, test from me.
This commit is contained in:
parent
ec17afdfda
commit
a8d458560e
3 changed files with 27 additions and 4 deletions
|
|
@ -1,7 +1,9 @@
|
|||
import __builtin__
|
||||
import gc
|
||||
import sys
|
||||
import types
|
||||
import unittest
|
||||
import weakref
|
||||
|
||||
from copy import deepcopy
|
||||
from test import test_support
|
||||
|
|
@ -1127,7 +1129,6 @@ order (MRO) for bases """
|
|||
self.assertEqual(Counted.counter, 0)
|
||||
|
||||
# Test lookup leaks [SF bug 572567]
|
||||
import gc
|
||||
if hasattr(gc, 'get_objects'):
|
||||
class G(object):
|
||||
def __cmp__(self, other):
|
||||
|
|
@ -4541,7 +4542,6 @@ order (MRO) for bases """
|
|||
self.assertRaises(AttributeError, getattr, C(), "attr")
|
||||
self.assertEqual(descr.counter, 4)
|
||||
|
||||
import gc
|
||||
class EvilGetattribute(object):
|
||||
# This used to segfault
|
||||
def __getattr__(self, name):
|
||||
|
|
@ -4590,6 +4590,21 @@ order (MRO) for bases """
|
|||
foo = Foo()
|
||||
str(foo)
|
||||
|
||||
def test_cycle_through_dict(self):
|
||||
# See bug #1469629
|
||||
class X(dict):
|
||||
def __init__(self):
|
||||
dict.__init__(self)
|
||||
self.__dict__ = self
|
||||
x = X()
|
||||
x.attr = 42
|
||||
wr = weakref.ref(x)
|
||||
del x
|
||||
test_support.gc_collect()
|
||||
self.assertIsNone(wr())
|
||||
for o in gc.get_objects():
|
||||
self.assertIsNot(type(o), X)
|
||||
|
||||
class DictProxyTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
class C(object):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue