From: Stefan Behnel Date: Tue, 23 Feb 2010 14:43:28 +0000 (+0100) Subject: fix dict.get() fallback in Py2 X-Git-Tag: 0.13.beta0~319^2~20 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1a6b77b5dd1ebccd183183801da8a1e3c7458f3f;p=cython.git fix dict.get() fallback in Py2 --- diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py index db3397ca..8f922cb4 100644 --- a/Cython/Compiler/Optimize.py +++ b/Cython/Compiler/Optimize.py @@ -1642,11 +1642,8 @@ static CYTHON_INLINE PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject PyObject *m; m = __Pyx_GetAttrString(d, "get"); if (!m) return NULL; - if (default_value == Py_None) { - value = PyObject_CallFunctionObjArgs(m, key, default_value, NULL); - } else { - value = PyObject_CallFunctionObjArgs(m, key, NULL); - } + value = PyObject_CallFunctionObjArgs(m, key, + (default_value == Py_None) ? NULL : default_value, NULL); Py_DECREF(m); } #endif diff --git a/tests/run/dict_get.pyx b/tests/run/dict_get.pyx index 546cbe6b..f27a8137 100644 --- a/tests/run/dict_get.pyx +++ b/tests/run/dict_get.pyx @@ -52,6 +52,11 @@ def get_default(dict d, key, default): >>> get_default(d, 2, 2) 2 + >>> d.get((1,2), 2) + 2 + >>> get_default(d, (1,2), 2) + 2 + >>> class Unhashable: ... def __hash__(self): ... raise ValueError