]> granicus.if.org Git - python/commitdiff
Issue #6149: Fix initialization of WeakValueDictionary objects from non-empty parameters.
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 30 May 2009 21:04:26 +0000 (21:04 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 30 May 2009 21:04:26 +0000 (21:04 +0000)
Lib/test/test_weakref.py
Lib/weakref.py
Misc/NEWS

index 9821e1ba759864ab692fe04c2db039db3e55a1be..049dba21105069ab4479eca0f8475d99851b5622 100644 (file)
@@ -942,6 +942,17 @@ class MappingTestCase(TestBase):
             dict[o] = o.arg
         return dict, objects
 
+    def test_make_weak_valued_dict_from_dict(self):
+        o = Object(3)
+        dict = weakref.WeakValueDictionary({364:o})
+        self.assertEqual(dict[364], o)
+
+    def test_make_weak_valued_dict_from_weak_valued_dict(self):
+        o = Object(3)
+        dict = weakref.WeakValueDictionary({364:o})
+        dict2 = weakref.WeakValueDictionary(dict)
+        self.assertEqual(dict[364], o)
+
     def make_weak_valued_dict(self):
         dict = weakref.WeakValueDictionary()
         objects = list(map(Object, range(self.COUNT)))
index 0276dfd117edb2f24bb5d00cca1ed599869e351c..5e6cc8be3a056183080af8850a7d9cd3c46ec6f9 100644 (file)
@@ -49,7 +49,7 @@ class WeakValueDictionary(collections.MutableMapping):
                 del self.data[wr.key]
         self._remove = remove
         self.data = d = {}
-        d.update(*args, **kw)
+        self.update(*args, **kw)
 
     def __getitem__(self, key):
         o = self.data[key]()
index 8130b7f1a4a3319b8893be3f33cf20473543cc13..6fa6d99a6fb4eca31f88040697c41620aaa39c07 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,6 +15,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #6149: Fix initialization of WeakValueDictionary objects from non-empty
+  parameters.
+
 
 What's New in Python 3.1 release candidate 1?
 =============================================