diff -r 9015f502ac06 Modules/_pickle.c --- a/Modules/_pickle.c Tue Oct 21 00:16:00 2014 +0200 +++ b/Modules/_pickle.c Tue Oct 21 09:41:32 2014 +0200 @@ -1535,7 +1535,7 @@ memo_put(PicklerObject *self, PyObject * } static PyObject * -getattribute(PyObject *obj, PyObject *name, int allow_qualname) { +getattribute(PyObject *obj, PyObject *name, int allow_qualname, int detailed_exc) { PyObject *dotted_path; Py_ssize_t i; _Py_static_string(PyId_dot, "."); @@ -1547,10 +1547,13 @@ getattribute(PyObject *obj, PyObject *na } assert(Py_SIZE(dotted_path) >= 1); if (!allow_qualname && Py_SIZE(dotted_path) > 1) { - PyErr_Format(PyExc_AttributeError, - "Can't get qualified attribute %R on %R;" - "use protocols >= 4 to enable support", - name, obj); + if (!detailed_exc) + PyErr_SetNone(PyExc_AttributeError); + else + PyErr_Format(PyExc_AttributeError, + "Can't get qualified attribute %R on %R;" + "use protocols >= 4 to enable support", + name, obj); Py_DECREF(dotted_path); return NULL; } @@ -1564,8 +1567,11 @@ getattribute(PyObject *obj, PyObject *na assert(PyBool_Check(result)); Py_DECREF(result); if (is_equal) { - PyErr_Format(PyExc_AttributeError, - "Can't get local attribute %R on %R", name, obj); + if (!detailed_exc) + PyErr_SetNone(PyExc_AttributeError); + else + PyErr_Format(PyExc_AttributeError, + "Can't get local attribute %R on %R", name, obj); Py_DECREF(dotted_path); Py_DECREF(obj); return NULL; @@ -1573,7 +1579,7 @@ getattribute(PyObject *obj, PyObject *na tmp = PyObject_GetAttr(obj, subpath); Py_DECREF(obj); if (tmp == NULL) { - if (PyErr_ExceptionMatches(PyExc_AttributeError)) { + if (detailed_exc && PyErr_ExceptionMatches(PyExc_AttributeError)) { PyErr_Clear(); PyErr_Format(PyExc_AttributeError, "Can't get attribute %R on %R", name, obj); @@ -1634,7 +1640,7 @@ whichmodule(PyObject *global, PyObject * if (module == Py_None) continue; - obj = getattribute(module, global_name, allow_qualname); + obj = getattribute(module, global_name, allow_qualname, 0); if (obj == NULL) { if (!PyErr_ExceptionMatches(PyExc_AttributeError)) return NULL; @@ -3105,7 +3111,7 @@ save_global(PicklerObject *self, PyObjec obj, module_name); goto error; } - cls = getattribute(module, global_name, self->proto >= 4); + cls = getattribute(module, global_name, self->proto >= 4, 0); if (cls == NULL) { PyErr_Format(st->PicklingError, "Can't pickle %R: attribute lookup %S on %S failed", @@ -6281,11 +6287,11 @@ static PyObject * module = PyImport_Import(module_name); if (module == NULL) return NULL; - global = getattribute(module, global_name, self->proto >= 4); + global = getattribute(module, global_name, self->proto >= 4, 1); Py_DECREF(module); } else { - global = getattribute(module, global_name, self->proto >= 4); + global = getattribute(module, global_name, self->proto >= 4, 1); } return global; }