@@ -258,6 +258,29 @@ test_dict_iteration(PyObject* self, PyObject *Py_UNUSED(ignored))
258258}
259259
260260
261+ static PyObject *
262+ dict_fromitems (PyObject * self , PyObject * args )
263+ {
264+ PyObject * keys_obj , * values_obj ;
265+ if (!PyArg_ParseTuple (args , "O!O!" ,
266+ & PyTuple_Type , & keys_obj ,
267+ & PyTuple_Type , & values_obj )) {
268+ return NULL ;
269+ }
270+
271+ Py_ssize_t length = PyTuple_GET_SIZE (keys_obj );
272+ if (PyTuple_GET_SIZE (values_obj ) != length ) {
273+ PyErr_SetString (PyExc_ValueError ,
274+ "keys and values must have the same length" );
275+ return NULL ;
276+ }
277+
278+ PyObject * * keys = & PyTuple_GET_ITEM (keys_obj , 0 );
279+ PyObject * * values = & PyTuple_GET_ITEM (values_obj , 0 );
280+ return PyDict_FromItems (keys , values , length );
281+ }
282+
283+
261284static PyMethodDef test_methods [] = {
262285 {"dict_containsstring" , dict_containsstring , METH_VARARGS },
263286 {"dict_getitemref" , dict_getitemref , METH_VARARGS },
@@ -268,7 +291,8 @@ static PyMethodDef test_methods[] = {
268291 {"dict_pop_null" , dict_pop_null , METH_VARARGS },
269292 {"dict_popstring" , dict_popstring , METH_VARARGS },
270293 {"dict_popstring_null" , dict_popstring_null , METH_VARARGS },
271- {"test_dict_iteration" , test_dict_iteration , METH_NOARGS },
294+ {"test_dict_iteration" , test_dict_iteration , METH_NOARGS },
295+ {"dict_fromitems" , dict_fromitems , METH_VARARGS },
272296 {NULL },
273297};
274298
0 commit comments