Merged revisions 68128 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r68128 | antoine.pitrou | 2009-01-01 15:11:22 +0100 (jeu., 01 janv. 2009) | 3 lines

  Issue #3680: Reference cycles created through a dict, set or deque iterator did not get collected.
........
diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py
index 403d5eb..2e74b68 100644
--- a/Lib/test/test_dict.py
+++ b/Lib/test/test_dict.py
@@ -2,6 +2,7 @@
 from test import support
 
 import sys, collections, random, string
+import gc, weakref
 
 
 class DictTest(unittest.TestCase):
@@ -648,6 +649,21 @@
             pass
         d = {}
 
+    def test_container_iterator(self):
+        # Bug #3680: tp_traverse was not implemented for dictiter and
+        # dictview objects.
+        class C(object):
+            pass
+        views = (dict.items, dict.values, dict.keys)
+        for v in views:
+            obj = C()
+            ref = weakref.ref(obj)
+            container = {obj: 1}
+            obj.v = v(container)
+            obj.x = iter(obj.v)
+            del obj, container
+            gc.collect()
+            self.assert_(ref() is None, "Cycle was not collected")
 
 
 from test import mapping_tests