From 5075416b8fedc5526b643dabc915f7945fa0d969 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 3 Aug 2017 11:45:23 +0300 Subject: bpo-30978: str.format_map() now passes key lookup exceptions through. (#2790) Previously any exception was replaced with a KeyError exception. --- Objects/stringlib/unicode_format.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'Objects/stringlib') diff --git a/Objects/stringlib/unicode_format.h b/Objects/stringlib/unicode_format.h index 7ac0d75166..baaac811a5 100644 --- a/Objects/stringlib/unicode_format.h +++ b/Objects/stringlib/unicode_format.h @@ -410,18 +410,22 @@ get_field_object(SubString *input, PyObject *args, PyObject *kwargs, if (index == -1) { /* look up in kwargs */ PyObject *key = SubString_new_object(&first); - if (key == NULL) + if (key == NULL) { goto error; - - /* 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) { + } + if (kwargs == NULL) { PyErr_SetObject(PyExc_KeyError, key); Py_DECREF(key); goto error; } + /* 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. */ + obj = PyObject_GetItem(kwargs, key); Py_DECREF(key); + if (obj == NULL) { + goto error; + } } else { /* If args is NULL, we have a format string with a positional field -- cgit v1.2.1