Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c06de47

Browse files
committed
Issue #6149: Fix initialization of WeakValueDictionary objects from non-empty parameters.
1 parent 3b1b807 commit c06de47

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

Lib/test/test_weakref.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,17 @@ def make_weak_keyed_dict(self):
942942
dict[o] = o.arg
943943
return dict, objects
944944

945+
def test_make_weak_valued_dict_from_dict(self):
946+
o = Object(3)
947+
dict = weakref.WeakValueDictionary({364:o})
948+
self.assertEqual(dict[364], o)
949+
950+
def test_make_weak_valued_dict_from_weak_valued_dict(self):
951+
o = Object(3)
952+
dict = weakref.WeakValueDictionary({364:o})
953+
dict2 = weakref.WeakValueDictionary(dict)
954+
self.assertEqual(dict[364], o)
955+
945956
def make_weak_valued_dict(self):
946957
dict = weakref.WeakValueDictionary()
947958
objects = list(map(Object, range(self.COUNT)))

Lib/weakref.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def remove(wr, selfref=ref(self)):
4949
del self.data[wr.key]
5050
self._remove = remove
5151
self.data = d = {}
52-
d.update(*args, **kw)
52+
self.update(*args, **kw)
5353

5454
def __getitem__(self, key):
5555
o = self.data[key]()

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Core and Builtins
1515
Library
1616
-------
1717

18+
- Issue #6149: Fix initialization of WeakValueDictionary objects from non-empty
19+
parameters.
20+
1821

1922
What's New in Python 3.1 release candidate 1?
2023
=============================================

0 commit comments

Comments
 (0)