[Python-Dev] Proposal: defaultdict (original) (raw)
"Martin v. Löwis" martin at v.loewis.de
Fri Feb 17 23:37:59 CET 2006
- Previous message: [Python-Dev] Proposal: defaultdict
- Next message: [Python-Dev] Proposal: defaultdict
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Guido van Rossum wrote:
I'm torn. While trying to implement this I came across some ugliness in PyDictGetItem() -- it would make sense if this also called onmissing(), but it must return a value without incrementing its refcount, and isn't supposed to raise exceptions -- so what to do if onmissing() returns a value that's not inserted in the dict?
I think there should be a guideline to use PyObject_GetItem/PyMapping_GetItemString "normally", i.e. in all cases where you would write d[k] in Python code.
It should be considered a bug if PyDict_GetItem is used in a place that "should" invoke defaulting; IOW, the function should be reserved to really low-level cases (e.g. if it is known that the dict doesn't have any defaulting, e.g. the string interned dictionary).
There should be a policy whether name-lookup invokes defaulting (i.e. dict access); I think it should. This would cause getattr to have no effect if the object's dictionary has a default factory (unless that raises a KeyError).
Regards, Martin
- Previous message: [Python-Dev] Proposal: defaultdict
- Next message: [Python-Dev] Proposal: defaultdict
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]