]> granicus.if.org Git - python/commitdiff
Closes #16126: PyErr_Format format mismatch in _testcapimodule.c
authorJesus Cea <jcea@jcea.es>
Thu, 4 Oct 2012 14:06:30 +0000 (16:06 +0200)
committerJesus Cea <jcea@jcea.es>
Thu, 4 Oct 2012 14:06:30 +0000 (16:06 +0200)
Lib/test/test_capi.py
Misc/NEWS
Modules/_testcapimodule.c

index d3c4a0490a8b67453871a2d609fb7b14a466f74e..af15a3d3350f8fd3a63fa627f6584b4654b14a8a 100644 (file)
@@ -316,6 +316,17 @@ class SkipitemTest(unittest.TestCase):
                     c, i, when_skipped, when_not_skipped))
             self.assertIs(when_skipped, when_not_skipped, message)
 
+    def test_parse_tuple_and_keywords(self):
+        # parse_tuple_and_keywords error handling tests
+        self.assertRaises(TypeError, _testcapi.parse_tuple_and_keywords,
+                          (), {}, 42, [])
+        self.assertRaises(ValueError, _testcapi.parse_tuple_and_keywords,
+                          (), {}, b'', 42)
+        self.assertRaises(ValueError, _testcapi.parse_tuple_and_keywords,
+                          (), {}, b'', [''] * 42)
+        self.assertRaises(ValueError, _testcapi.parse_tuple_and_keywords,
+                          (), {}, b'', [42])
+
 def test_main():
     support.run_unittest(CAPITest, TestPendingCalls,
                          Test6012, EmbeddingTest, SkipitemTest)
index 4051d2b1554dc42851f80c9ff60a387b48fca36b..3ad1bc8901c635f12b35e3dbce9fc9ce96c04ea5 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -73,6 +73,9 @@ Library
   `io.BytesIO` and `io.StringIO` objects now raise ValueError when the object
   has been closed.  Patch by Alessandro Moura.
 
+- Issue #16126: PyErr_Format format mismatch in _testcapimodule.c.
+  Patch by Serhiy Storchaka.
+
 - Issue #15447: Use `subprocess.DEVNULL` in webbrowser, instead of opening
   `os.devnull` explicitly and leaving it open.
 
index ce58651512d3cc8845f5b3d2cc855eb2bc37332f..ab11f5169263caf876a7b0f49f71ec4d78f286c7 100644 (file)
@@ -1238,7 +1238,7 @@ parse_tuple_and_keywords(PyObject *self, PyObject *args)
         o = PySequence_Fast_GET_ITEM(sub_keywords, i);
         if (!PyUnicode_FSConverter(o, (void *)(converted + i))) {
             PyErr_Format(PyExc_ValueError,
-                "parse_tuple_and_keywords: could not convert keywords[%s] to narrow string", i);
+                "parse_tuple_and_keywords: could not convert keywords[%zd] to narrow string", i);
             goto exit;
         }
         keywords[i] = PyBytes_AS_STRING(converted[i]);