New submission from Stefan Behnel: The functionality of dict.setdefault() is not currently available through the C-API. Specfically, there is no way to test for a key and insert a fallback value for it without evaluating the hash function twice.
The attached patch adds a new C-API function PyDict_GetItemSetDefault() that makes this feature available. Like all PyDict_Getitem*() functions, it returns a borrowed reference. I hope I got the update in refcounts.dat right. I have no idea how to express that a function *may* increase the refcounts of its arguments. ---------- components: Interpreter Core files: pydict_setitemdefault.patch keywords: patch messages: 183260 nosy: scoder priority: normal severity: normal status: open title: Add PyDict_GetItemSetDefault() as C-API for dict.setdefault() type: enhancement versions: Python 3.4 Added file: http://bugs.python.org/file29284/pydict_setitemdefault.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue17327> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com