mirror of
https://github.com/python/cpython.git
synced 2026-04-26 22:01:08 +00:00
[3.6] bpo-30978: str.format_map() now passes key lookup exceptions through. (GH-2790) (#2992)
Previously any exception was replaced with a KeyError exception.
(cherry picked from commit 5075416)
This commit is contained in:
parent
f142e85d22
commit
f08b2be441
4 changed files with 20 additions and 7 deletions
|
|
@ -412,18 +412,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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue