New submission from STINNER Victor:
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.
----------
messages: 211142
nosy: haypo, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Replace PyDict_GetItem() with PyDict_GetItemWithError()
versions: Python 3.3, Python 3.4, Python 3.5
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue20615>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com