Stefan Behnel, 23.02.2010 13:29: > Dag Sverre Seljebotn, 23.02.2010 12:30: >> Stefan Behnel wrote: >>> cdef dict d = ... >>> try: >>> item = d['test'] >>> except KeyError: >>> item = d['test'] = some_value >> How about just optimizing "d.get(key[, default])" if it isn't already >> for this case, and document that [] is slower? > > Very good idea. I'll do that.
... and it obviously suffers from the same problem that Robert described: if the object is not hashable, it silently swallows the exception. Now, Python 3.x has a new PyDict_GetItemWithError() function that gives us exactly what we want. So my proposal is to not duplicate any implementation details from CPython (again!), but instead provide the speedup only for CPython 3.x. Stefan _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
