summaryrefslogtreecommitdiffstats
path: root/Objects/stringlib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-08-03 08:45:23 (GMT)
committerGitHub <noreply@github.com>2017-08-03 08:45:23 (GMT)
commit5075416b8fedc5526b643dabc915f7945fa0d969 (patch)
tree31e23d9e4dbda6c41dc8faf831cc543e9e4e89c9 /Objects/stringlib
parent25e4f779d7ae9f37a1933cb5cbfad06e673c01f9 (diff)
downloadcpython-5075416b8fedc5526b643dabc915f7945fa0d969.zip
cpython-5075416b8fedc5526b643dabc915f7945fa0d969.tar.gz
cpython-5075416b8fedc5526b643dabc915f7945fa0d969.tar.bz2
bpo-30978: str.format_map() now passes key lookup exceptions through. (#2790)
Previously any exception was replaced with a KeyError exception.
Diffstat (limited to 'Objects/stringlib')
-rw-r--r--Objects/stringlib/unicode_format.h16
1 files changed, 10 insertions, 6 deletions
diff --git a/Objects/stringlib/unicode_format.h b/Objects/stringlib/unicode_format.h
index 7ac0d75..baaac81 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