Index: Objects/unicodeobject.c =================================================================== --- Objects/unicodeobject.c (revision 79048) +++ Objects/unicodeobject.c (working copy) @@ -8666,6 +8666,7 @@ {"isprintable", (PyCFunction) unicode_isprintable, METH_NOARGS, isprintable__doc__}, {"zfill", (PyCFunction) unicode_zfill, METH_VARARGS, zfill__doc__}, {"format", (PyCFunction) do_string_format, METH_VARARGS | METH_KEYWORDS, format__doc__}, + {"format_using_mapping", (PyCFunction) do_string_format_using_mapping, METH_O, format__doc__}, {"__format__", (PyCFunction) unicode__format__, METH_VARARGS, p_format__doc__}, {"_formatter_field_name_split", (PyCFunction) formatter_field_name_split, METH_NOARGS}, {"_formatter_parser", (PyCFunction) formatter_parser, METH_NOARGS}, Index: Objects/stringlib/string_format.h =================================================================== --- Objects/stringlib/string_format.h (revision 79048) +++ Objects/stringlib/string_format.h (working copy) @@ -495,7 +495,11 @@ PyObject *key = SubString_new_object(&first); if (key == NULL) goto error; - if ((kwargs == NULL) || (obj = PyDict_GetItem(kwargs, key)) == NULL) { + + /* Use PyObject_GetItem instead of PyDict_GetItem because this + code is no longer just used with kwargs. It might be passed + a non-dict when called through format_using_mapping. */ + if ((kwargs == NULL) || (obj = PyObject_GetItem(kwargs, key)) == NULL) { PyErr_SetObject(PyExc_KeyError, key); Py_DECREF(key); goto error; @@ -1035,6 +1039,11 @@ return build_string(&input, args, kwargs, recursion_depth, &auto_number); } +static PyObject * +do_string_format_using_mapping(PyObject *self, PyObject *obj) +{ + return do_string_format(self, NULL, obj); +} /************************************************************************/