mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
handle dict subclasses gracefully in PyArg_ValidateKeywordArguments
This commit is contained in:
parent
12ae290bf3
commit
f609654b0e
4 changed files with 14 additions and 6 deletions
|
@ -8,10 +8,13 @@ import gc, weakref
|
||||||
class DictTest(unittest.TestCase):
|
class DictTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_invalid_keyword_arguments(self):
|
def test_invalid_keyword_arguments(self):
|
||||||
|
class Custom(dict):
|
||||||
|
pass
|
||||||
|
for invalid in {1 : 2}, Custom({1 : 2}):
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
dict(**{1 : 2})
|
dict(**invalid)
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
{}.update(**{1 : 2})
|
{}.update(**invalid)
|
||||||
|
|
||||||
def test_constructor(self):
|
def test_constructor(self):
|
||||||
# calling built-in types without argument must return empty
|
# calling built-in types without argument must return empty
|
||||||
|
|
|
@ -26,6 +26,11 @@ Library
|
||||||
- Issue #10429: IMAP.starttls() stored the capabilities as bytes objects,
|
- Issue #10429: IMAP.starttls() stored the capabilities as bytes objects,
|
||||||
rather than strings.
|
rather than strings.
|
||||||
|
|
||||||
|
C-API
|
||||||
|
-----
|
||||||
|
|
||||||
|
- Loosen PyArg_ValidateKeywordArguments to allow dict subclasses.
|
||||||
|
|
||||||
|
|
||||||
What's New in Python 3.2 Alpha 4?
|
What's New in Python 3.2 Alpha 4?
|
||||||
=================================
|
=================================
|
||||||
|
|
|
@ -454,7 +454,7 @@ _PyDict_HasOnlyStringKeys(PyObject *dict)
|
||||||
{
|
{
|
||||||
Py_ssize_t pos = 0;
|
Py_ssize_t pos = 0;
|
||||||
PyObject *key, *value;
|
PyObject *key, *value;
|
||||||
assert(PyDict_CheckExact(dict));
|
assert(PyDict_Check(dict));
|
||||||
/* Shortcut */
|
/* Shortcut */
|
||||||
if (((PyDictObject *)dict)->ma_lookup == lookdict_unicode)
|
if (((PyDictObject *)dict)->ma_lookup == lookdict_unicode)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -1394,7 +1394,7 @@ _PyArg_VaParseTupleAndKeywords_SizeT(PyObject *args,
|
||||||
int
|
int
|
||||||
PyArg_ValidateKeywordArguments(PyObject *kwargs)
|
PyArg_ValidateKeywordArguments(PyObject *kwargs)
|
||||||
{
|
{
|
||||||
if (!PyDict_CheckExact(kwargs)) {
|
if (!PyDict_Check(kwargs)) {
|
||||||
PyErr_BadInternalCall();
|
PyErr_BadInternalCall();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue