diff options
author | Benjamin Peterson <benjamin@python.org> | 2014-02-16 18:49:16 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2014-02-16 18:49:16 (GMT) |
commit | e686c5c3e81526d93043cc15062dd8289b2c65ee (patch) | |
tree | 1d64a213cf4ec4a15489c30b38a9ce2643650c21 /Objects | |
parent | 1bcfbd5107c4160a77bc9a02446694ea679e570c (diff) | |
download | cpython-e686c5c3e81526d93043cc15062dd8289b2c65ee.zip cpython-e686c5c3e81526d93043cc15062dd8289b2c65ee.tar.gz cpython-e686c5c3e81526d93043cc15062dd8289b2c65ee.tar.bz2 |
look up __getnewargs__ and __getnewargs_ex__ on the object type (#16251)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/typeobject.c | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 449b6d6..f58960d 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -3719,7 +3719,7 @@ _PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs) /* We first attempt to fetch the arguments for __new__ by calling __getnewargs_ex__ on the object. */ - getnewargs_ex = _PyObject_GetAttrId(obj, &PyId___getnewargs_ex__); + getnewargs_ex = _PyObject_LookupSpecial(obj, &PyId___getnewargs_ex__); if (getnewargs_ex != NULL) { PyObject *newargs = PyObject_CallObject(getnewargs_ex, NULL); Py_DECREF(getnewargs_ex); @@ -3766,16 +3766,13 @@ _PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs) return -1; } return 0; - } else { - if (!PyErr_ExceptionMatches(PyExc_AttributeError)) { - return -1; - } - PyErr_Clear(); + } else if (PyErr_Occurred()) { + return -1; } /* The object does not have __getnewargs_ex__ so we fallback on using __getnewargs__ instead. */ - getnewargs = _PyObject_GetAttrId(obj, &PyId___getnewargs__); + getnewargs = _PyObject_LookupSpecial(obj, &PyId___getnewargs__); if (getnewargs != NULL) { *args = PyObject_CallObject(getnewargs, NULL); Py_DECREF(getnewargs); @@ -3791,11 +3788,8 @@ _PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs) } *kwargs = NULL; return 0; - } else { - if (!PyErr_ExceptionMatches(PyExc_AttributeError)) { - return -1; - } - PyErr_Clear(); + } else if (PyErr_Occurred()) { + return -1; } /* The object does not have __getnewargs_ex__ and __getnewargs__. This may |