[Python-checkins] r86501 - in python/branches/py3k: Lib/test/test_dict.py Misc/NEWS Objects/dictobject.c Python/getargs.c
benjamin.peterson
python-checkins at python.org
Wed Nov 17 23:33:14 CET 2010
Author: benjamin.peterson
Date: Wed Nov 17 23:33:12 2010
New Revision: 86501
Log:
handle dict subclasses gracefully in PyArg_ValidateKeywordArguments
Modified:
python/branches/py3k/Lib/test/test_dict.py
python/branches/py3k/Misc/NEWS
python/branches/py3k/Objects/dictobject.c
python/branches/py3k/Python/getargs.c
Modified: python/branches/py3k/Lib/test/test_dict.py
==============================================================================
--- python/branches/py3k/Lib/test/test_dict.py (original)
+++ python/branches/py3k/Lib/test/test_dict.py Wed Nov 17 23:33:12 2010
@@ -8,10 +8,13 @@
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
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Wed Nov 17 23:33:12 2010
@@ -26,6 +26,11 @@
- 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?
=================================
Modified: python/branches/py3k/Objects/dictobject.c
==============================================================================
--- python/branches/py3k/Objects/dictobject.c (original)
+++ python/branches/py3k/Objects/dictobject.c Wed Nov 17 23:33:12 2010
@@ -454,7 +454,7 @@
{
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;
Modified: python/branches/py3k/Python/getargs.c
==============================================================================
--- python/branches/py3k/Python/getargs.c (original)
+++ python/branches/py3k/Python/getargs.c Wed Nov 17 23:33:12 2010
@@ -1394,7 +1394,7 @@
int
PyArg_ValidateKeywordArguments(PyObject *kwargs)
{
- if (!PyDict_CheckExact(kwargs)) {
+ if (!PyDict_Check(kwargs)) {
PyErr_BadInternalCall();
return 0;
}
More information about the Python-checkins
mailing list