Skip to content

Commit 9843bc1

Browse files
franciscouzorhettinger
authored andcommitted
Improve exception message for str.format (GH-12675)
1 parent cd74e66 commit 9843bc1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Objects/stringlib/unicode_format.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,13 @@ get_field_object(SubString *input, PyObject *args, PyObject *kwargs,
440440

441441
/* look up in args */
442442
obj = PySequence_GetItem(args, index);
443-
if (obj == NULL)
444-
goto error;
443+
if (obj == NULL) {
444+
PyErr_Format(PyExc_IndexError,
445+
"Replacement index %zd out of range for positional "
446+
"args tuple",
447+
index);
448+
goto error;
449+
}
445450
}
446451

447452
/* iterate over the rest of the field_name */

0 commit comments

Comments
 (0)