From: Raymond Hettinger Date: Wed, 21 Mar 2007 20:33:57 +0000 (+0000) Subject: Add test and fix for fromkeys() optional argument. X-Git-Tag: v2.6a1~1949 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e3146f5aa3cbb8d28a6a429b5ccc07002e339ff2;p=thirdparty%2FPython%2Fcpython.git Add test and fix for fromkeys() optional argument. --- diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py index e6e0ba6b5b16..f528ad89ee06 100644 --- a/Lib/test/test_set.py +++ b/Lib/test/test_set.py @@ -293,6 +293,9 @@ class TestJointOps(unittest.TestCase): self.assertEqual(sum(elem.hash_count for elem in d), n) d3 = dict.fromkeys(frozenset(d)) self.assertEqual(sum(elem.hash_count for elem in d), n) + d3 = dict.fromkeys(frozenset(d), 123) + self.assertEqual(sum(elem.hash_count for elem in d), n) + self.assertEqual(d3, dict.fromkeys(d, 123)) class TestSet(TestJointOps): thetype = set diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 06cc4a8bd9f4..7d6ff610077e 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -1186,8 +1186,8 @@ dict_fromkeys(PyObject *cls, PyObject *args) while (_PySet_NextEntry(seq, &pos, &key, &hash)) { Py_INCREF(key); - Py_INCREF(Py_None); - if (insertdict(mp, key, hash, Py_None)) + Py_INCREF(value); + if (insertdict(mp, key, hash, value)) return NULL; } return d;