From: Raymond Hettinger Date: Sat, 30 Oct 2010 08:17:46 +0000 (+0000) Subject: Issue 10221: Improve error message for dict.pop(). X-Git-Tag: v2.7.1rc1~97 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2ad17e19eec7f873005a215a00c13520c679d4fb;p=python Issue 10221: Improve error message for dict.pop(). --- diff --git a/Misc/NEWS b/Misc/NEWS index eeff4a7760..dc5dca453f 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 2.7.1? Core and Builtins ----------------- +- Issue #10221: dict.pop(k) now has a key error message that includes the + missing key (same message d[k] returns for missing keys). + - Issue #10125: Don't segfault when the iterator passed to ``file.writelines()`` closes the file. diff --git a/Objects/dictobject.c b/Objects/dictobject.c index def3da9af0..3670e974ad 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -1980,8 +1980,7 @@ dict_pop(PyDictObject *mp, PyObject *args) Py_INCREF(deflt); return deflt; } - PyErr_SetString(PyExc_KeyError, - "pop(): dictionary is empty"); + set_key_error(key); return NULL; } if (!PyString_CheckExact(key) ||