[Python-checkins] python/dist/src/Objects dictobject.c,2.130,2.131

jvr@users.sourceforge.net jvr@users.sourceforge.net
Sat, 23 Nov 2002 01:45:06 -0800


Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv31972/Objects

Modified Files:
	dictobject.c 
Log Message:
Patch #642500 with slight modifications: allow keyword arguments in
dict() constructor. Example:
  >>> dict(a=1, b=2)
  {'a': 1, 'b': 2}
  >>>


Index: dictobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/dictobject.c,v
retrieving revision 2.130
retrieving revision 2.131
diff -C2 -d -r2.130 -r2.131
*** dictobject.c	4 Sep 2002 11:29:45 -0000	2.130
--- dictobject.c	23 Nov 2002 09:45:04 -0000	2.131
***************
*** 1706,1710 ****
  	 setdefault_doc__},
  	{"pop",         (PyCFunction)dict_pop,          METH_O,
! 	 pop__doc__},	
  	{"popitem",	(PyCFunction)dict_popitem,	METH_NOARGS,
  	 popitem__doc__},
--- 1706,1710 ----
  	 setdefault_doc__},
  	{"pop",         (PyCFunction)dict_pop,          METH_O,
! 	 pop__doc__},
  	{"popitem",	(PyCFunction)dict_popitem,	METH_NOARGS,
  	 popitem__doc__},
***************
*** 1782,1790 ****
  {
  	PyObject *arg = NULL;
- 	static char *kwlist[] = {"items", 0};
  	int result = 0;
  
! 	if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:dict",
! 					 kwlist, &arg))
  		result = -1;
  
--- 1782,1788 ----
  {
  	PyObject *arg = NULL;
  	int result = 0;
  
! 	if (!PyArg_ParseTuple(args, "|O:dict", &arg))
  		result = -1;
  
***************
*** 1795,1798 ****
--- 1793,1798 ----
  			result = PyDict_MergeFromSeq2(self, arg, 1);
  	}
+ 	if (result == 0 && kwds != NULL)
+ 		result = PyDict_Merge(self, kwds, 1);
  	return result;
  }
***************
*** 1818,1822 ****
  "    d = {}\n"
  "    for k, v in seq:\n"
! "        d[k] = v");
  
  PyTypeObject PyDict_Type = {
--- 1818,1824 ----
  "    d = {}\n"
  "    for k, v in seq:\n"
! "        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 = {