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

Stefan Behnel stefan_ml at behnel.de
Thu Mar 7 08:32:59 CET 2013


Hi,

I've written a patch that adds a new C-API call for dict.setdefault(). The
reason is that there is currently no way to test for a key and insert a
fallback value for it without either evaluating the hash function twice or
calling through the Python function. Both may involve considerable overhead
and the double hash may have side-effects.

http://bugs.python.org/issue17327

It does not include an explicit test because it does not add any code over
the normal dict.setdefault() implementation, which is already tested at the
Python level. If you prefer having a dummy test that checks that the
function is there, I don't mind adding one.

Please comment and/or apply the patch.

Thanks,

Stefan



More information about the Python-Dev mailing list