]> granicus.if.org Git - python/commitdiff
handle dict subclasses gracefully in PyArg_ValidateKeywordArguments
authorBenjamin Peterson <benjamin@python.org>
Wed, 17 Nov 2010 22:33:12 +0000 (22:33 +0000)
committerBenjamin Peterson <benjamin@python.org>
Wed, 17 Nov 2010 22:33:12 +0000 (22:33 +0000)
Lib/test/test_dict.py
Misc/NEWS
Objects/dictobject.c
Python/getargs.c

index 818c99ed3bb3404e20ea699bf75cf656614bdee8..1507e420538b90c86e2578e1c692e8343572076d 100644 (file)
@@ -8,10 +8,13 @@ import gc, weakref
 class DictTest(unittest.TestCase):
 
     def test_invalid_keyword_arguments(self):
-        with self.assertRaises(TypeError):
-            dict(**{1 : 2})
-        with self.assertRaises(TypeError):
-            {}.update(**{1 : 2})
+        class Custom(dict):
+            pass
+        for invalid in {1 : 2}, Custom({1 : 2}):
+            with self.assertRaises(TypeError):
+                dict(**invalid)
+            with self.assertRaises(TypeError):
+                {}.update(**invalid)
 
     def test_constructor(self):
         # calling built-in types without argument must return empty
index 9f47ca339cba8ca9c1a7dbe9d793d07517063e88..bf660ccc0e46536bfbf1b883f9f9d00cd96a58f3 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -26,6 +26,11 @@ Library
 - Issue #10429: IMAP.starttls() stored the capabilities as bytes objects,
   rather than strings.
 
+C-API
+-----
+
+- Loosen PyArg_ValidateKeywordArguments to allow dict subclasses.
+
 
 What's New in Python 3.2 Alpha 4?
 =================================
index 1015772898430e6e73a55b62b15100b7343626ea..df8d77f313d35ec5f716b329573782b180dab484 100644 (file)
@@ -454,7 +454,7 @@ _PyDict_HasOnlyStringKeys(PyObject *dict)
 {
     Py_ssize_t pos = 0;
     PyObject *key, *value;
-    assert(PyDict_CheckExact(dict));
+    assert(PyDict_Check(dict));
     /* Shortcut */
     if (((PyDictObject *)dict)->ma_lookup == lookdict_unicode)
         return 1;
index abf55ce041abfa46f1397769e46bd2986b14f273..cf9869965c2e4d5a7b3356d2c544321904b71346 100644 (file)
@@ -1394,7 +1394,7 @@ _PyArg_VaParseTupleAndKeywords_SizeT(PyObject *args,
 int
 PyArg_ValidateKeywordArguments(PyObject *kwargs)
 {
-    if (!PyDict_CheckExact(kwargs)) {
+    if (!PyDict_Check(kwargs)) {
         PyErr_BadInternalCall();
         return 0;
     }