Author vstinner
Recipients serhiy.storchaka, vstinner
Date 2014-02-13.10:44:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1392288253.13.0.332874319538.issue20615@psf.upfronthosting.co.za>
In-reply-to
Content
See this huge warning in the definition of PyDict_GetItem:

/* Note that, for historical reasons, PyDict_GetItem() suppresses all errors
 * that may occur (originally dicts supported only string keys, and exceptions
 * weren't possible).  So, while the original intent was that a NULL return
 * meant the key wasn't present, in reality it can mean that, or that an error
 * (suppressed) occurred while computing the key's hash, or that some error
 * (suppressed) occurred when comparing keys in the dict's internal probe
 * sequence.  A nasty example of the latter is when a Python-coded comparison
 * function hits a stack-depth error, which can cause this to return NULL
 * even if the key is present.
 */
PyObject *
PyDict_GetItem(PyObject *op, PyObject *key)
{ ... }

PyDict_GetItem() should avoided because it may hide important exceptions like KeyboardInterrupt or MemoryError.

See for example #14537 for a specific error.

By the way, the PyDict_GetItem() documentation should contain a big red warning and suggest to use PyDict_GetItemWithError() instead.
History
Date User Action Args
2014-02-13 10:44:13vstinnersetrecipients: + vstinner, serhiy.storchaka
2014-02-13 10:44:13vstinnersetmessageid: <1392288253.13.0.332874319538.issue20615@psf.upfronthosting.co.za>
2014-02-13 10:44:13vstinnerlinkissue20615 messages
2014-02-13 10:44:12vstinnercreate