mirror of
https://github.com/AdaCore/cpython.git
synced 2026-02-12 12:57:15 -08:00
Issue #6081: Add str.format_map. str.format_map(mapping) is similar to str.format(**mapping), except mapping does not get converted to a dict.
This commit is contained in:
@@ -499,7 +499,11 @@ get_field_object(SubString *input, PyObject *args, PyObject *kwargs,
|
||||
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_map. */
|
||||
if ((kwargs == NULL) || (obj = PyObject_GetItem(kwargs, key)) == NULL) {
|
||||
PyErr_SetObject(PyExc_KeyError, key);
|
||||
Py_DECREF(key);
|
||||
goto error;
|
||||
@@ -1039,6 +1043,11 @@ do_string_format(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||
return build_string(&input, args, kwargs, recursion_depth, &auto_number);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
do_string_format_map(PyObject *self, PyObject *obj)
|
||||
{
|
||||
return do_string_format(self, NULL, obj);
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user