[issue17327] Add PyDict_GetItemSetDefault() as C-API for dict.setdefault()

Stefan Behnel report at bugs.python.org
Fri Mar 1 14:45:55 CET 2013


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 <report at bugs.python.org>
<http://bugs.python.org/issue17327>
_______________________________________


More information about the Python-bugs-list mailing list