[Python-checkins] Improve exception message for str.format (GH-12675)

Raymond Hettinger webhook-mailer at python.org
Sat Jun 1 13:14:04 EDT 2019


https://github.com/python/cpython/commit/9843bc110dc4241ba7cb05f3d3ef74ac6c77caf2
commit: 9843bc110dc4241ba7cb05f3d3ef74ac6c77caf2
branch: master
author: Francisco Couzo <franciscouzo at gmail.com>
committer: Raymond Hettinger <rhettinger at users.noreply.github.com>
date: 2019-06-01T10:14:00-07:00
summary:

Improve exception message for str.format (GH-12675)

files:
M Objects/stringlib/unicode_format.h

diff --git a/Objects/stringlib/unicode_format.h b/Objects/stringlib/unicode_format.h
index 0fa54eb32cd3..ddf1e2644869 100644
--- a/Objects/stringlib/unicode_format.h
+++ b/Objects/stringlib/unicode_format.h
@@ -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 */



More information about the Python-checkins mailing list