]> granicus.if.org Git - python/commitdiff
Add test and fix for fromkeys() optional argument.
authorRaymond Hettinger <python@rcn.com>
Wed, 21 Mar 2007 20:33:57 +0000 (20:33 +0000)
committerRaymond Hettinger <python@rcn.com>
Wed, 21 Mar 2007 20:33:57 +0000 (20:33 +0000)
Lib/test/test_set.py
Objects/dictobject.c

index e6e0ba6b5b169171b9dc58edc0ba3f47822a48d4..f528ad89ee06efdf6d70fcc95d8d0cd86c44c8aa 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 06cc4a8bd9f44f0925949c84279acb77c0f6a829..7d6ff610077eb1aea874433aa13431fe191688f6 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;