summaryrefslogtreecommitdiffstats
path: root/Python/errors.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2013-09-02 22:59:26 (GMT)
committerRaymond Hettinger <python@rcn.com>2013-09-02 22:59:26 (GMT)
commit69492dab07772f71aa226cbafa03f7d50309dd43 (patch)
treed1ac5b703936538b8faa0fbd5bd5851064c5010d /Python/errors.c
parent7f5c22c022592e5e9a82520e152d619f58382e7d (diff)
downloadcpython-69492dab07772f71aa226cbafa03f7d50309dd43.zip
cpython-69492dab07772f71aa226cbafa03f7d50309dd43.tar.gz
cpython-69492dab07772f71aa226cbafa03f7d50309dd43.tar.bz2
Factor-out the common code for setting a KeyError.
Diffstat (limited to 'Python/errors.c')
-rw-r--r--Python/errors.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/Python/errors.c b/Python/errors.c
index 93b1120..b674480 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -117,6 +117,20 @@ PyErr_SetObject(PyObject *exception, PyObject *value)
PyErr_Restore(exception, value, tb);
}
+/* Set a key error with the specified argument, wrapping it in a
+ * tuple automatically so that tuple keys are not unpacked as the
+ * exception arguments. */
+void
+_PyErr_SetKeyError(PyObject *arg)
+{
+ PyObject *tup;
+ tup = PyTuple_Pack(1, arg);
+ if (!tup)
+ return; /* caller will expect error to be set anyway */
+ PyErr_SetObject(PyExc_KeyError, tup);
+ Py_DECREF(tup);
+}
+
void
PyErr_SetNone(PyObject *exception)
{