]> granicus.if.org Git - python/commitdiff
Issue 10221: Improve error message for dict.pop().
authorRaymond Hettinger <python@rcn.com>
Sat, 30 Oct 2010 08:10:29 +0000 (08:10 +0000)
committerRaymond Hettinger <python@rcn.com>
Sat, 30 Oct 2010 08:10:29 +0000 (08:10 +0000)
Misc/NEWS
Objects/dictobject.c

index b1e701d8f208c217ede68fc90dab2c23bfbc07a3..52fecdd17b39a68d8c5305b69babed33d28f67d1 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.2 Beta 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 #5437: A preallocated MemoryError instance should not hold traceback
   data (including local variables caught in the stack trace) alive infinitely.
 
index d932ba7723eb9bc88f47868aaf4d9835bc800341..1015772898430e6e73a55b62b15100b7343626ea 100644 (file)
@@ -1820,8 +1820,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 (!PyUnicode_CheckExact(key) ||