summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorJust van Rossum <just@letterror.com>2002-11-23 09:45:04 (GMT)
committerJust van Rossum <just@letterror.com>2002-11-23 09:45:04 (GMT)
commita797d8150dd6fd8336653d8e91db3c088f2c53ff (patch)
tree02fd69d522c9e7477b11e3cc530f7181d3d052f2 /Objects
parente17af7b3dbb0ebc6fea7e55052833564ca59d104 (diff)
downloadcpython-a797d8150dd6fd8336653d8e91db3c088f2c53ff.zip
cpython-a797d8150dd6fd8336653d8e91db3c088f2c53ff.tar.gz
cpython-a797d8150dd6fd8336653d8e91db3c088f2c53ff.tar.bz2
Patch #642500 with slight modifications: allow keyword arguments in
dict() constructor. Example: >>> dict(a=1, b=2) {'a': 1, 'b': 2} >>>
Diffstat (limited to 'Objects')
-rw-r--r--Objects/dictobject.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index e9726cf..2eaa20c 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -1705,7 +1705,7 @@ static PyMethodDef mapp_methods[] = {
{"setdefault", (PyCFunction)dict_setdefault, METH_VARARGS,
setdefault_doc__},
{"pop", (PyCFunction)dict_pop, METH_O,
- pop__doc__},
+ pop__doc__},
{"popitem", (PyCFunction)dict_popitem, METH_NOARGS,
popitem__doc__},
{"keys", (PyCFunction)dict_keys, METH_NOARGS,
@@ -1781,11 +1781,9 @@ static int
dict_init(PyObject *self, PyObject *args, PyObject *kwds)
{
PyObject *arg = NULL;
- static char *kwlist[] = {"items", 0};
int result = 0;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:dict",
- kwlist, &arg))
+ if (!PyArg_ParseTuple(args, "|O:dict", &arg))
result = -1;
else if (arg != NULL) {
@@ -1794,6 +1792,8 @@ dict_init(PyObject *self, PyObject *args, PyObject *kwds)
else
result = PyDict_MergeFromSeq2(self, arg, 1);
}
+ if (result == 0 && kwds != NULL)
+ result = PyDict_Merge(self, kwds, 1);
return result;
}
@@ -1817,7 +1817,9 @@ PyDoc_STRVAR(dictionary_doc,
"dict(seq) -> new dictionary initialized as if via:\n"
" d = {}\n"
" for k, v in seq:\n"
-" d[k] = v");
+" d[k] = v\n"
+"dict(**kwargs) -> new dictionary initialized with the name=value pairs\n"
+" in the keyword argument list. For example: dict(one=1, two=2)");
PyTypeObject PyDict_Type = {
PyObject_HEAD_INIT(&PyType_Type)