Skip to content

Commit 4fd06e0

Browse files
committed
Make sure that WeakValueDictionary[] raises KeyError instead of TypeError
for keys that are not in the dictionary.
1 parent 5d54879 commit 4fd06e0

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Lib/test/test_weakref.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@ def test_weak_values(self):
252252
del objects, o
253253
self.assert_(len(dict) == 0,
254254
"deleting the values did not clear the dictionary")
255+
# regression on SF bug #447152:
256+
dict = weakref.WeakValueDictionary()
257+
self.assertRaises(KeyError, dict.__getitem__, 1)
258+
dict[2] = C()
259+
self.assertRaises(KeyError, dict.__getitem__, 2)
255260

256261
def test_weak_keys(self):
257262
#

Lib/weakref.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class WeakValueDictionary(UserDict.UserDict):
4141
# way in).
4242

4343
def __getitem__(self, key):
44-
o = self.data.get(key)()
44+
o = self.data[key]()
4545
if o is None:
4646
raise KeyError, key
4747
else:

0 commit comments

Comments
 (0)