]> granicus.if.org Git - python/commitdiff
SF #1615701: make d.update(m) honor __getitem__() and keys() in dict subclasses
authorRaymond Hettinger <python@rcn.com>
Wed, 7 Feb 2007 20:01:28 +0000 (20:01 +0000)
committerRaymond Hettinger <python@rcn.com>
Wed, 7 Feb 2007 20:01:28 +0000 (20:01 +0000)
Lib/test/test_dict.py
Objects/dictobject.c

index 218f7cc7aa2a1d41372ac6781b6bb030b7bd49b9..6d6e245d42b4f1165df02be9e0142bd0769965ea 100644 (file)
@@ -189,6 +189,14 @@ class DictTest(unittest.TestCase):
 
         self.assertRaises(ValueError, {}.update, [(1, 2, 3)])
 
+        # SF #1615701:  make d.update(m) honor __getitem__() and keys() in dict subclasses
+        class KeyUpperDict(dict):
+            def __getitem__(self, key):
+                return key.upper()
+        d.clear()
+        d.update(KeyUpperDict.fromkeys('abc'))
+        self.assertEqual(d, {'a':'A', 'b':'B', 'c':'C'})
+
     def test_fromkeys(self):
         self.assertEqual(dict.fromkeys('abc'), {'a':None, 'b':None, 'c':None})
         d = {}
index 5a5f86074d8b9e2a5872191c669e343b27ebbd1b..901e33383f222bb4c99eb1bc315d626d4b3691f0 100644 (file)
@@ -1306,7 +1306,7 @@ PyDict_Merge(PyObject *a, PyObject *b, int override)
                return -1;
        }
        mp = (dictobject*)a;
-       if (PyDict_Check(b)) {
+       if (PyDict_CheckExact(b)) {
                other = (dictobject*)b;
                if (other == mp || other->ma_used == 0)
                        /* a.update(a) or a.update({}); nothing to do */