Test and fix fromkeys optional argument.
authorRaymond Hettinger <python@rcn.com>
Wed, 21 Mar 2007 20:36:45 +0000 (20:36 +0000)
committerRaymond Hettinger <python@rcn.com>
Wed, 21 Mar 2007 20:36:45 +0000 (20:36 +0000)
Lib/test/test_set.py
Objects/dictobject.c

index b46cac4a44b4679757740016ed1c31ac52c2197e..ef7cea7be1110d1c68b267b7b4d4c63f42cc2e76 100644 (file)
@@ -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
index acf5ae3159414bc7f49859f0e6b35769334350f2..bc3cd53ebeabf9383dc23586750d31bcd39c6ce5 100644 (file)
@@ -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;