]> granicus.if.org Git - python/commitdiff
Improve exception message for str.format (GH-12675)
authorFrancisco Couzo <franciscouzo@gmail.com>
Sat, 1 Jun 2019 17:14:00 +0000 (14:14 -0300)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>
Sat, 1 Jun 2019 17:14:00 +0000 (10:14 -0700)
Objects/stringlib/unicode_format.h

index 0fa54eb32cd3610ef342c22fb399fe3249bdaf77..ddf1e26448693a9c12dcd23e85f62ab68c91545a 100644 (file)
@@ -440,8 +440,13 @@ get_field_object(SubString *input, PyObject *args, PyObject *kwargs,
 
         /* look up in args */
         obj = PySequence_GetItem(args, index);
-        if (obj == NULL)
-            goto error;
+        if (obj == NULL) {
+            PyErr_Format(PyExc_IndexError,
+                         "Replacement index %zd out of range for positional "
+                         "args tuple",
+                         index);
+             goto error;
+        }
     }
 
     /* iterate over the rest of the field_name */