Mercurial > cpython-lru_cache-weakref
diff Objects/classobject.c @ 27612:0729f8393b16 2.2
backport:
revision 2.164
date: 2002/10/29 18:36:40; author: gvanrossum; state: Exp; lines: +12 -13
Since properties are supported here, is possible that
instance_getattr2() raises an exception. Fix all code that made this
assumption.
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Sun, 02 Feb 2003 19:37:32 +0000 |
| parents | 09e3f0d8be10 |
| children | 5fa8344d6e6f |
line wrap: on
line diff
--- a/Objects/classobject.c Sun Feb 02 19:34:40 2003 +0000 +++ b/Objects/classobject.c Sun Feb 02 19:37:32 2003 +0000 @@ -543,6 +543,10 @@ initstr = PyString_InternFromString("__init__"); init = instance_getattr2(inst, initstr); if (init == NULL) { + if (PyErr_Occurred()) { + Py_DECREF(inst); + return NULL; + } if ((arg != NULL && (!PyTuple_Check(arg) || PyTuple_Size(arg) != 0)) || (kw != NULL && (!PyDict_Check(kw) || @@ -674,7 +678,7 @@ } } v = instance_getattr2(inst, name); - if (v == NULL) { + if (v == NULL && !PyErr_Occurred()) { PyErr_Format(PyExc_AttributeError, "%.50s instance has no attribute '%.400s'", PyString_AS_STRING(inst->in_class->cl_name), sname); @@ -1759,25 +1763,20 @@ /* If the instance doesn't define an __getattr__ method, use instance_getattr2 directly because it will not set an exception on failure. */ - if (((PyInstanceObject *)v)->in_class->cl_getattr == NULL) { - method = instance_getattr2((PyInstanceObject *)v, + if (((PyInstanceObject *)v)->in_class->cl_getattr == NULL) + method = instance_getattr2((PyInstanceObject *)v, name_op[op]); - if (method == NULL) { - assert(!PyErr_Occurred()); - res = Py_NotImplemented; - Py_INCREF(res); - return res; - } - } else { + else method = PyObject_GetAttr(v, name_op[op]); - if (method == NULL) { + if (method == NULL) { + if (PyErr_Occurred()) { if (!PyErr_ExceptionMatches(PyExc_AttributeError)) return NULL; PyErr_Clear(); - res = Py_NotImplemented; - Py_INCREF(res); - return res; } + res = Py_NotImplemented; + Py_INCREF(res); + return res; } args = Py_BuildValue("(O)", w);
