mirror of
https://github.com/python/cpython.git
synced 2025-08-29 05:05:03 +00:00
SF patch 564549 (Erik Andersén).
The WeakKeyDictionary constructor didn't work when a dict arg was given. Fixed by moving a line. Also adding a unit test. Bugfix candidate.
This commit is contained in:
parent
804cdca7ea
commit
009afb7c90
3 changed files with 13 additions and 1 deletions
|
@ -391,6 +391,17 @@ class MappingTestCase(TestBase):
|
||||||
values.remove(v)
|
values.remove(v)
|
||||||
self.assert_(len(values) == 0, "itervalues() did not touch all values")
|
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):
|
def make_weak_keyed_dict(self):
|
||||||
dict = weakref.WeakKeyDictionary()
|
dict = weakref.WeakKeyDictionary()
|
||||||
objects = map(Object, range(self.COUNT))
|
objects = map(Object, range(self.COUNT))
|
||||||
|
|
|
@ -144,12 +144,12 @@ class WeakKeyDictionary(UserDict.UserDict):
|
||||||
|
|
||||||
def __init__(self, dict=None):
|
def __init__(self, dict=None):
|
||||||
self.data = {}
|
self.data = {}
|
||||||
if dict is not None: self.update(dict)
|
|
||||||
def remove(k, selfref=ref(self)):
|
def remove(k, selfref=ref(self)):
|
||||||
self = selfref()
|
self = selfref()
|
||||||
if self is not None:
|
if self is not None:
|
||||||
del self.data[k]
|
del self.data[k]
|
||||||
self._remove = remove
|
self._remove = remove
|
||||||
|
if dict is not None: self.update(dict)
|
||||||
|
|
||||||
def __delitem__(self, key):
|
def __delitem__(self, key):
|
||||||
for ref in self.data.iterkeys():
|
for ref in self.data.iterkeys():
|
||||||
|
|
|
@ -16,6 +16,7 @@ Jyrki Alakuijala
|
||||||
Billy G. Allie
|
Billy G. Allie
|
||||||
Mark Anacker
|
Mark Anacker
|
||||||
Anders Andersen
|
Anders Andersen
|
||||||
|
Erik Andersén
|
||||||
Oliver Andrich
|
Oliver Andrich
|
||||||
Ross Andrus
|
Ross Andrus
|
||||||
Jason Asbahr
|
Jason Asbahr
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue