From 7ed0a6583188e3fdfd8912f05a5219771c419cf1 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Wed, 21 Mar 2007 20:36:45 +0000 Subject: [PATCH] Test and fix fromkeys optional argument. --- Lib/test/test_set.py | 3 +++ Objects/dictobject.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py index b46cac4a44b..ef7cea7be11 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 acf5ae31594..bc3cd53ebea 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;