[Python-checkins] python/dist/src/Objects dictobject.c,2.151,2.152

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Thu Mar 4 03:25:47 EST 2004


Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14562/Objects

Modified Files:
	dictobject.c 
Log Message:
SF #904720:  dict.update should take a 2-tuple sequence like dict.__init_
(Championed by Bob Ippolito.)

The update() method for mappings now accepts all the same argument forms
as the dict() constructor.  This includes item lists and/or keyword
arguments.



Index: dictobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/dictobject.c,v
retrieving revision 2.151
retrieving revision 2.152
diff -C2 -d -r2.151 -r2.152
*** dictobject.c	17 Feb 2004 20:10:11 -0000	2.151
--- dictobject.c	4 Mar 2004 08:25:44 -0000	2.152
***************
*** 1030,1037 ****
  }
  
  static PyObject *
! dict_update(PyObject *mp, PyObject *other)
  {
! 	if (PyDict_Update(mp, other) < 0)
  		return NULL;
  	Py_INCREF(Py_None);
--- 1030,1057 ----
  }
  
+ static int
+ dict_update_common(PyObject *self, PyObject *args, PyObject *kwds, char *methname)
+ {
+ 	PyObject *arg = NULL;
+ 	int result = 0;
+ 
+ 	if (!PyArg_UnpackTuple(args, methname, 0, 1, &arg))
+ 		result = -1;
+ 
+ 	else if (arg != NULL) {
+ 		if (PyObject_HasAttrString(arg, "keys"))
+ 			result = PyDict_Merge(self, arg, 1);
+ 		else
+ 			result = PyDict_MergeFromSeq2(self, arg, 1);
+ 	}
+ 	if (result == 0 && kwds != NULL)
+ 		result = PyDict_Merge(self, kwds, 1);
+ 	return result;
+ }
+ 
  static PyObject *
! dict_update(PyObject *self, PyObject *args, PyObject *kwds)
  {
! 	if (dict_update_common(self, args, kwds, "update") == -1)
  		return NULL;
  	Py_INCREF(Py_None);
***************
*** 1807,1811 ****
  	{"values",	(PyCFunction)dict_values,	METH_NOARGS,
  	 values__doc__},
! 	{"update",	(PyCFunction)dict_update,	METH_O,
  	 update__doc__},
  	{"fromkeys",	(PyCFunction)dict_fromkeys,	METH_VARARGS | METH_CLASS,
--- 1827,1831 ----
  	{"values",	(PyCFunction)dict_values,	METH_NOARGS,
  	 values__doc__},
! 	{"update",	(PyCFunction)dict_update,	METH_VARARGS | METH_KEYWORDS,
  	 update__doc__},
  	{"fromkeys",	(PyCFunction)dict_fromkeys,	METH_VARARGS | METH_CLASS,
***************
*** 1876,1894 ****
  dict_init(PyObject *self, PyObject *args, PyObject *kwds)
  {
! 	PyObject *arg = NULL;
! 	int result = 0;
! 
! 	if (!PyArg_UnpackTuple(args, "dict", 0, 1, &arg))
! 		result = -1;
! 
! 	else if (arg != NULL) {
! 		if (PyObject_HasAttrString(arg, "keys"))
! 			result = PyDict_Merge(self, arg, 1);
! 		else
! 			result = PyDict_MergeFromSeq2(self, arg, 1);
! 	}
! 	if (result == 0 && kwds != NULL)
! 		result = PyDict_Merge(self, kwds, 1);
! 	return result;
  }
  
--- 1896,1900 ----
  dict_init(PyObject *self, PyObject *args, PyObject *kwds)
  {
! 	return dict_update_common(self, args, kwds, "dict");
  }
  




More information about the Python-checkins mailing list