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

2013-03-11 Thread Stefan Behnel
Stefan Behnel added the comment: Thanks! -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.

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

2013-03-11 Thread Roundup Robot
Roundup Robot added the comment: New changeset f6f39ebd3121 by Benjamin Peterson in branch 'default': fix spelling (#17327) http://hg.python.org/cpython/rev/f6f39ebd3121 -- ___ Python tracker __

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

2013-03-11 Thread Stefan Behnel
Stefan Behnel added the comment: ... and it's called "defaultobj", not "defautobj". -- ___ Python tracker ___ ___ Python-bugs-list mai

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

2013-03-11 Thread Roundup Robot
Roundup Robot added the comment: New changeset 8948dd77b095 by Benjamin Peterson in branch 'default': say defaultobj is returned (#17327) http://hg.python.org/cpython/rev/8948dd77b095 -- ___ Python tracker

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

2013-03-11 Thread Stefan Behnel
Stefan Behnel added the comment: Please use either of the following wordings in the documentation: """ If the key is not in the dict, it is inserted with value *defaultobj* and *defaultobj* is returned. """ or """ If the key is not in the dict, it is inserted with value *defaultobj*, which is

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

2013-03-11 Thread Roundup Robot
Roundup Robot added the comment: New changeset 89174df2ee45 by Benjamin Peterson in branch 'default': remove useless words (#17327) http://hg.python.org/cpython/rev/89174df2ee45 -- ___ Python tracker __

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

2013-03-11 Thread Stefan Behnel
Stefan Behnel added the comment: Benjamin, I hadn't noticed that you also changed the documentation in dict.rst from what I originall wrote. Ezio already fixed one of your typos, but there's another one in the description of the "defaultobj" behaviour: it says "inserted" twice but should say "

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

2013-03-08 Thread Roundup Robot
Roundup Robot added the comment: New changeset ca9a85c36e09 by Benjamin Peterson in branch 'default': fix warning (closes #17327) http://hg.python.org/cpython/rev/ca9a85c36e09 -- resolution: -> fixed status: open -> closed ___ Python tracker

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

2013-03-07 Thread Stefan Behnel
Stefan Behnel added the comment: I'm totally ok with your changes, though. The only real difference is an aditional type check in the slot function path, and that's not going to make any difference right after the costly operation of unpacking python function arguments. -- __

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

2013-03-07 Thread Stefan Behnel
Stefan Behnel added the comment: If you decide to refactor a well tested patch, you might want to give it another test run before committing it. Objects/dictobject.c: In function 'dict_setdefault': Objects/dictobject.c:2266:5: warning: passing argument 1 of 'PyDict_SetDefault' from incompatibl

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

2013-03-07 Thread Roundup Robot
Roundup Robot added the comment: New changeset a0b750ea3397 by Benjamin Peterson in branch 'default': Add PyDict_SetDefault. (closes #17327) http://hg.python.org/cpython/rev/a0b750ea3397 -- nosy: +python-dev resolution: -> fixed stage: -> committed/rejected status: open -> closed

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

2013-03-07 Thread Stefan Behnel
Stefan Behnel added the comment: Ok (shrug), since everyone seems to agree, PyDict_SetDefault() it is. I wouldn't be surprised if the same kind of discussion lead to the original naming of dict.setdefault()... -- Added file: http://bugs.python.org/file29345/pydict_setitemdefault.patch

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

2013-03-07 Thread Raymond Hettinger
Raymond Hettinger added the comment: +1 for PyDict_SetDefault. Any other name is confusing. -- ___ Python tracker ___ ___ Python-bugs

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

2013-03-07 Thread Stefan Behnel
Stefan Behnel added the comment: I'm fine with PyDict_GetItemOrSetDefault() as well. -- ___ Python tracker ___ ___ Python-bugs-list ma

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

2013-03-07 Thread Benjamin Peterson
Benjamin Peterson added the comment: I find the name PyDict_GetItemSetDefault very confusing. My brain isn't quite sure where to partition the four words of GetItemSetDefault. If you really wanted to be clear, you would have to call it PyDict_GetItemAndSetDefault. There's no reason not to pick

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

2013-03-07 Thread Stefan Behnel
Stefan Behnel added the comment: To me, PyDict_SetDefault() sounds like it's supposed to set a default value that PyDict_GetItem() would return instead of NULL on lookup failure. Basically a defaultdict-like extension to normal dicts. -- ___ Python

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

2013-03-07 Thread Antoine Pitrou
Antoine Pitrou added the comment: I would simply call it PyDict_SetDefault, too. It's also shorter to type ;) -- nosy: +pitrou ___ Python tracker ___

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

2013-03-07 Thread Stefan Behnel
Stefan Behnel added the comment: Well, guess what, I kind-of figured that. So, what's wrong with PyDict_GetItemSetDefault()? That mimics the Python method name, too, while at the same time making it clear what actually happens and how the C-API function behaves. -- __

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

2013-03-07 Thread Benjamin Peterson
Benjamin Peterson added the comment: PyDict_SetDefault mimicks the Python API, though. -- ___ Python tracker ___ ___ Python-bugs-list

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

2013-03-07 Thread Stefan Behnel
Stefan Behnel added the comment: I had originally considered that name. However, what it really does is PyDict_GetItem(). In a specific special case, it sets a default value and *then* returns that. So it's still PyDict_GetItem(), just with a preceding modification. Also, the interface mimics

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

2013-03-07 Thread Benjamin Peterson
Benjamin Peterson added the comment: Please call it PyDict_SetDefault, though. -- nosy: +benjamin.peterson ___ Python tracker ___ ___

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

2013-03-07 Thread Stefan Behnel
Stefan Behnel added the comment: The problem with 'default' is that it is a reserved word in C. I changed it to "defaultobj", except for the docs page, where "default" should work. I also removed the "register" declaration from the "mp" argument because it is most likely useless and just takes

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

2013-03-07 Thread Raymond Hettinger
Raymond Hettinger added the comment: +1 for the idea. Please change "failobj" to "default" to keep the terminology consistent with the pure Python API. For reference, here's the code from collections.MutableMapping: def setdefault(self, key, default=None): try: return

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

2013-03-01 Thread Stefan Behnel
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 PyD