]> granicus.if.org Git - python/commitdiff
Make sure that WeakValueDictionary[] raises KeyError instead of TypeError
authorFred Drake <fdrake@acm.org>
Fri, 3 Aug 2001 04:11:27 +0000 (04:11 +0000)
committerFred Drake <fdrake@acm.org>
Fri, 3 Aug 2001 04:11:27 +0000 (04:11 +0000)
for keys that are not in the dictionary.

Lib/test/test_weakref.py
Lib/weakref.py

index bb4ce7639ef88525a6ed8621579e99403537444e..341d53fae282ff4c1a2454bac3b99a77c849ee8e 100644 (file)
@@ -252,6 +252,11 @@ class MappingTestCase(TestBase):
         del objects, o
         self.assert_(len(dict) == 0,
                      "deleting the values did not clear the dictionary")
+        # regression on SF bug #447152:
+        dict = weakref.WeakValueDictionary()
+        self.assertRaises(KeyError, dict.__getitem__, 1)
+        dict[2] = C()
+        self.assertRaises(KeyError, dict.__getitem__, 2)
 
     def test_weak_keys(self):
         #
index cf950baef72e160444c999184098a85175d89530..1d21e7988670538c8f771f975fbf71326f3848a8 100644 (file)
@@ -41,7 +41,7 @@ class WeakValueDictionary(UserDict.UserDict):
     # way in).
 
     def __getitem__(self, key):
-        o = self.data.get(key)()
+        o = self.data[key]()
         if o is None:
             raise KeyError, key
         else: