changeset: 100222:c7eff18f3840 user: Serhiy Storchaka date: Thu Feb 11 12:41:40 2016 +0200 files: Lib/test/test_capi.py Misc/NEWS Python/getargs.c description: Issue #26312: SystemError is now raised in all programming bugs with using PyArg_ParseTupleAndKeywords(). RuntimeError did raised before in some programming bugs. diff -r 1ba0deb52223 -r c7eff18f3840 Lib/test/test_capi.py --- a/Lib/test/test_capi.py Wed Feb 10 22:58:18 2016 +0000 +++ b/Lib/test/test_capi.py Thu Feb 11 12:41:40 2016 +0200 @@ -491,7 +491,7 @@ except SystemError as e: s = "argument 1 (impossible)" when_not_skipped = (str(e) == s) - except (TypeError, RuntimeError): + except TypeError: when_not_skipped = False # test the format unit when skipped @@ -500,7 +500,7 @@ _testcapi.parse_tuple_and_keywords(empty_tuple, dict_b, optional_format.encode("ascii"), keywords) when_skipped = False - except RuntimeError as e: + except SystemError as e: s = "impossible: '{}'".format(format) when_skipped = (str(e) == s) diff -r 1ba0deb52223 -r c7eff18f3840 Misc/NEWS --- a/Misc/NEWS Wed Feb 10 22:58:18 2016 +0000 +++ b/Misc/NEWS Thu Feb 11 12:41:40 2016 +0200 @@ -741,6 +741,10 @@ C API ----- +- Issue #26312: SystemError is now raised in all programming bugs with using + PyArg_ParseTupleAndKeywords(). RuntimeError did raised before in some + programming bugs. + - Issue #26198: ValueError is now raised instead of TypeError on buffer overflow in parsing "es#" and "et#" format units. SystemError is now raised instead of TypeError on programmical error in parsing format string. diff -r 1ba0deb52223 -r c7eff18f3840 Python/getargs.c --- a/Python/getargs.c Wed Feb 10 22:58:18 2016 +0000 +++ b/Python/getargs.c Thu Feb 11 12:41:40 2016 +0200 @@ -1512,7 +1512,7 @@ keyword = kwlist[i]; if (*format == '|') { if (min != INT_MAX) { - PyErr_SetString(PyExc_RuntimeError, + PyErr_SetString(PyExc_SystemError, "Invalid format string (| specified twice)"); return cleanreturn(0, &freelist); } @@ -1521,14 +1521,14 @@ format++; if (max != INT_MAX) { - PyErr_SetString(PyExc_RuntimeError, + PyErr_SetString(PyExc_SystemError, "Invalid format string ($ before |)"); return cleanreturn(0, &freelist); } } if (*format == '$') { if (max != INT_MAX) { - PyErr_SetString(PyExc_RuntimeError, + PyErr_SetString(PyExc_SystemError, "Invalid format string ($ specified twice)"); return cleanreturn(0, &freelist); } @@ -1546,7 +1546,7 @@ } } if (IS_END_OF_FORMAT(*format)) { - PyErr_Format(PyExc_RuntimeError, + PyErr_Format(PyExc_SystemError, "More keyword list entries (%d) than " "format specifiers (%d)", len, i); return cleanreturn(0, &freelist); @@ -1598,14 +1598,14 @@ * keyword args */ msg = skipitem(&format, p_va, flags); if (msg) { - PyErr_Format(PyExc_RuntimeError, "%s: '%s'", msg, + PyErr_Format(PyExc_SystemError, "%s: '%s'", msg, format); return cleanreturn(0, &freelist); } } if (!IS_END_OF_FORMAT(*format) && (*format != '|') && (*format != '$')) { - PyErr_Format(PyExc_RuntimeError, + PyErr_Format(PyExc_SystemError, "more argument specifiers than keyword list entries " "(remaining format:'%s')", format); return cleanreturn(0, &freelist);