From 009afb7c90882ee83e196b62b1555067e14fd950 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 10 Jun 2002 20:00:52 +0000 Subject: =?UTF-8?q?SF=20patch=20564549=20(Erik=20Anders=C3=A9n).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The WeakKeyDictionary constructor didn't work when a dict arg was given. Fixed by moving a line. Also adding a unit test. Bugfix candidate. --- Lib/test/test_weakref.py | 11 +++++++++++ Lib/weakref.py | 2 +- Misc/ACKS | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py index 9f16482..0764358 100644 --- a/Lib/test/test_weakref.py +++ b/Lib/test/test_weakref.py @@ -391,6 +391,17 @@ class MappingTestCase(TestBase): values.remove(v) self.assert_(len(values) == 0, "itervalues() did not touch all values") + def test_make_weak_keyed_dict_from_dict(self): + o = Object(3) + dict = weakref.WeakKeyDictionary({o:364}) + self.assert_(dict[o] == 364) + + def test_make_weak_keyed_dict_from_weak_keyed_dict(self): + o = Object(3) + dict = weakref.WeakKeyDictionary({o:364}) + dict2 = weakref.WeakKeyDictionary(dict) + self.assert_(dict[o] == 364) + def make_weak_keyed_dict(self): dict = weakref.WeakKeyDictionary() objects = map(Object, range(self.COUNT)) diff --git a/Lib/weakref.py b/Lib/weakref.py index 70d36fa..a1fa4e8 100644 --- a/Lib/weakref.py +++ b/Lib/weakref.py @@ -144,12 +144,12 @@ class WeakKeyDictionary(UserDict.UserDict): def __init__(self, dict=None): self.data = {} - if dict is not None: self.update(dict) def remove(k, selfref=ref(self)): self = selfref() if self is not None: del self.data[k] self._remove = remove + if dict is not None: self.update(dict) def __delitem__(self, key): for ref in self.data.iterkeys(): diff --git a/Misc/ACKS b/Misc/ACKS index 0adeec3..51807a7 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -16,6 +16,7 @@ Jyrki Alakuijala Billy G. Allie Mark Anacker Anders Andersen +Erik Andersén Oliver Andrich Ross Andrus Jason Asbahr -- cgit v0.12