diff -r 26200f535296 Lib/test/test_capi.py --- a/Lib/test/test_capi.py Wed Oct 03 13:53:28 2012 +0530 +++ b/Lib/test/test_capi.py Thu Oct 04 09:26:56 2012 +0300 @@ -316,6 +316,17 @@ 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) diff -r 26200f535296 Modules/_testcapimodule.c --- a/Modules/_testcapimodule.c Wed Oct 03 13:53:28 2012 +0530 +++ b/Modules/_testcapimodule.c Thu Oct 04 09:26:56 2012 +0300 @@ -1238,7 +1238,7 @@ 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]);