[Python-checkins] r53655 - in python/branches/release25-maint: Lib/test/test_dict.py Objects/dictobject.c
raymond.hettinger
python-checkins at python.org
Wed Feb 7 21:01:29 CET 2007
Author: raymond.hettinger
Date: Wed Feb 7 21:01:28 2007
New Revision: 53655
Modified:
python/branches/release25-maint/Lib/test/test_dict.py
python/branches/release25-maint/Objects/dictobject.c
Log:
SF #1615701: make d.update(m) honor __getitem__() and keys() in dict subclasses
Modified: python/branches/release25-maint/Lib/test/test_dict.py
==============================================================================
--- python/branches/release25-maint/Lib/test/test_dict.py (original)
+++ python/branches/release25-maint/Lib/test/test_dict.py Wed Feb 7 21:01:28 2007
@@ -189,6 +189,14 @@
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 = {}
Modified: python/branches/release25-maint/Objects/dictobject.c
==============================================================================
--- python/branches/release25-maint/Objects/dictobject.c (original)
+++ python/branches/release25-maint/Objects/dictobject.c Wed Feb 7 21:01:28 2007
@@ -1306,7 +1306,7 @@
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 */
More information about the Python-checkins
mailing list