diff options
author | Raymond Hettinger <python@rcn.com> | 2013-09-02 15:59:26 -0700 |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2013-09-02 15:59:26 -0700 |
commit | 81ee0af7749af3994faad79de5e3092e5fb8ea49 (patch) | |
tree | dccbe677cf329ed99b8302adf1c498003fb035f3 /Python/errors.c | |
parent | 6f658143b3db6112ca84389362ca7eedd78ea351 (diff) | |
download | cpython-81ee0af7749af3994faad79de5e3092e5fb8ea49.tar.gz |
Factor-out the common code for setting a KeyError.
Diffstat (limited to 'Python/errors.c')
-rw-r--r-- | Python/errors.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Python/errors.c b/Python/errors.c index 93b1120191..b67448090f 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) { |