Mercurial > cpython-lru_cache-weakref
diff Python/errors.c @ 85502:bfaf3a2907bd
Factor-out the common code for setting a KeyError.
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Mon, 02 Sep 2013 15:59:26 -0700 |
| parents | ef889c3d5dc6 |
| children | eeec58c57964 |
line wrap: on
line diff
--- a/Python/errors.c Mon Sep 02 08:57:21 2013 -0700 +++ b/Python/errors.c Mon Sep 02 15:59:26 2013 -0700 @@ -117,6 +117,20 @@ 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) {
