mirror of https://github.com/python/cpython
gh-106521: Remove _PyObject_LookupAttr() function (GH-106642)
This commit is contained in:
parent
e8ab0096a5
commit
be1b968dc1
|
@ -294,7 +294,6 @@ PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *);
|
||||||
PyAPI_FUNC(int) _PyObject_IsAbstract(PyObject *);
|
PyAPI_FUNC(int) _PyObject_IsAbstract(PyObject *);
|
||||||
PyAPI_FUNC(PyObject *) _PyObject_GetAttrId(PyObject *, _Py_Identifier *);
|
PyAPI_FUNC(PyObject *) _PyObject_GetAttrId(PyObject *, _Py_Identifier *);
|
||||||
PyAPI_FUNC(int) _PyObject_SetAttrId(PyObject *, _Py_Identifier *, PyObject *);
|
PyAPI_FUNC(int) _PyObject_SetAttrId(PyObject *, _Py_Identifier *, PyObject *);
|
||||||
#define _PyObject_LookupAttr PyObject_GetOptionalAttr
|
|
||||||
|
|
||||||
PyAPI_FUNC(int) _PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method);
|
PyAPI_FUNC(int) _PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method);
|
||||||
|
|
||||||
|
|
|
@ -361,7 +361,7 @@ compute_abstract_methods(PyObject *self)
|
||||||
PyObject *item = PyTuple_GET_ITEM(bases, pos); // borrowed
|
PyObject *item = PyTuple_GET_ITEM(bases, pos); // borrowed
|
||||||
PyObject *base_abstracts, *iter;
|
PyObject *base_abstracts, *iter;
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(item, &_Py_ID(__abstractmethods__),
|
if (PyObject_GetOptionalAttr(item, &_Py_ID(__abstractmethods__),
|
||||||
&base_abstracts) < 0) {
|
&base_abstracts) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -375,7 +375,7 @@ compute_abstract_methods(PyObject *self)
|
||||||
Py_DECREF(base_abstracts);
|
Py_DECREF(base_abstracts);
|
||||||
PyObject *key, *value;
|
PyObject *key, *value;
|
||||||
while ((key = PyIter_Next(iter))) {
|
while ((key = PyIter_Next(iter))) {
|
||||||
if (_PyObject_LookupAttr(self, key, &value) < 0) {
|
if (PyObject_GetOptionalAttr(self, key, &value) < 0) {
|
||||||
Py_DECREF(key);
|
Py_DECREF(key);
|
||||||
Py_DECREF(iter);
|
Py_DECREF(iter);
|
||||||
goto error;
|
goto error;
|
||||||
|
|
|
@ -248,7 +248,7 @@ get_future_loop(asyncio_state *state, PyObject *fut)
|
||||||
return Py_NewRef(loop);
|
return Py_NewRef(loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(fut, &_Py_ID(get_loop), &getloop) < 0) {
|
if (PyObject_GetOptionalAttr(fut, &_Py_ID(get_loop), &getloop) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (getloop != NULL) {
|
if (getloop != NULL) {
|
||||||
|
@ -2966,7 +2966,7 @@ task_step_handle_result_impl(asyncio_state *state, TaskObj *task, PyObject *resu
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if `result` is a Future-compatible object */
|
/* Check if `result` is a Future-compatible object */
|
||||||
if (_PyObject_LookupAttr(result, &_Py_ID(_asyncio_future_blocking), &o) < 0) {
|
if (PyObject_GetOptionalAttr(result, &_Py_ID(_asyncio_future_blocking), &o) < 0) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (o != NULL && o != Py_None) {
|
if (o != NULL && o != Py_None) {
|
||||||
|
|
|
@ -1450,7 +1450,7 @@ csv_writer(PyObject *module, PyObject *args, PyObject *keyword_args)
|
||||||
Py_DECREF(self);
|
Py_DECREF(self);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (_PyObject_LookupAttr(output_file,
|
if (PyObject_GetOptionalAttr(output_file,
|
||||||
module_state->str_write,
|
module_state->str_write,
|
||||||
&self->write) < 0) {
|
&self->write) < 0) {
|
||||||
Py_DECREF(self);
|
Py_DECREF(self);
|
||||||
|
|
|
@ -851,7 +851,7 @@ CDataType_from_param(PyObject *type, PyObject *value)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(value, &_Py_ID(_as_parameter_), &as_parameter) < 0) {
|
if (PyObject_GetOptionalAttr(value, &_Py_ID(_as_parameter_), &as_parameter) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (as_parameter) {
|
if (as_parameter) {
|
||||||
|
@ -1495,7 +1495,7 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
stgdict = NULL;
|
stgdict = NULL;
|
||||||
type_attr = NULL;
|
type_attr = NULL;
|
||||||
|
|
||||||
if (_PyObject_LookupAttr((PyObject *)result, &_Py_ID(_length_), &length_attr) < 0) {
|
if (PyObject_GetOptionalAttr((PyObject *)result, &_Py_ID(_length_), &length_attr) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (!length_attr) {
|
if (!length_attr) {
|
||||||
|
@ -1528,7 +1528,7 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyObject_LookupAttr((PyObject *)result, &_Py_ID(_type_), &type_attr) < 0) {
|
if (PyObject_GetOptionalAttr((PyObject *)result, &_Py_ID(_type_), &type_attr) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (!type_attr) {
|
if (!type_attr) {
|
||||||
|
@ -1720,7 +1720,7 @@ c_wchar_p_from_param(PyObject *type, PyObject *value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(value, &_Py_ID(_as_parameter_), &as_parameter) < 0) {
|
if (PyObject_GetOptionalAttr(value, &_Py_ID(_as_parameter_), &as_parameter) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (as_parameter) {
|
if (as_parameter) {
|
||||||
|
@ -1784,7 +1784,7 @@ c_char_p_from_param(PyObject *type, PyObject *value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(value, &_Py_ID(_as_parameter_), &as_parameter) < 0) {
|
if (PyObject_GetOptionalAttr(value, &_Py_ID(_as_parameter_), &as_parameter) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (as_parameter) {
|
if (as_parameter) {
|
||||||
|
@ -1919,7 +1919,7 @@ c_void_p_from_param(PyObject *type, PyObject *value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(value, &_Py_ID(_as_parameter_), &as_parameter) < 0) {
|
if (PyObject_GetOptionalAttr(value, &_Py_ID(_as_parameter_), &as_parameter) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (as_parameter) {
|
if (as_parameter) {
|
||||||
|
@ -2054,7 +2054,7 @@ PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
if (result == NULL)
|
if (result == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (_PyObject_LookupAttr((PyObject *)result, &_Py_ID(_type_), &proto) < 0) {
|
if (PyObject_GetOptionalAttr((PyObject *)result, &_Py_ID(_type_), &proto) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (!proto) {
|
if (!proto) {
|
||||||
|
@ -2266,7 +2266,7 @@ PyCSimpleType_from_param(PyObject *type, PyObject *value)
|
||||||
PyObject *exc = PyErr_GetRaisedException();
|
PyObject *exc = PyErr_GetRaisedException();
|
||||||
Py_DECREF(parg);
|
Py_DECREF(parg);
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(value, &_Py_ID(_as_parameter_), &as_parameter) < 0) {
|
if (PyObject_GetOptionalAttr(value, &_Py_ID(_as_parameter_), &as_parameter) < 0) {
|
||||||
Py_XDECREF(exc);
|
Py_XDECREF(exc);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -2429,7 +2429,7 @@ converters_from_argtypes(PyObject *ob)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(tp, &_Py_ID(from_param), &cnv) <= 0) {
|
if (PyObject_GetOptionalAttr(tp, &_Py_ID(from_param), &cnv) <= 0) {
|
||||||
Py_DECREF(converters);
|
Py_DECREF(converters);
|
||||||
Py_DECREF(ob);
|
Py_DECREF(ob);
|
||||||
if (!PyErr_Occurred()) {
|
if (!PyErr_Occurred()) {
|
||||||
|
@ -2489,7 +2489,7 @@ make_funcptrtype_dict(StgDictObject *stgdict)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
stgdict->restype = Py_NewRef(ob);
|
stgdict->restype = Py_NewRef(ob);
|
||||||
if (_PyObject_LookupAttr(ob, &_Py_ID(_check_retval_),
|
if (PyObject_GetOptionalAttr(ob, &_Py_ID(_check_retval_),
|
||||||
&stgdict->checker) < 0)
|
&stgdict->checker) < 0)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -3275,7 +3275,7 @@ PyCFuncPtr_set_restype(PyCFuncPtrObject *self, PyObject *ob, void *Py_UNUSED(ign
|
||||||
"restype must be a type, a callable, or None");
|
"restype must be a type, a callable, or None");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (_PyObject_LookupAttr(ob, &_Py_ID(_check_retval_), &checker) < 0) {
|
if (PyObject_GetOptionalAttr(ob, &_Py_ID(_check_retval_), &checker) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
oldchecker = self->checker;
|
oldchecker = self->checker;
|
||||||
|
|
|
@ -727,7 +727,7 @@ static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa)
|
||||||
|
|
||||||
{
|
{
|
||||||
PyObject *arg;
|
PyObject *arg;
|
||||||
if (_PyObject_LookupAttr(obj, &_Py_ID(_as_parameter_), &arg) < 0) {
|
if (PyObject_GetOptionalAttr(obj, &_Py_ID(_as_parameter_), &arg) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/* Which types should we exactly allow here?
|
/* Which types should we exactly allow here?
|
||||||
|
|
|
@ -295,7 +295,7 @@ MakeAnonFields(PyObject *type)
|
||||||
PyObject *anon_names;
|
PyObject *anon_names;
|
||||||
Py_ssize_t i;
|
Py_ssize_t i;
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(type, &_Py_ID(_anonymous_), &anon) < 0) {
|
if (PyObject_GetOptionalAttr(type, &_Py_ID(_anonymous_), &anon) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (anon == NULL) {
|
if (anon == NULL) {
|
||||||
|
@ -385,7 +385,7 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
|
||||||
if (fields == NULL)
|
if (fields == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(type, &_Py_ID(_swappedbytes_), &tmp) < 0) {
|
if (PyObject_GetOptionalAttr(type, &_Py_ID(_swappedbytes_), &tmp) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (tmp) {
|
if (tmp) {
|
||||||
|
@ -396,7 +396,7 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
|
||||||
big_endian = PY_BIG_ENDIAN;
|
big_endian = PY_BIG_ENDIAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(type, &_Py_ID(_pack_), &tmp) < 0) {
|
if (PyObject_GetOptionalAttr(type, &_Py_ID(_pack_), &tmp) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (tmp) {
|
if (tmp) {
|
||||||
|
|
|
@ -3791,7 +3791,7 @@ tzinfo_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||||
PyObject *args, *state;
|
PyObject *args, *state;
|
||||||
PyObject *getinitargs;
|
PyObject *getinitargs;
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(self, &_Py_ID(__getinitargs__), &getinitargs) < 0) {
|
if (PyObject_GetOptionalAttr(self, &_Py_ID(__getinitargs__), &getinitargs) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (getinitargs != NULL) {
|
if (getinitargs != NULL) {
|
||||||
|
|
|
@ -3530,7 +3530,7 @@ expat_start_doctype_handler(XMLParserObject *self,
|
||||||
sysid_obj, NULL);
|
sysid_obj, NULL);
|
||||||
Py_XDECREF(res);
|
Py_XDECREF(res);
|
||||||
}
|
}
|
||||||
else if (_PyObject_LookupAttr((PyObject *)self, st->str_doctype, &res) > 0) {
|
else if (PyObject_GetOptionalAttr((PyObject *)self, st->str_doctype, &res) > 0) {
|
||||||
(void)PyErr_WarnEx(PyExc_RuntimeWarning,
|
(void)PyErr_WarnEx(PyExc_RuntimeWarning,
|
||||||
"The doctype() method of XMLParser is ignored. "
|
"The doctype() method of XMLParser is ignored. "
|
||||||
"Define doctype() method on the TreeBuilder target.",
|
"Define doctype() method on the TreeBuilder target.",
|
||||||
|
|
|
@ -1463,7 +1463,7 @@ buffered_repr(buffered *self)
|
||||||
{
|
{
|
||||||
PyObject *nameobj, *res;
|
PyObject *nameobj, *res;
|
||||||
|
|
||||||
if (_PyObject_LookupAttr((PyObject *) self, &_Py_ID(name), &nameobj) < 0) {
|
if (PyObject_GetOptionalAttr((PyObject *) self, &_Py_ID(name), &nameobj) < 0) {
|
||||||
if (!PyErr_ExceptionMatches(PyExc_ValueError)) {
|
if (!PyErr_ExceptionMatches(PyExc_ValueError)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1630,7 +1630,7 @@ _bufferedreader_read_all(buffered *self)
|
||||||
}
|
}
|
||||||
_bufferedreader_reset_buf(self);
|
_bufferedreader_reset_buf(self);
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(self->raw, &_Py_ID(readall), &readall) < 0) {
|
if (PyObject_GetOptionalAttr(self->raw, &_Py_ID(readall), &readall) < 0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (readall) {
|
if (readall) {
|
||||||
|
|
|
@ -1099,7 +1099,7 @@ fileio_repr(fileio *self)
|
||||||
if (self->fd < 0)
|
if (self->fd < 0)
|
||||||
return PyUnicode_FromFormat("<_io.FileIO [closed]>");
|
return PyUnicode_FromFormat("<_io.FileIO [closed]>");
|
||||||
|
|
||||||
if (_PyObject_LookupAttr((PyObject *) self, &_Py_ID(name), &nameobj) < 0) {
|
if (PyObject_GetOptionalAttr((PyObject *) self, &_Py_ID(name), &nameobj) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (nameobj == NULL) {
|
if (nameobj == NULL) {
|
||||||
|
|
|
@ -148,7 +148,7 @@ iobase_is_closed(PyObject *self)
|
||||||
int ret;
|
int ret;
|
||||||
/* This gets the derived attribute, which is *not* __IOBase_closed
|
/* This gets the derived attribute, which is *not* __IOBase_closed
|
||||||
in most cases! */
|
in most cases! */
|
||||||
ret = _PyObject_LookupAttr(self, &_Py_ID(__IOBase_closed), &res);
|
ret = PyObject_GetOptionalAttr(self, &_Py_ID(__IOBase_closed), &res);
|
||||||
Py_XDECREF(res);
|
Py_XDECREF(res);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ iobase_check_closed(PyObject *self)
|
||||||
int closed;
|
int closed;
|
||||||
/* This gets the derived attribute, which is *not* __IOBase_closed
|
/* This gets the derived attribute, which is *not* __IOBase_closed
|
||||||
in most cases! */
|
in most cases! */
|
||||||
closed = _PyObject_LookupAttr(self, &_Py_ID(closed), &res);
|
closed = PyObject_GetOptionalAttr(self, &_Py_ID(closed), &res);
|
||||||
if (closed > 0) {
|
if (closed > 0) {
|
||||||
closed = PyObject_IsTrue(res);
|
closed = PyObject_IsTrue(res);
|
||||||
Py_DECREF(res);
|
Py_DECREF(res);
|
||||||
|
@ -303,7 +303,7 @@ iobase_finalize(PyObject *self)
|
||||||
|
|
||||||
/* If `closed` doesn't exist or can't be evaluated as bool, then the
|
/* If `closed` doesn't exist or can't be evaluated as bool, then the
|
||||||
object is probably in an unusable state, so ignore. */
|
object is probably in an unusable state, so ignore. */
|
||||||
if (_PyObject_LookupAttr(self, &_Py_ID(closed), &res) <= 0) {
|
if (PyObject_GetOptionalAttr(self, &_Py_ID(closed), &res) <= 0) {
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
closed = -1;
|
closed = -1;
|
||||||
}
|
}
|
||||||
|
@ -571,7 +571,7 @@ _io__IOBase_readline_impl(PyObject *self, Py_ssize_t limit)
|
||||||
PyObject *peek, *buffer, *result;
|
PyObject *peek, *buffer, *result;
|
||||||
Py_ssize_t old_size = -1;
|
Py_ssize_t old_size = -1;
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(self, &_Py_ID(peek), &peek) < 0) {
|
if (PyObject_GetOptionalAttr(self, &_Py_ID(peek), &peek) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -946,7 +946,7 @@ _textiowrapper_set_encoder(textio *self, PyObject *codec_info,
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Get the normalized named of the codec */
|
/* Get the normalized named of the codec */
|
||||||
if (_PyObject_LookupAttr(codec_info, &_Py_ID(name), &res) < 0) {
|
if (PyObject_GetOptionalAttr(codec_info, &_Py_ID(name), &res) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (res != NULL && PyUnicode_Check(res)) {
|
if (res != NULL && PyUnicode_Check(res)) {
|
||||||
|
@ -1202,7 +1202,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
|
||||||
Py_IS_TYPE(buffer, state->PyBufferedWriter_Type) ||
|
Py_IS_TYPE(buffer, state->PyBufferedWriter_Type) ||
|
||||||
Py_IS_TYPE(buffer, state->PyBufferedRandom_Type))
|
Py_IS_TYPE(buffer, state->PyBufferedRandom_Type))
|
||||||
{
|
{
|
||||||
if (_PyObject_LookupAttr(buffer, &_Py_ID(raw), &raw) < 0)
|
if (PyObject_GetOptionalAttr(buffer, &_Py_ID(raw), &raw) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
/* Cache the raw FileIO object to speed up 'closed' checks */
|
/* Cache the raw FileIO object to speed up 'closed' checks */
|
||||||
if (raw != NULL) {
|
if (raw != NULL) {
|
||||||
|
@ -1222,7 +1222,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
|
||||||
goto error;
|
goto error;
|
||||||
self->seekable = self->telling = r;
|
self->seekable = self->telling = r;
|
||||||
|
|
||||||
r = _PyObject_LookupAttr(buffer, &_Py_ID(read1), &res);
|
r = PyObject_GetOptionalAttr(buffer, &_Py_ID(read1), &res);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -2897,7 +2897,7 @@ textiowrapper_repr(textio *self)
|
||||||
}
|
}
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (_PyObject_LookupAttr((PyObject *) self, &_Py_ID(name), &nameobj) < 0) {
|
if (PyObject_GetOptionalAttr((PyObject *) self, &_Py_ID(name), &nameobj) < 0) {
|
||||||
if (!PyErr_ExceptionMatches(PyExc_ValueError)) {
|
if (!PyErr_ExceptionMatches(PyExc_ValueError)) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -2913,7 +2913,7 @@ textiowrapper_repr(textio *self)
|
||||||
if (res == NULL)
|
if (res == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (_PyObject_LookupAttr((PyObject *) self, &_Py_ID(mode), &modeobj) < 0) {
|
if (PyObject_GetOptionalAttr((PyObject *) self, &_Py_ID(mode), &modeobj) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (modeobj != NULL) {
|
if (modeobj != NULL) {
|
||||||
|
@ -3130,7 +3130,7 @@ textiowrapper_newlines_get(textio *self, void *context)
|
||||||
PyObject *res;
|
PyObject *res;
|
||||||
CHECK_ATTACHED(self);
|
CHECK_ATTACHED(self);
|
||||||
if (self->decoder == NULL ||
|
if (self->decoder == NULL ||
|
||||||
_PyObject_LookupAttr(self->decoder, &_Py_ID(newlines), &res) == 0)
|
PyObject_GetOptionalAttr(self->decoder, &_Py_ID(newlines), &res) == 0)
|
||||||
{
|
{
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -406,7 +406,7 @@ init_method_ref(PyObject *self, PyObject *name,
|
||||||
|
|
||||||
/* *method_func and *method_self should be consistent. All refcount decrements
|
/* *method_func and *method_self should be consistent. All refcount decrements
|
||||||
should be occurred after setting *method_self and *method_func. */
|
should be occurred after setting *method_self and *method_func. */
|
||||||
ret = _PyObject_LookupAttr(self, name, &func);
|
ret = PyObject_GetOptionalAttr(self, name, &func);
|
||||||
if (func == NULL) {
|
if (func == NULL) {
|
||||||
*method_self = NULL;
|
*method_self = NULL;
|
||||||
Py_CLEAR(*method_func);
|
Py_CLEAR(*method_func);
|
||||||
|
@ -1224,7 +1224,7 @@ static int
|
||||||
_Pickler_SetOutputStream(PicklerObject *self, PyObject *file)
|
_Pickler_SetOutputStream(PicklerObject *self, PyObject *file)
|
||||||
{
|
{
|
||||||
assert(file != NULL);
|
assert(file != NULL);
|
||||||
if (_PyObject_LookupAttr(file, &_Py_ID(write), &self->write) < 0) {
|
if (PyObject_GetOptionalAttr(file, &_Py_ID(write), &self->write) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (self->write == NULL) {
|
if (self->write == NULL) {
|
||||||
|
@ -1694,16 +1694,16 @@ static int
|
||||||
_Unpickler_SetInputStream(UnpicklerObject *self, PyObject *file)
|
_Unpickler_SetInputStream(UnpicklerObject *self, PyObject *file)
|
||||||
{
|
{
|
||||||
/* Optional file methods */
|
/* Optional file methods */
|
||||||
if (_PyObject_LookupAttr(file, &_Py_ID(peek), &self->peek) < 0) {
|
if (PyObject_GetOptionalAttr(file, &_Py_ID(peek), &self->peek) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (_PyObject_LookupAttr(file, &_Py_ID(readinto), &self->readinto) < 0) {
|
if (PyObject_GetOptionalAttr(file, &_Py_ID(readinto), &self->readinto) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (_PyObject_LookupAttr(file, &_Py_ID(read), &self->read) < 0) {
|
if (PyObject_GetOptionalAttr(file, &_Py_ID(read), &self->read) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (_PyObject_LookupAttr(file, &_Py_ID(readline), &self->readline) < 0) {
|
if (PyObject_GetOptionalAttr(file, &_Py_ID(readline), &self->readline) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (!self->readline || !self->read) {
|
if (!self->readline || !self->read) {
|
||||||
|
@ -1900,7 +1900,7 @@ get_deep_attribute(PyObject *obj, PyObject *names, PyObject **pparent)
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
PyObject *name = PyList_GET_ITEM(names, i);
|
PyObject *name = PyList_GET_ITEM(names, i);
|
||||||
Py_XSETREF(parent, obj);
|
Py_XSETREF(parent, obj);
|
||||||
(void)_PyObject_LookupAttr(parent, name, &obj);
|
(void)PyObject_GetOptionalAttr(parent, name, &obj);
|
||||||
if (obj == NULL) {
|
if (obj == NULL) {
|
||||||
Py_DECREF(parent);
|
Py_DECREF(parent);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1927,7 +1927,7 @@ getattribute(PyObject *obj, PyObject *name, int allow_qualname)
|
||||||
Py_DECREF(dotted_path);
|
Py_DECREF(dotted_path);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
(void)_PyObject_LookupAttr(obj, name, &attr);
|
(void)PyObject_GetOptionalAttr(obj, name, &attr);
|
||||||
}
|
}
|
||||||
if (attr == NULL && !PyErr_Occurred()) {
|
if (attr == NULL && !PyErr_Occurred()) {
|
||||||
PyErr_Format(PyExc_AttributeError,
|
PyErr_Format(PyExc_AttributeError,
|
||||||
|
@ -1968,7 +1968,7 @@ whichmodule(PyObject *global, PyObject *dotted_path)
|
||||||
Py_ssize_t i;
|
Py_ssize_t i;
|
||||||
PyObject *modules;
|
PyObject *modules;
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(global, &_Py_ID(__module__), &module_name) < 0) {
|
if (PyObject_GetOptionalAttr(global, &_Py_ID(__module__), &module_name) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (module_name) {
|
if (module_name) {
|
||||||
|
@ -3656,7 +3656,7 @@ save_global(PickleState *st, PicklerObject *self, PyObject *obj,
|
||||||
global_name = Py_NewRef(name);
|
global_name = Py_NewRef(name);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (_PyObject_LookupAttr(obj, &_Py_ID(__qualname__), &global_name) < 0)
|
if (PyObject_GetOptionalAttr(obj, &_Py_ID(__qualname__), &global_name) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
if (global_name == NULL) {
|
if (global_name == NULL) {
|
||||||
global_name = PyObject_GetAttr(obj, &_Py_ID(__name__));
|
global_name = PyObject_GetAttr(obj, &_Py_ID(__name__));
|
||||||
|
@ -3979,7 +3979,7 @@ get_class(PyObject *obj)
|
||||||
{
|
{
|
||||||
PyObject *cls;
|
PyObject *cls;
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(obj, &_Py_ID(__class__), &cls) == 0) {
|
if (PyObject_GetOptionalAttr(obj, &_Py_ID(__class__), &cls) == 0) {
|
||||||
cls = Py_NewRef(Py_TYPE(obj));
|
cls = Py_NewRef(Py_TYPE(obj));
|
||||||
}
|
}
|
||||||
return cls;
|
return cls;
|
||||||
|
@ -4062,7 +4062,7 @@ save_reduce(PickleState *st, PicklerObject *self, PyObject *args,
|
||||||
if (self->proto >= 2) {
|
if (self->proto >= 2) {
|
||||||
PyObject *name;
|
PyObject *name;
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(callable, &_Py_ID(__name__), &name) < 0) {
|
if (PyObject_GetOptionalAttr(callable, &_Py_ID(__name__), &name) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (name != NULL && PyUnicode_Check(name)) {
|
if (name != NULL && PyUnicode_Check(name)) {
|
||||||
|
@ -4462,7 +4462,7 @@ save(PickleState *st, PicklerObject *self, PyObject *obj, int pers_save)
|
||||||
don't actually have to check for a __reduce__ method. */
|
don't actually have to check for a __reduce__ method. */
|
||||||
|
|
||||||
/* Check for a __reduce_ex__ method. */
|
/* Check for a __reduce_ex__ method. */
|
||||||
if (_PyObject_LookupAttr(obj, &_Py_ID(__reduce_ex__), &reduce_func) < 0) {
|
if (PyObject_GetOptionalAttr(obj, &_Py_ID(__reduce_ex__), &reduce_func) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (reduce_func != NULL) {
|
if (reduce_func != NULL) {
|
||||||
|
@ -4474,7 +4474,7 @@ save(PickleState *st, PicklerObject *self, PyObject *obj, int pers_save)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Check for a __reduce__ method. */
|
/* Check for a __reduce__ method. */
|
||||||
if (_PyObject_LookupAttr(obj, &_Py_ID(__reduce__), &reduce_func) < 0) {
|
if (PyObject_GetOptionalAttr(obj, &_Py_ID(__reduce__), &reduce_func) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (reduce_func != NULL) {
|
if (reduce_func != NULL) {
|
||||||
|
@ -4526,7 +4526,7 @@ dump(PickleState *state, PicklerObject *self, PyObject *obj)
|
||||||
int status = -1;
|
int status = -1;
|
||||||
PyObject *tmp;
|
PyObject *tmp;
|
||||||
|
|
||||||
if (_PyObject_LookupAttr((PyObject *)self, &_Py_ID(reducer_override),
|
if (PyObject_GetOptionalAttr((PyObject *)self, &_Py_ID(reducer_override),
|
||||||
&tmp) < 0) {
|
&tmp) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -4796,7 +4796,7 @@ _pickle_Pickler___init___impl(PicklerObject *self, PyObject *file,
|
||||||
if (self->dispatch_table != NULL) {
|
if (self->dispatch_table != NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (_PyObject_LookupAttr((PyObject *)self, &_Py_ID(dispatch_table),
|
if (PyObject_GetOptionalAttr((PyObject *)self, &_Py_ID(dispatch_table),
|
||||||
&self->dispatch_table) < 0) {
|
&self->dispatch_table) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -5797,7 +5797,7 @@ instantiate(PyObject *cls, PyObject *args)
|
||||||
assert(PyTuple_Check(args));
|
assert(PyTuple_Check(args));
|
||||||
if (!PyTuple_GET_SIZE(args) && PyType_Check(cls)) {
|
if (!PyTuple_GET_SIZE(args) && PyType_Check(cls)) {
|
||||||
PyObject *func;
|
PyObject *func;
|
||||||
if (_PyObject_LookupAttr(cls, &_Py_ID(__getinitargs__), &func) < 0) {
|
if (PyObject_GetOptionalAttr(cls, &_Py_ID(__getinitargs__), &func) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (func == NULL) {
|
if (func == NULL) {
|
||||||
|
@ -6451,7 +6451,7 @@ do_append(PickleState *state, UnpicklerObject *self, Py_ssize_t x)
|
||||||
else {
|
else {
|
||||||
PyObject *extend_func;
|
PyObject *extend_func;
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(list, &_Py_ID(extend), &extend_func) < 0) {
|
if (PyObject_GetOptionalAttr(list, &_Py_ID(extend), &extend_func) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (extend_func != NULL) {
|
if (extend_func != NULL) {
|
||||||
|
@ -6637,7 +6637,7 @@ load_build(PickleState *st, UnpicklerObject *self)
|
||||||
|
|
||||||
inst = self->stack->data[Py_SIZE(self->stack) - 1];
|
inst = self->stack->data[Py_SIZE(self->stack) - 1];
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(inst, &_Py_ID(__setstate__), &setstate) < 0) {
|
if (PyObject_GetOptionalAttr(inst, &_Py_ID(__setstate__), &setstate) < 0) {
|
||||||
Py_DECREF(state);
|
Py_DECREF(state);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ pysqlite_microprotocols_adapt(pysqlite_state *state, PyObject *obj,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* try to have the protocol adapt this object */
|
/* try to have the protocol adapt this object */
|
||||||
if (_PyObject_LookupAttr(proto, state->str___adapt__, &adapter) < 0) {
|
if (PyObject_GetOptionalAttr(proto, state->str___adapt__, &adapter) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (adapter) {
|
if (adapter) {
|
||||||
|
@ -117,7 +117,7 @@ pysqlite_microprotocols_adapt(pysqlite_state *state, PyObject *obj,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* and finally try to have the object adapt itself */
|
/* and finally try to have the object adapt itself */
|
||||||
if (_PyObject_LookupAttr(obj, state->str___conform__, &adapter) < 0) {
|
if (PyObject_GetOptionalAttr(obj, state->str___conform__, &adapter) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (adapter) {
|
if (adapter) {
|
||||||
|
|
|
@ -1438,7 +1438,7 @@ thread_excepthook_file(PyObject *file, PyObject *exc_type, PyObject *exc_value,
|
||||||
|
|
||||||
PyObject *name = NULL;
|
PyObject *name = NULL;
|
||||||
if (thread != Py_None) {
|
if (thread != Py_None) {
|
||||||
if (_PyObject_LookupAttr(thread, &_Py_ID(name), &name) < 0) {
|
if (PyObject_GetOptionalAttr(thread, &_Py_ID(name), &name) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2268,7 +2268,7 @@ array_array___reduce_ex___impl(arrayobject *self, PyTypeObject *cls,
|
||||||
if (protocol == -1 && PyErr_Occurred())
|
if (protocol == -1 && PyErr_Occurred())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (_PyObject_LookupAttr((PyObject *)self, state->str___dict__, &dict) < 0) {
|
if (PyObject_GetOptionalAttr((PyObject *)self, state->str___dict__, &dict) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (dict == NULL) {
|
if (dict == NULL) {
|
||||||
|
|
|
@ -1146,7 +1146,7 @@ itertools_tee_impl(PyObject *module, PyObject *iterable, Py_ssize_t n)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(it, &_Py_ID(__copy__), ©func) < 0) {
|
if (PyObject_GetOptionalAttr(it, &_Py_ID(__copy__), ©func) < 0) {
|
||||||
Py_DECREF(it);
|
Py_DECREF(it);
|
||||||
Py_DECREF(result);
|
Py_DECREF(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -832,7 +832,7 @@ pyexpat_xmlparser_ParseFile_impl(xmlparseobject *self, PyTypeObject *cls,
|
||||||
|
|
||||||
pyexpat_state *state = PyType_GetModuleState(cls);
|
pyexpat_state *state = PyType_GetModuleState(cls);
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(file, state->str_read, &readmethod) < 0) {
|
if (PyObject_GetOptionalAttr(file, state->str_read, &readmethod) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (readmethod == NULL) {
|
if (readmethod == NULL) {
|
||||||
|
|
|
@ -182,7 +182,7 @@ PyObject_GetItem(PyObject *o, PyObject *key)
|
||||||
return Py_GenericAlias(o, key);
|
return Py_GenericAlias(o, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(o, &_Py_ID(__class_getitem__), &meth) < 0) {
|
if (PyObject_GetOptionalAttr(o, &_Py_ID(__class_getitem__), &meth) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (meth && meth != Py_None) {
|
if (meth && meth != Py_None) {
|
||||||
|
@ -2552,7 +2552,7 @@ abstract_get_bases(PyObject *cls)
|
||||||
{
|
{
|
||||||
PyObject *bases;
|
PyObject *bases;
|
||||||
|
|
||||||
(void)_PyObject_LookupAttr(cls, &_Py_ID(__bases__), &bases);
|
(void)PyObject_GetOptionalAttr(cls, &_Py_ID(__bases__), &bases);
|
||||||
if (bases != NULL && !PyTuple_Check(bases)) {
|
if (bases != NULL && !PyTuple_Check(bases)) {
|
||||||
Py_DECREF(bases);
|
Py_DECREF(bases);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -2636,7 +2636,7 @@ object_isinstance(PyObject *inst, PyObject *cls)
|
||||||
if (PyType_Check(cls)) {
|
if (PyType_Check(cls)) {
|
||||||
retval = PyObject_TypeCheck(inst, (PyTypeObject *)cls);
|
retval = PyObject_TypeCheck(inst, (PyTypeObject *)cls);
|
||||||
if (retval == 0) {
|
if (retval == 0) {
|
||||||
retval = _PyObject_LookupAttr(inst, &_Py_ID(__class__), &icls);
|
retval = PyObject_GetOptionalAttr(inst, &_Py_ID(__class__), &icls);
|
||||||
if (icls != NULL) {
|
if (icls != NULL) {
|
||||||
if (icls != (PyObject *)(Py_TYPE(inst)) && PyType_Check(icls)) {
|
if (icls != (PyObject *)(Py_TYPE(inst)) && PyType_Check(icls)) {
|
||||||
retval = PyType_IsSubtype(
|
retval = PyType_IsSubtype(
|
||||||
|
@ -2654,7 +2654,7 @@ object_isinstance(PyObject *inst, PyObject *cls)
|
||||||
if (!check_class(cls,
|
if (!check_class(cls,
|
||||||
"isinstance() arg 2 must be a type, a tuple of types, or a union"))
|
"isinstance() arg 2 must be a type, a tuple of types, or a union"))
|
||||||
return -1;
|
return -1;
|
||||||
retval = _PyObject_LookupAttr(inst, &_Py_ID(__class__), &icls);
|
retval = PyObject_GetOptionalAttr(inst, &_Py_ID(__class__), &icls);
|
||||||
if (icls != NULL) {
|
if (icls != NULL) {
|
||||||
retval = abstract_issubclass(icls, cls);
|
retval = abstract_issubclass(icls, cls);
|
||||||
Py_DECREF(icls);
|
Py_DECREF(icls);
|
||||||
|
|
|
@ -173,7 +173,7 @@ object_is_not_callable(PyThreadState *tstate, PyObject *callable)
|
||||||
goto basic_type_error;
|
goto basic_type_error;
|
||||||
}
|
}
|
||||||
PyObject *attr;
|
PyObject *attr;
|
||||||
int res = _PyObject_LookupAttr(callable, name, &attr);
|
int res = PyObject_GetOptionalAttr(callable, name, &attr);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
_PyErr_Clear(tstate);
|
_PyErr_Clear(tstate);
|
||||||
}
|
}
|
||||||
|
|
|
@ -275,9 +275,9 @@ method_repr(PyMethodObject *a)
|
||||||
PyObject *funcname, *result;
|
PyObject *funcname, *result;
|
||||||
const char *defname = "?";
|
const char *defname = "?";
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(func, &_Py_ID(__qualname__), &funcname) < 0 ||
|
if (PyObject_GetOptionalAttr(func, &_Py_ID(__qualname__), &funcname) < 0 ||
|
||||||
(funcname == NULL &&
|
(funcname == NULL &&
|
||||||
_PyObject_LookupAttr(func, &_Py_ID(__name__), &funcname) < 0))
|
PyObject_GetOptionalAttr(func, &_Py_ID(__name__), &funcname) < 0))
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -479,7 +479,7 @@ instancemethod_repr(PyObject *self)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(func, &_Py_ID(__name__), &funcname) < 0) {
|
if (PyObject_GetOptionalAttr(func, &_Py_ID(__name__), &funcname) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (funcname != NULL && !PyUnicode_Check(funcname)) {
|
if (funcname != NULL && !PyUnicode_Check(funcname)) {
|
||||||
|
|
|
@ -1792,7 +1792,7 @@ property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset,
|
||||||
}
|
}
|
||||||
/* if no docstring given and the getter has one, use that one */
|
/* if no docstring given and the getter has one, use that one */
|
||||||
else if (fget != NULL) {
|
else if (fget != NULL) {
|
||||||
int rc = _PyObject_LookupAttr(fget, &_Py_ID(__doc__), &prop_doc);
|
int rc = PyObject_GetOptionalAttr(fget, &_Py_ID(__doc__), &prop_doc);
|
||||||
if (rc <= 0) {
|
if (rc <= 0) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2664,7 +2664,7 @@ dict_update_arg(PyObject *self, PyObject *arg)
|
||||||
return PyDict_Merge(self, arg, 1);
|
return PyDict_Merge(self, arg, 1);
|
||||||
}
|
}
|
||||||
PyObject *func;
|
PyObject *func;
|
||||||
if (_PyObject_LookupAttr(arg, &_Py_ID(keys), &func) < 0) {
|
if (PyObject_GetOptionalAttr(arg, &_Py_ID(keys), &func) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (func != NULL) {
|
if (func != NULL) {
|
||||||
|
|
|
@ -208,7 +208,7 @@ BaseException_add_note(PyObject *self, PyObject *note)
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *notes;
|
PyObject *notes;
|
||||||
if (_PyObject_LookupAttr(self, &_Py_ID(__notes__), ¬es) < 0) {
|
if (PyObject_GetOptionalAttr(self, &_Py_ID(__notes__), ¬es) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (notes == NULL) {
|
if (notes == NULL) {
|
||||||
|
@ -941,7 +941,7 @@ exceptiongroup_subset(
|
||||||
PyException_SetCause(eg, PyException_GetCause(orig));
|
PyException_SetCause(eg, PyException_GetCause(orig));
|
||||||
|
|
||||||
PyObject *notes;
|
PyObject *notes;
|
||||||
if (_PyObject_LookupAttr(orig, &_Py_ID(__notes__), ¬es) < 0) {
|
if (PyObject_GetOptionalAttr(orig, &_Py_ID(__notes__), ¬es) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (notes) {
|
if (notes) {
|
||||||
|
|
|
@ -176,7 +176,7 @@ PyObject_AsFileDescriptor(PyObject *o)
|
||||||
if (PyLong_Check(o)) {
|
if (PyLong_Check(o)) {
|
||||||
fd = _PyLong_AsInt(o);
|
fd = _PyLong_AsInt(o);
|
||||||
}
|
}
|
||||||
else if (_PyObject_LookupAttr(o, &_Py_ID(fileno), &meth) < 0) {
|
else if (PyObject_GetOptionalAttr(o, &_Py_ID(fileno), &meth) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else if (meth != NULL) {
|
else if (meth != NULL) {
|
||||||
|
|
|
@ -943,7 +943,7 @@ static int
|
||||||
functools_copy_attr(PyObject *wrapper, PyObject *wrapped, PyObject *name)
|
functools_copy_attr(PyObject *wrapper, PyObject *wrapped, PyObject *name)
|
||||||
{
|
{
|
||||||
PyObject *value;
|
PyObject *value;
|
||||||
int res = _PyObject_LookupAttr(wrapped, name, &value);
|
int res = PyObject_GetOptionalAttr(wrapped, name, &value);
|
||||||
if (value != NULL) {
|
if (value != NULL) {
|
||||||
res = PyObject_SetAttr(wrapper, name, value);
|
res = PyObject_SetAttr(wrapper, name, value);
|
||||||
Py_DECREF(value);
|
Py_DECREF(value);
|
||||||
|
|
|
@ -63,12 +63,12 @@ ga_repr_item(_PyUnicodeWriter *writer, PyObject *p)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(p, &_Py_ID(__origin__), &tmp) < 0) {
|
if (PyObject_GetOptionalAttr(p, &_Py_ID(__origin__), &tmp) < 0) {
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (tmp != NULL) {
|
if (tmp != NULL) {
|
||||||
Py_DECREF(tmp);
|
Py_DECREF(tmp);
|
||||||
if (_PyObject_LookupAttr(p, &_Py_ID(__args__), &tmp) < 0) {
|
if (PyObject_GetOptionalAttr(p, &_Py_ID(__args__), &tmp) < 0) {
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (tmp != NULL) {
|
if (tmp != NULL) {
|
||||||
|
@ -78,13 +78,13 @@ ga_repr_item(_PyUnicodeWriter *writer, PyObject *p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(p, &_Py_ID(__qualname__), &qualname) < 0) {
|
if (PyObject_GetOptionalAttr(p, &_Py_ID(__qualname__), &qualname) < 0) {
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (qualname == NULL) {
|
if (qualname == NULL) {
|
||||||
goto use_repr;
|
goto use_repr;
|
||||||
}
|
}
|
||||||
if (_PyObject_LookupAttr(p, &_Py_ID(__module__), &module) < 0) {
|
if (PyObject_GetOptionalAttr(p, &_Py_ID(__module__), &module) < 0) {
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (module == NULL || module == Py_None) {
|
if (module == NULL || module == Py_None) {
|
||||||
|
@ -257,7 +257,7 @@ _Py_make_parameters(PyObject *args)
|
||||||
if (PyType_Check(t)) {
|
if (PyType_Check(t)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (_PyObject_LookupAttr(t, &_Py_ID(__typing_subst__), &subst) < 0) {
|
if (PyObject_GetOptionalAttr(t, &_Py_ID(__typing_subst__), &subst) < 0) {
|
||||||
Py_DECREF(parameters);
|
Py_DECREF(parameters);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -267,7 +267,7 @@ _Py_make_parameters(PyObject *args)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PyObject *subparams;
|
PyObject *subparams;
|
||||||
if (_PyObject_LookupAttr(t, &_Py_ID(__parameters__),
|
if (PyObject_GetOptionalAttr(t, &_Py_ID(__parameters__),
|
||||||
&subparams) < 0) {
|
&subparams) < 0) {
|
||||||
Py_DECREF(parameters);
|
Py_DECREF(parameters);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -310,7 +310,7 @@ subs_tvars(PyObject *obj, PyObject *params,
|
||||||
PyObject **argitems, Py_ssize_t nargs)
|
PyObject **argitems, Py_ssize_t nargs)
|
||||||
{
|
{
|
||||||
PyObject *subparams;
|
PyObject *subparams;
|
||||||
if (_PyObject_LookupAttr(obj, &_Py_ID(__parameters__), &subparams) < 0) {
|
if (PyObject_GetOptionalAttr(obj, &_Py_ID(__parameters__), &subparams) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (subparams && PyTuple_Check(subparams) && PyTuple_GET_SIZE(subparams)) {
|
if (subparams && PyTuple_Check(subparams) && PyTuple_GET_SIZE(subparams)) {
|
||||||
|
@ -361,7 +361,7 @@ _is_unpacked_typevartuple(PyObject *arg)
|
||||||
if (PyType_Check(arg)) { // TODO: Add test
|
if (PyType_Check(arg)) { // TODO: Add test
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int res = _PyObject_LookupAttr(arg, &_Py_ID(__typing_is_unpacked_typevartuple__), &tmp);
|
int res = PyObject_GetOptionalAttr(arg, &_Py_ID(__typing_is_unpacked_typevartuple__), &tmp);
|
||||||
if (res > 0) {
|
if (res > 0) {
|
||||||
res = PyObject_IsTrue(tmp);
|
res = PyObject_IsTrue(tmp);
|
||||||
Py_DECREF(tmp);
|
Py_DECREF(tmp);
|
||||||
|
@ -383,7 +383,7 @@ _unpacked_tuple_args(PyObject *arg)
|
||||||
return Py_NewRef(result);
|
return Py_NewRef(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(arg, &_Py_ID(__typing_unpacked_tuple_args__), &result) > 0) {
|
if (PyObject_GetOptionalAttr(arg, &_Py_ID(__typing_unpacked_tuple_args__), &result) > 0) {
|
||||||
if (result == Py_None) {
|
if (result == Py_None) {
|
||||||
Py_DECREF(result);
|
Py_DECREF(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -448,7 +448,7 @@ _Py_subs_parameters(PyObject *self, PyObject *args, PyObject *parameters, PyObje
|
||||||
for (Py_ssize_t i = 0; i < nparams; i++) {
|
for (Py_ssize_t i = 0; i < nparams; i++) {
|
||||||
PyObject *param = PyTuple_GET_ITEM(parameters, i);
|
PyObject *param = PyTuple_GET_ITEM(parameters, i);
|
||||||
PyObject *prepare, *tmp;
|
PyObject *prepare, *tmp;
|
||||||
if (_PyObject_LookupAttr(param, &_Py_ID(__typing_prepare_subst__), &prepare) < 0) {
|
if (PyObject_GetOptionalAttr(param, &_Py_ID(__typing_prepare_subst__), &prepare) < 0) {
|
||||||
Py_DECREF(item);
|
Py_DECREF(item);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -503,7 +503,7 @@ _Py_subs_parameters(PyObject *self, PyObject *args, PyObject *parameters, PyObje
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
PyObject *subst;
|
PyObject *subst;
|
||||||
if (_PyObject_LookupAttr(arg, &_Py_ID(__typing_subst__), &subst) < 0) {
|
if (PyObject_GetOptionalAttr(arg, &_Py_ID(__typing_subst__), &subst) < 0) {
|
||||||
Py_DECREF(newargs);
|
Py_DECREF(newargs);
|
||||||
Py_DECREF(item);
|
Py_DECREF(item);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -317,7 +317,7 @@ gen_close_iter(PyObject *yf)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PyObject *meth;
|
PyObject *meth;
|
||||||
if (_PyObject_LookupAttr(yf, &_Py_ID(close), &meth) < 0) {
|
if (PyObject_GetOptionalAttr(yf, &_Py_ID(close), &meth) < 0) {
|
||||||
PyErr_WriteUnraisable(yf);
|
PyErr_WriteUnraisable(yf);
|
||||||
}
|
}
|
||||||
if (meth) {
|
if (meth) {
|
||||||
|
@ -492,7 +492,7 @@ _gen_throw(PyGenObject *gen, int close_on_genexit,
|
||||||
} else {
|
} else {
|
||||||
/* `yf` is an iterator or a coroutine-like object. */
|
/* `yf` is an iterator or a coroutine-like object. */
|
||||||
PyObject *meth;
|
PyObject *meth;
|
||||||
if (_PyObject_LookupAttr(yf, &_Py_ID(throw), &meth) < 0) {
|
if (PyObject_GetOptionalAttr(yf, &_Py_ID(throw), &meth) < 0) {
|
||||||
Py_DECREF(yf);
|
Py_DECREF(yf);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -742,7 +742,7 @@ _PyModuleSpec_IsInitializing(PyObject *spec)
|
||||||
{
|
{
|
||||||
if (spec != NULL) {
|
if (spec != NULL) {
|
||||||
PyObject *value;
|
PyObject *value;
|
||||||
int ok = _PyObject_LookupAttr(spec, &_Py_ID(_initializing), &value);
|
int ok = PyObject_GetOptionalAttr(spec, &_Py_ID(_initializing), &value);
|
||||||
if (ok == 0) {
|
if (ok == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2154,7 +2154,7 @@ mutablemapping_update_arg(PyObject *self, PyObject *arg)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
PyObject *func;
|
PyObject *func;
|
||||||
if (_PyObject_LookupAttr(arg, &_Py_ID(keys), &func) < 0) {
|
if (PyObject_GetOptionalAttr(arg, &_Py_ID(keys), &func) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (func != NULL) {
|
if (func != NULL) {
|
||||||
|
@ -2186,7 +2186,7 @@ mutablemapping_update_arg(PyObject *self, PyObject *arg)
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (_PyObject_LookupAttr(arg, &_Py_ID(items), &func) < 0) {
|
if (PyObject_GetOptionalAttr(arg, &_Py_ID(items), &func) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (func != NULL) {
|
if (func != NULL) {
|
||||||
|
|
|
@ -2359,7 +2359,7 @@ static PyObject *
|
||||||
class_name(PyObject *cls)
|
class_name(PyObject *cls)
|
||||||
{
|
{
|
||||||
PyObject *name;
|
PyObject *name;
|
||||||
if (_PyObject_LookupAttr(cls, &_Py_ID(__name__), &name) == 0) {
|
if (PyObject_GetOptionalAttr(cls, &_Py_ID(__name__), &name) == 0) {
|
||||||
name = PyObject_Repr(cls);
|
name = PyObject_Repr(cls);
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
|
@ -3865,7 +3865,7 @@ type_new_get_bases(type_new_ctx *ctx, PyObject **type)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
PyObject *mro_entries;
|
PyObject *mro_entries;
|
||||||
if (_PyObject_LookupAttr(base, &_Py_ID(__mro_entries__),
|
if (PyObject_GetOptionalAttr(base, &_Py_ID(__mro_entries__),
|
||||||
&mro_entries) < 0) {
|
&mro_entries) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -5147,7 +5147,7 @@ merge_class_dict(PyObject *dict, PyObject *aclass)
|
||||||
assert(aclass);
|
assert(aclass);
|
||||||
|
|
||||||
/* Merge in the type's dict (if any). */
|
/* Merge in the type's dict (if any). */
|
||||||
if (_PyObject_LookupAttr(aclass, &_Py_ID(__dict__), &classdict) < 0) {
|
if (PyObject_GetOptionalAttr(aclass, &_Py_ID(__dict__), &classdict) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (classdict != NULL) {
|
if (classdict != NULL) {
|
||||||
|
@ -5158,7 +5158,7 @@ merge_class_dict(PyObject *dict, PyObject *aclass)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Recursively merge in the base types' (if any) dicts. */
|
/* Recursively merge in the base types' (if any) dicts. */
|
||||||
if (_PyObject_LookupAttr(aclass, &_Py_ID(__bases__), &bases) < 0) {
|
if (PyObject_GetOptionalAttr(aclass, &_Py_ID(__bases__), &bases) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (bases != NULL) {
|
if (bases != NULL) {
|
||||||
|
@ -5984,7 +5984,7 @@ object_getstate_default(PyObject *obj, int required)
|
||||||
PyObject *name, *value;
|
PyObject *name, *value;
|
||||||
|
|
||||||
name = Py_NewRef(PyList_GET_ITEM(slotnames, i));
|
name = Py_NewRef(PyList_GET_ITEM(slotnames, i));
|
||||||
if (_PyObject_LookupAttr(obj, name, &value) < 0) {
|
if (PyObject_GetOptionalAttr(obj, name, &value) < 0) {
|
||||||
Py_DECREF(name);
|
Py_DECREF(name);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -6381,7 +6381,7 @@ object___reduce_ex___impl(PyObject *self, int protocol)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(self, &_Py_ID(__reduce__), &reduce) < 0) {
|
if (PyObject_GetOptionalAttr(self, &_Py_ID(__reduce__), &reduce) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (reduce != NULL) {
|
if (reduce != NULL) {
|
||||||
|
@ -6500,7 +6500,7 @@ object___dir___impl(PyObject *self)
|
||||||
PyObject *itsclass = NULL;
|
PyObject *itsclass = NULL;
|
||||||
|
|
||||||
/* Get __dict__ (which may or may not be a real dict...) */
|
/* Get __dict__ (which may or may not be a real dict...) */
|
||||||
if (_PyObject_LookupAttr(self, &_Py_ID(__dict__), &dict) < 0) {
|
if (PyObject_GetOptionalAttr(self, &_Py_ID(__dict__), &dict) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (dict == NULL) {
|
if (dict == NULL) {
|
||||||
|
@ -6520,7 +6520,7 @@ object___dir___impl(PyObject *self)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
/* Merge in attrs reachable from its class. */
|
/* Merge in attrs reachable from its class. */
|
||||||
if (_PyObject_LookupAttr(self, &_Py_ID(__class__), &itsclass) < 0) {
|
if (PyObject_GetOptionalAttr(self, &_Py_ID(__class__), &itsclass) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
/* XXX(tomer): Perhaps fall back to Py_TYPE(obj) if no
|
/* XXX(tomer): Perhaps fall back to Py_TYPE(obj) if no
|
||||||
|
@ -8393,7 +8393,7 @@ method_is_overloaded(PyObject *left, PyObject *right, PyObject *name)
|
||||||
PyObject *a, *b;
|
PyObject *a, *b;
|
||||||
int ok;
|
int ok;
|
||||||
|
|
||||||
if (_PyObject_LookupAttr((PyObject *)(Py_TYPE(right)), name, &b) < 0) {
|
if (PyObject_GetOptionalAttr((PyObject *)(Py_TYPE(right)), name, &b) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (b == NULL) {
|
if (b == NULL) {
|
||||||
|
@ -8401,7 +8401,7 @@ method_is_overloaded(PyObject *left, PyObject *right, PyObject *name)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyObject_LookupAttr((PyObject *)(Py_TYPE(left)), name, &a) < 0) {
|
if (PyObject_GetOptionalAttr((PyObject *)(Py_TYPE(left)), name, &a) < 0) {
|
||||||
Py_DECREF(b);
|
Py_DECREF(b);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -10373,7 +10373,7 @@ supercheck(PyTypeObject *type, PyObject *obj)
|
||||||
/* Try the slow way */
|
/* Try the slow way */
|
||||||
PyObject *class_attr;
|
PyObject *class_attr;
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(obj, &_Py_ID(__class__), &class_attr) < 0) {
|
if (PyObject_GetOptionalAttr(obj, &_Py_ID(__class__), &class_attr) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (class_attr != NULL &&
|
if (class_attr != NULL &&
|
||||||
|
|
|
@ -194,13 +194,13 @@ union_repr_item(_PyUnicodeWriter *writer, PyObject *p)
|
||||||
return _PyUnicodeWriter_WriteASCIIString(writer, "None", 4);
|
return _PyUnicodeWriter_WriteASCIIString(writer, "None", 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(p, &_Py_ID(__origin__), &tmp) < 0) {
|
if (PyObject_GetOptionalAttr(p, &_Py_ID(__origin__), &tmp) < 0) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tmp) {
|
if (tmp) {
|
||||||
Py_DECREF(tmp);
|
Py_DECREF(tmp);
|
||||||
if (_PyObject_LookupAttr(p, &_Py_ID(__args__), &tmp) < 0) {
|
if (PyObject_GetOptionalAttr(p, &_Py_ID(__args__), &tmp) < 0) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
if (tmp) {
|
if (tmp) {
|
||||||
|
@ -210,13 +210,13 @@ union_repr_item(_PyUnicodeWriter *writer, PyObject *p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(p, &_Py_ID(__qualname__), &qualname) < 0) {
|
if (PyObject_GetOptionalAttr(p, &_Py_ID(__qualname__), &qualname) < 0) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
if (qualname == NULL) {
|
if (qualname == NULL) {
|
||||||
goto use_repr;
|
goto use_repr;
|
||||||
}
|
}
|
||||||
if (_PyObject_LookupAttr(p, &_Py_ID(__module__), &module) < 0) {
|
if (PyObject_GetOptionalAttr(p, &_Py_ID(__module__), &module) < 0) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
if (module == NULL || module == Py_None) {
|
if (module == NULL || module == Py_None) {
|
||||||
|
|
|
@ -629,7 +629,7 @@ class Obj2ModVisitor(PickleVisitor):
|
||||||
|
|
||||||
def visitField(self, field, name, sum=None, prod=None, depth=0):
|
def visitField(self, field, name, sum=None, prod=None, depth=0):
|
||||||
ctype = get_c_type(field.type)
|
ctype = get_c_type(field.type)
|
||||||
line = "if (_PyObject_LookupAttr(obj, state->%s, &tmp) < 0) {"
|
line = "if (PyObject_GetOptionalAttr(obj, state->%s, &tmp) < 0) {"
|
||||||
self.emit(line % field.name, depth)
|
self.emit(line % field.name, depth)
|
||||||
self.emit("return 1;", depth+1)
|
self.emit("return 1;", depth+1)
|
||||||
self.emit("}", depth)
|
self.emit("}", depth)
|
||||||
|
@ -813,7 +813,7 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
|
||||||
Py_ssize_t i, numfields = 0;
|
Py_ssize_t i, numfields = 0;
|
||||||
int res = -1;
|
int res = -1;
|
||||||
PyObject *key, *value, *fields;
|
PyObject *key, *value, *fields;
|
||||||
if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), state->_fields, &fields) < 0) {
|
if (PyObject_GetOptionalAttr((PyObject*)Py_TYPE(self), state->_fields, &fields) < 0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (fields) {
|
if (fields) {
|
||||||
|
@ -887,7 +887,7 @@ ast_type_reduce(PyObject *self, PyObject *unused)
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *dict;
|
PyObject *dict;
|
||||||
if (_PyObject_LookupAttr(self, state->__dict__, &dict) < 0) {
|
if (PyObject_GetOptionalAttr(self, state->__dict__, &dict) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (dict) {
|
if (dict) {
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -223,7 +223,7 @@ get_warnings_attr(PyInterpreterState *interp, PyObject *attr, int try_import)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)_PyObject_LookupAttr(warnings_module, attr, &obj);
|
(void)PyObject_GetOptionalAttr(warnings_module, attr, &obj);
|
||||||
Py_DECREF(warnings_module);
|
Py_DECREF(warnings_module);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
@ -1069,7 +1069,7 @@ get_source_line(PyInterpreterState *interp, PyObject *module_globals, int lineno
|
||||||
Py_INCREF(module_name);
|
Py_INCREF(module_name);
|
||||||
|
|
||||||
/* Make sure the loader implements the optional get_source() method. */
|
/* Make sure the loader implements the optional get_source() method. */
|
||||||
(void)_PyObject_LookupAttr(loader, &_Py_ID(get_source), &get_source);
|
(void)PyObject_GetOptionalAttr(loader, &_Py_ID(get_source), &get_source);
|
||||||
Py_DECREF(loader);
|
Py_DECREF(loader);
|
||||||
if (!get_source) {
|
if (!get_source) {
|
||||||
Py_DECREF(module_name);
|
Py_DECREF(module_name);
|
||||||
|
|
|
@ -34,7 +34,7 @@ update_bases(PyObject *bases, PyObject *const *args, Py_ssize_t nargs)
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (_PyObject_LookupAttr(base, &_Py_ID(__mro_entries__), &meth) < 0) {
|
if (PyObject_GetOptionalAttr(base, &_Py_ID(__mro_entries__), &meth) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (!meth) {
|
if (!meth) {
|
||||||
|
@ -175,7 +175,7 @@ builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs,
|
||||||
}
|
}
|
||||||
/* else: meta is not a class, so we cannot do the metaclass
|
/* else: meta is not a class, so we cannot do the metaclass
|
||||||
calculation, so we will use the explicitly given object as it is */
|
calculation, so we will use the explicitly given object as it is */
|
||||||
if (_PyObject_LookupAttr(meta, &_Py_ID(__prepare__), &prep) < 0) {
|
if (PyObject_GetOptionalAttr(meta, &_Py_ID(__prepare__), &prep) < 0) {
|
||||||
ns = NULL;
|
ns = NULL;
|
||||||
}
|
}
|
||||||
else if (prep == NULL) {
|
else if (prep == NULL) {
|
||||||
|
@ -1160,7 +1160,7 @@ builtin_getattr_impl(PyObject *module, PyObject *object, PyObject *name,
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
|
|
||||||
if (default_value != NULL) {
|
if (default_value != NULL) {
|
||||||
if (_PyObject_LookupAttr(object, name, &result) == 0) {
|
if (PyObject_GetOptionalAttr(object, name, &result) == 0) {
|
||||||
return Py_NewRef(default_value);
|
return Py_NewRef(default_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1209,7 +1209,7 @@ builtin_hasattr_impl(PyObject *module, PyObject *obj, PyObject *name)
|
||||||
{
|
{
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(obj, name, &v) < 0) {
|
if (PyObject_GetOptionalAttr(obj, name, &v) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (v == NULL) {
|
if (v == NULL) {
|
||||||
|
@ -2465,7 +2465,7 @@ builtin_vars_impl(PyObject *module, PyObject *object)
|
||||||
d = _PyEval_GetFrameLocals();
|
d = _PyEval_GetFrameLocals();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (_PyObject_LookupAttr(object, &_Py_ID(__dict__), &d) == 0) {
|
if (PyObject_GetOptionalAttr(object, &_Py_ID(__dict__), &d) == 0) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"vars() argument must have __dict__ attribute");
|
"vars() argument must have __dict__ attribute");
|
||||||
}
|
}
|
||||||
|
|
|
@ -419,7 +419,7 @@ match_class_attr(PyThreadState *tstate, PyObject *subject, PyObject *type,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
PyObject *attr;
|
PyObject *attr;
|
||||||
(void)_PyObject_LookupAttr(subject, name, &attr);
|
(void)PyObject_GetOptionalAttr(subject, name, &attr);
|
||||||
return attr;
|
return attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -454,7 +454,7 @@ match_class(PyThreadState *tstate, PyObject *subject, PyObject *type,
|
||||||
// First, the positional subpatterns:
|
// First, the positional subpatterns:
|
||||||
if (nargs) {
|
if (nargs) {
|
||||||
int match_self = 0;
|
int match_self = 0;
|
||||||
if (_PyObject_LookupAttr(type, &_Py_ID(__match_args__), &match_args) < 0) {
|
if (PyObject_GetOptionalAttr(type, &_Py_ID(__match_args__), &match_args) < 0) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (match_args) {
|
if (match_args) {
|
||||||
|
@ -2414,7 +2414,7 @@ import_from(PyThreadState *tstate, PyObject *v, PyObject *name)
|
||||||
PyObject *x;
|
PyObject *x;
|
||||||
PyObject *fullmodname, *pkgname, *pkgpath, *pkgname_or_unknown, *errmsg;
|
PyObject *fullmodname, *pkgname, *pkgpath, *pkgname_or_unknown, *errmsg;
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(v, name, &x) != 0) {
|
if (PyObject_GetOptionalAttr(v, name, &x) != 0) {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
/* Issue #17636: in case this failed because of a circular relative
|
/* Issue #17636: in case this failed because of a circular relative
|
||||||
|
|
|
@ -516,7 +516,7 @@ PyObject * _PyCodec_LookupTextEncoding(const char *encoding,
|
||||||
* attribute.
|
* attribute.
|
||||||
*/
|
*/
|
||||||
if (!PyTuple_CheckExact(codec)) {
|
if (!PyTuple_CheckExact(codec)) {
|
||||||
if (_PyObject_LookupAttr(codec, &_Py_ID(_is_text_encoding), &attr) < 0) {
|
if (PyObject_GetOptionalAttr(codec, &_Py_ID(_is_text_encoding), &attr) < 0) {
|
||||||
Py_DECREF(codec);
|
Py_DECREF(codec);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1748,7 +1748,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((PyObject *)Py_TYPE(exc) != PyExc_SyntaxError) {
|
if ((PyObject *)Py_TYPE(exc) != PyExc_SyntaxError) {
|
||||||
if (_PyObject_LookupAttr(exc, &_Py_ID(msg), &tmp) < 0) {
|
if (PyObject_GetOptionalAttr(exc, &_Py_ID(msg), &tmp) < 0) {
|
||||||
_PyErr_Clear(tstate);
|
_PyErr_Clear(tstate);
|
||||||
}
|
}
|
||||||
else if (tmp) {
|
else if (tmp) {
|
||||||
|
@ -1767,7 +1767,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(exc, &_Py_ID(print_file_and_line), &tmp) < 0) {
|
if (PyObject_GetOptionalAttr(exc, &_Py_ID(print_file_and_line), &tmp) < 0) {
|
||||||
_PyErr_Clear(tstate);
|
_PyErr_Clear(tstate);
|
||||||
}
|
}
|
||||||
else if (tmp) {
|
else if (tmp) {
|
||||||
|
|
|
@ -2878,7 +2878,7 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PyObject *path;
|
PyObject *path;
|
||||||
if (_PyObject_LookupAttr(mod, &_Py_ID(__path__), &path) < 0) {
|
if (PyObject_GetOptionalAttr(mod, &_Py_ID(__path__), &path) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (path) {
|
if (path) {
|
||||||
|
|
|
@ -40,11 +40,11 @@ import_all_from(PyThreadState *tstate, PyObject *locals, PyObject *v)
|
||||||
int skip_leading_underscores = 0;
|
int skip_leading_underscores = 0;
|
||||||
int pos, err;
|
int pos, err;
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(v, &_Py_ID(__all__), &all) < 0) {
|
if (PyObject_GetOptionalAttr(v, &_Py_ID(__all__), &all) < 0) {
|
||||||
return -1; /* Unexpected error */
|
return -1; /* Unexpected error */
|
||||||
}
|
}
|
||||||
if (all == NULL) {
|
if (all == NULL) {
|
||||||
if (_PyObject_LookupAttr(v, &_Py_ID(__dict__), &dict) < 0) {
|
if (PyObject_GetOptionalAttr(v, &_Py_ID(__dict__), &dict) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (dict == NULL) {
|
if (dict == NULL) {
|
||||||
|
|
|
@ -953,7 +953,7 @@ print_exception_file_and_line(struct exception_print_context *ctx,
|
||||||
PyObject *f = ctx->file;
|
PyObject *f = ctx->file;
|
||||||
|
|
||||||
PyObject *tmp;
|
PyObject *tmp;
|
||||||
int res = _PyObject_LookupAttr(*value_p, &_Py_ID(print_file_and_line), &tmp);
|
int res = PyObject_GetOptionalAttr(*value_p, &_Py_ID(print_file_and_line), &tmp);
|
||||||
if (res <= 0) {
|
if (res <= 0) {
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
|
@ -1132,7 +1132,7 @@ print_exception_notes(struct exception_print_context *ctx, PyObject *value)
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *notes;
|
PyObject *notes;
|
||||||
int res = _PyObject_LookupAttr(value, &_Py_ID(__notes__), ¬es);
|
int res = PyObject_GetOptionalAttr(value, &_Py_ID(__notes__), ¬es);
|
||||||
if (res <= 0) {
|
if (res <= 0) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -247,7 +247,7 @@ get_suggestions_for_name_error(PyObject* name, PyFrameObject* frame)
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *value;
|
PyObject *value;
|
||||||
res = _PyObject_LookupAttr(self, name, &value);
|
res = PyObject_GetOptionalAttr(self, name, &value);
|
||||||
Py_DECREF(locals);
|
Py_DECREF(locals);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
|
|
|
@ -257,7 +257,7 @@ sys_audit_tstate(PyThreadState *ts, const char *event,
|
||||||
PyThreadState_EnterTracing(ts);
|
PyThreadState_EnterTracing(ts);
|
||||||
while ((hook = PyIter_Next(hooks)) != NULL) {
|
while ((hook = PyIter_Next(hooks)) != NULL) {
|
||||||
PyObject *o;
|
PyObject *o;
|
||||||
int canTrace = _PyObject_LookupAttr(hook, &_Py_ID(__cantrace__), &o);
|
int canTrace = PyObject_GetOptionalAttr(hook, &_Py_ID(__cantrace__), &o);
|
||||||
if (o) {
|
if (o) {
|
||||||
canTrace = PyObject_IsTrue(o);
|
canTrace = PyObject_IsTrue(o);
|
||||||
Py_DECREF(o);
|
Py_DECREF(o);
|
||||||
|
@ -657,7 +657,7 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o)
|
||||||
if (encoded == NULL)
|
if (encoded == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(outf, &_Py_ID(buffer), &buffer) < 0) {
|
if (PyObject_GetOptionalAttr(outf, &_Py_ID(buffer), &buffer) < 0) {
|
||||||
Py_DECREF(encoded);
|
Py_DECREF(encoded);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue