Commit 1a6b77b5 authored by Stefan Behnel's avatar Stefan Behnel

fix dict.get() fallback in Py2

parent bdfc9525
...@@ -1642,11 +1642,8 @@ static CYTHON_INLINE PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject ...@@ -1642,11 +1642,8 @@ static CYTHON_INLINE PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject
PyObject *m; PyObject *m;
m = __Pyx_GetAttrString(d, "get"); m = __Pyx_GetAttrString(d, "get");
if (!m) return NULL; if (!m) return NULL;
if (default_value == Py_None) { value = PyObject_CallFunctionObjArgs(m, key,
value = PyObject_CallFunctionObjArgs(m, key, default_value, NULL); (default_value == Py_None) ? NULL : default_value, NULL);
} else {
value = PyObject_CallFunctionObjArgs(m, key, NULL);
}
Py_DECREF(m); Py_DECREF(m);
} }
#endif #endif
......
...@@ -52,6 +52,11 @@ def get_default(dict d, key, default): ...@@ -52,6 +52,11 @@ def get_default(dict d, key, default):
>>> get_default(d, 2, 2) >>> get_default(d, 2, 2)
2 2
>>> d.get((1,2), 2)
2
>>> get_default(d, (1,2), 2)
2
>>> class Unhashable: >>> class Unhashable:
... def __hash__(self): ... def __hash__(self):
... raise ValueError ... raise ValueError
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment