mirror of https://github.com/python/cpython
SF #1615701: make d.update(m) honor __getitem__() and keys() in dict subclasses
This commit is contained in:
parent
814ef237a2
commit
0922d71604
|
@ -189,6 +189,14 @@ class DictTest(unittest.TestCase):
|
||||||
|
|
||||||
self.assertRaises(ValueError, {}.update, [(1, 2, 3)])
|
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):
|
def test_fromkeys(self):
|
||||||
self.assertEqual(dict.fromkeys('abc'), {'a':None, 'b':None, 'c':None})
|
self.assertEqual(dict.fromkeys('abc'), {'a':None, 'b':None, 'c':None})
|
||||||
d = {}
|
d = {}
|
||||||
|
|
|
@ -1306,7 +1306,7 @@ PyDict_Merge(PyObject *a, PyObject *b, int override)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
mp = (dictobject*)a;
|
mp = (dictobject*)a;
|
||||||
if (PyDict_Check(b)) {
|
if (PyDict_CheckExact(b)) {
|
||||||
other = (dictobject*)b;
|
other = (dictobject*)b;
|
||||||
if (other == mp || other->ma_used == 0)
|
if (other == mp || other->ma_used == 0)
|
||||||
/* a.update(a) or a.update({}); nothing to do */
|
/* a.update(a) or a.update({}); nothing to do */
|
||||||
|
|
Loading…
Reference in New Issue