There is a small error in weakref.WeakValueDictionary.
This error was found in 2.1c1, a quick look in the
april 15th build revealed it was not fixed.
Demonstration:
>>> class Spam:
... pass
...
>>> dict = {'a':Spam()}
>>> weakref.WeakValueDictionary(dict)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File
"/usr/local/python-2.1c1/lib/python2.1/UserDict.py",
line 6, in __init__
if dict is not None: self.update(dict)
File
"/usr/local/python-2.1c1/lib/python2.1/weakref.py",
line 103, in update
L.append(key, ref(o, remove))
Examination of the script reveals that the fix is obvious:
def update(self, dict):
d = self.data
L = []
for key, o in dict.items():
def remove(o, data=d, key=key):
del data[key]
# L.append(key, ref(o, remove))
# ^^^ erroneous ^^^^
L.append((key, ref(o, remove)))
# ^^^ right ^^^
for key, r in L:
d[key] = r
|