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(PyObject *) _PyObject_GetAttrId(PyObject *, _Py_Identifier *);
|
||||
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);
|
||||
|
||||
|
|
|
@ -361,7 +361,7 @@ compute_abstract_methods(PyObject *self)
|
|||
PyObject *item = PyTuple_GET_ITEM(bases, pos); // borrowed
|
||||
PyObject *base_abstracts, *iter;
|
||||
|
||||
if (_PyObject_LookupAttr(item, &_Py_ID(__abstractmethods__),
|
||||
if (PyObject_GetOptionalAttr(item, &_Py_ID(__abstractmethods__),
|
||||
&base_abstracts) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ compute_abstract_methods(PyObject *self)
|
|||
Py_DECREF(base_abstracts);
|
||||
PyObject *key, *value;
|
||||
while ((key = PyIter_Next(iter))) {
|
||||
if (_PyObject_LookupAttr(self, key, &value) < 0) {
|
||||
if (PyObject_GetOptionalAttr(self, key, &value) < 0) {
|
||||
Py_DECREF(key);
|
||||
Py_DECREF(iter);
|
||||
goto error;
|
||||
|
|
|
@ -248,7 +248,7 @@ get_future_loop(asyncio_state *state, PyObject *fut)
|
|||
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;
|
||||
}
|
||||
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 */
|
||||
if (_PyObject_LookupAttr(result, &_Py_ID(_asyncio_future_blocking), &o) < 0) {
|
||||
if (PyObject_GetOptionalAttr(result, &_Py_ID(_asyncio_future_blocking), &o) < 0) {
|
||||
goto fail;
|
||||
}
|
||||
if (o != NULL && o != Py_None) {
|
||||
|
|
|
@ -1450,7 +1450,7 @@ csv_writer(PyObject *module, PyObject *args, PyObject *keyword_args)
|
|||
Py_DECREF(self);
|
||||
return NULL;
|
||||
}
|
||||
if (_PyObject_LookupAttr(output_file,
|
||||
if (PyObject_GetOptionalAttr(output_file,
|
||||
module_state->str_write,
|
||||
&self->write) < 0) {
|
||||
Py_DECREF(self);
|
||||
|
|
|
@ -851,7 +851,7 @@ CDataType_from_param(PyObject *type, PyObject *value)
|
|||
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;
|
||||
}
|
||||
if (as_parameter) {
|
||||
|
@ -1495,7 +1495,7 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
stgdict = 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;
|
||||
}
|
||||
if (!length_attr) {
|
||||
|
@ -1528,7 +1528,7 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
if (as_parameter) {
|
||||
|
@ -2054,7 +2054,7 @@ PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
if (result == 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;
|
||||
}
|
||||
if (!proto) {
|
||||
|
@ -2266,7 +2266,7 @@ PyCSimpleType_from_param(PyObject *type, PyObject *value)
|
|||
PyObject *exc = PyErr_GetRaisedException();
|
||||
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);
|
||||
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(ob);
|
||||
if (!PyErr_Occurred()) {
|
||||
|
@ -2489,7 +2489,7 @@ make_funcptrtype_dict(StgDictObject *stgdict)
|
|||
return -1;
|
||||
}
|
||||
stgdict->restype = Py_NewRef(ob);
|
||||
if (_PyObject_LookupAttr(ob, &_Py_ID(_check_retval_),
|
||||
if (PyObject_GetOptionalAttr(ob, &_Py_ID(_check_retval_),
|
||||
&stgdict->checker) < 0)
|
||||
{
|
||||
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");
|
||||
return -1;
|
||||
}
|
||||
if (_PyObject_LookupAttr(ob, &_Py_ID(_check_retval_), &checker) < 0) {
|
||||
if (PyObject_GetOptionalAttr(ob, &_Py_ID(_check_retval_), &checker) < 0) {
|
||||
return -1;
|
||||
}
|
||||
oldchecker = self->checker;
|
||||
|
|
|
@ -727,7 +727,7 @@ static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa)
|
|||
|
||||
{
|
||||
PyObject *arg;
|
||||
if (_PyObject_LookupAttr(obj, &_Py_ID(_as_parameter_), &arg) < 0) {
|
||||
if (PyObject_GetOptionalAttr(obj, &_Py_ID(_as_parameter_), &arg) < 0) {
|
||||
return -1;
|
||||
}
|
||||
/* Which types should we exactly allow here?
|
||||
|
|
|
@ -295,7 +295,7 @@ MakeAnonFields(PyObject *type)
|
|||
PyObject *anon_names;
|
||||
Py_ssize_t i;
|
||||
|
||||
if (_PyObject_LookupAttr(type, &_Py_ID(_anonymous_), &anon) < 0) {
|
||||
if (PyObject_GetOptionalAttr(type, &_Py_ID(_anonymous_), &anon) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (anon == NULL) {
|
||||
|
@ -385,7 +385,7 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
|
|||
if (fields == NULL)
|
||||
return 0;
|
||||
|
||||
if (_PyObject_LookupAttr(type, &_Py_ID(_swappedbytes_), &tmp) < 0) {
|
||||
if (PyObject_GetOptionalAttr(type, &_Py_ID(_swappedbytes_), &tmp) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (tmp) {
|
||||
|
@ -396,7 +396,7 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
|
|||
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;
|
||||
}
|
||||
if (tmp) {
|
||||
|
|
|
@ -3791,7 +3791,7 @@ tzinfo_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
|
|||
PyObject *args, *state;
|
||||
PyObject *getinitargs;
|
||||
|
||||
if (_PyObject_LookupAttr(self, &_Py_ID(__getinitargs__), &getinitargs) < 0) {
|
||||
if (PyObject_GetOptionalAttr(self, &_Py_ID(__getinitargs__), &getinitargs) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (getinitargs != NULL) {
|
||||
|
|
|
@ -3530,7 +3530,7 @@ expat_start_doctype_handler(XMLParserObject *self,
|
|||
sysid_obj, NULL);
|
||||
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,
|
||||
"The doctype() method of XMLParser is ignored. "
|
||||
"Define doctype() method on the TreeBuilder target.",
|
||||
|
|
|
@ -1463,7 +1463,7 @@ buffered_repr(buffered *self)
|
|||
{
|
||||
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)) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1630,7 +1630,7 @@ _bufferedreader_read_all(buffered *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;
|
||||
}
|
||||
if (readall) {
|
||||
|
|
|
@ -1099,7 +1099,7 @@ fileio_repr(fileio *self)
|
|||
if (self->fd < 0)
|
||||
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;
|
||||
}
|
||||
if (nameobj == NULL) {
|
||||
|
|
|
@ -148,7 +148,7 @@ iobase_is_closed(PyObject *self)
|
|||
int ret;
|
||||
/* This gets the derived attribute, which is *not* __IOBase_closed
|
||||
in most cases! */
|
||||
ret = _PyObject_LookupAttr(self, &_Py_ID(__IOBase_closed), &res);
|
||||
ret = PyObject_GetOptionalAttr(self, &_Py_ID(__IOBase_closed), &res);
|
||||
Py_XDECREF(res);
|
||||
return ret;
|
||||
}
|
||||
|
@ -196,7 +196,7 @@ iobase_check_closed(PyObject *self)
|
|||
int closed;
|
||||
/* This gets the derived attribute, which is *not* __IOBase_closed
|
||||
in most cases! */
|
||||
closed = _PyObject_LookupAttr(self, &_Py_ID(closed), &res);
|
||||
closed = PyObject_GetOptionalAttr(self, &_Py_ID(closed), &res);
|
||||
if (closed > 0) {
|
||||
closed = PyObject_IsTrue(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
|
||||
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();
|
||||
closed = -1;
|
||||
}
|
||||
|
@ -571,7 +571,7 @@ _io__IOBase_readline_impl(PyObject *self, Py_ssize_t limit)
|
|||
PyObject *peek, *buffer, *result;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -946,7 +946,7 @@ _textiowrapper_set_encoder(textio *self, PyObject *codec_info,
|
|||
return -1;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
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->PyBufferedRandom_Type))
|
||||
{
|
||||
if (_PyObject_LookupAttr(buffer, &_Py_ID(raw), &raw) < 0)
|
||||
if (PyObject_GetOptionalAttr(buffer, &_Py_ID(raw), &raw) < 0)
|
||||
goto error;
|
||||
/* Cache the raw FileIO object to speed up 'closed' checks */
|
||||
if (raw != NULL) {
|
||||
|
@ -1222,7 +1222,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
|
|||
goto error;
|
||||
self->seekable = self->telling = r;
|
||||
|
||||
r = _PyObject_LookupAttr(buffer, &_Py_ID(read1), &res);
|
||||
r = PyObject_GetOptionalAttr(buffer, &_Py_ID(read1), &res);
|
||||
if (r < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
@ -2897,7 +2897,7 @@ textiowrapper_repr(textio *self)
|
|||
}
|
||||
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)) {
|
||||
goto error;
|
||||
}
|
||||
|
@ -2913,7 +2913,7 @@ textiowrapper_repr(textio *self)
|
|||
if (res == NULL)
|
||||
goto error;
|
||||
}
|
||||
if (_PyObject_LookupAttr((PyObject *) self, &_Py_ID(mode), &modeobj) < 0) {
|
||||
if (PyObject_GetOptionalAttr((PyObject *) self, &_Py_ID(mode), &modeobj) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (modeobj != NULL) {
|
||||
|
@ -3130,7 +3130,7 @@ textiowrapper_newlines_get(textio *self, void *context)
|
|||
PyObject *res;
|
||||
CHECK_ATTACHED(self);
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -406,7 +406,7 @@ init_method_ref(PyObject *self, PyObject *name,
|
|||
|
||||
/* *method_func and *method_self should be consistent. All refcount decrements
|
||||
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) {
|
||||
*method_self = NULL;
|
||||
Py_CLEAR(*method_func);
|
||||
|
@ -1224,7 +1224,7 @@ static int
|
|||
_Pickler_SetOutputStream(PicklerObject *self, PyObject *file)
|
||||
{
|
||||
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;
|
||||
}
|
||||
if (self->write == NULL) {
|
||||
|
@ -1694,16 +1694,16 @@ static int
|
|||
_Unpickler_SetInputStream(UnpicklerObject *self, PyObject *file)
|
||||
{
|
||||
/* 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;
|
||||
}
|
||||
if (_PyObject_LookupAttr(file, &_Py_ID(readinto), &self->readinto) < 0) {
|
||||
if (PyObject_GetOptionalAttr(file, &_Py_ID(readinto), &self->readinto) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (_PyObject_LookupAttr(file, &_Py_ID(read), &self->read) < 0) {
|
||||
if (PyObject_GetOptionalAttr(file, &_Py_ID(read), &self->read) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (_PyObject_LookupAttr(file, &_Py_ID(readline), &self->readline) < 0) {
|
||||
if (PyObject_GetOptionalAttr(file, &_Py_ID(readline), &self->readline) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (!self->readline || !self->read) {
|
||||
|
@ -1900,7 +1900,7 @@ get_deep_attribute(PyObject *obj, PyObject *names, PyObject **pparent)
|
|||
for (i = 0; i < n; i++) {
|
||||
PyObject *name = PyList_GET_ITEM(names, i);
|
||||
Py_XSETREF(parent, obj);
|
||||
(void)_PyObject_LookupAttr(parent, name, &obj);
|
||||
(void)PyObject_GetOptionalAttr(parent, name, &obj);
|
||||
if (obj == NULL) {
|
||||
Py_DECREF(parent);
|
||||
return NULL;
|
||||
|
@ -1927,7 +1927,7 @@ getattribute(PyObject *obj, PyObject *name, int allow_qualname)
|
|||
Py_DECREF(dotted_path);
|
||||
}
|
||||
else {
|
||||
(void)_PyObject_LookupAttr(obj, name, &attr);
|
||||
(void)PyObject_GetOptionalAttr(obj, name, &attr);
|
||||
}
|
||||
if (attr == NULL && !PyErr_Occurred()) {
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
|
@ -1968,7 +1968,7 @@ whichmodule(PyObject *global, PyObject *dotted_path)
|
|||
Py_ssize_t i;
|
||||
PyObject *modules;
|
||||
|
||||
if (_PyObject_LookupAttr(global, &_Py_ID(__module__), &module_name) < 0) {
|
||||
if (PyObject_GetOptionalAttr(global, &_Py_ID(__module__), &module_name) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (module_name) {
|
||||
|
@ -3656,7 +3656,7 @@ save_global(PickleState *st, PicklerObject *self, PyObject *obj,
|
|||
global_name = Py_NewRef(name);
|
||||
}
|
||||
else {
|
||||
if (_PyObject_LookupAttr(obj, &_Py_ID(__qualname__), &global_name) < 0)
|
||||
if (PyObject_GetOptionalAttr(obj, &_Py_ID(__qualname__), &global_name) < 0)
|
||||
goto error;
|
||||
if (global_name == NULL) {
|
||||
global_name = PyObject_GetAttr(obj, &_Py_ID(__name__));
|
||||
|
@ -3979,7 +3979,7 @@ get_class(PyObject *obj)
|
|||
{
|
||||
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));
|
||||
}
|
||||
return cls;
|
||||
|
@ -4062,7 +4062,7 @@ save_reduce(PickleState *st, PicklerObject *self, PyObject *args,
|
|||
if (self->proto >= 2) {
|
||||
PyObject *name;
|
||||
|
||||
if (_PyObject_LookupAttr(callable, &_Py_ID(__name__), &name) < 0) {
|
||||
if (PyObject_GetOptionalAttr(callable, &_Py_ID(__name__), &name) < 0) {
|
||||
return -1;
|
||||
}
|
||||
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. */
|
||||
|
||||
/* 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;
|
||||
}
|
||||
if (reduce_func != NULL) {
|
||||
|
@ -4474,7 +4474,7 @@ save(PickleState *st, PicklerObject *self, PyObject *obj, int pers_save)
|
|||
}
|
||||
else {
|
||||
/* 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;
|
||||
}
|
||||
if (reduce_func != NULL) {
|
||||
|
@ -4526,7 +4526,7 @@ dump(PickleState *state, PicklerObject *self, PyObject *obj)
|
|||
int status = -1;
|
||||
PyObject *tmp;
|
||||
|
||||
if (_PyObject_LookupAttr((PyObject *)self, &_Py_ID(reducer_override),
|
||||
if (PyObject_GetOptionalAttr((PyObject *)self, &_Py_ID(reducer_override),
|
||||
&tmp) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
@ -4796,7 +4796,7 @@ _pickle_Pickler___init___impl(PicklerObject *self, PyObject *file,
|
|||
if (self->dispatch_table != NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (_PyObject_LookupAttr((PyObject *)self, &_Py_ID(dispatch_table),
|
||||
if (PyObject_GetOptionalAttr((PyObject *)self, &_Py_ID(dispatch_table),
|
||||
&self->dispatch_table) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -5797,7 +5797,7 @@ instantiate(PyObject *cls, PyObject *args)
|
|||
assert(PyTuple_Check(args));
|
||||
if (!PyTuple_GET_SIZE(args) && PyType_Check(cls)) {
|
||||
PyObject *func;
|
||||
if (_PyObject_LookupAttr(cls, &_Py_ID(__getinitargs__), &func) < 0) {
|
||||
if (PyObject_GetOptionalAttr(cls, &_Py_ID(__getinitargs__), &func) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (func == NULL) {
|
||||
|
@ -6451,7 +6451,7 @@ do_append(PickleState *state, UnpicklerObject *self, Py_ssize_t x)
|
|||
else {
|
||||
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;
|
||||
}
|
||||
if (extend_func != NULL) {
|
||||
|
@ -6637,7 +6637,7 @@ load_build(PickleState *st, UnpicklerObject *self)
|
|||
|
||||
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);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ pysqlite_microprotocols_adapt(pysqlite_state *state, PyObject *obj,
|
|||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
if (adapter) {
|
||||
|
@ -117,7 +117,7 @@ pysqlite_microprotocols_adapt(pysqlite_state *state, PyObject *obj,
|
|||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
if (adapter) {
|
||||
|
|
|
@ -1438,7 +1438,7 @@ thread_excepthook_file(PyObject *file, PyObject *exc_type, PyObject *exc_value,
|
|||
|
||||
PyObject *name = NULL;
|
||||
if (thread != Py_None) {
|
||||
if (_PyObject_LookupAttr(thread, &_Py_ID(name), &name) < 0) {
|
||||
if (PyObject_GetOptionalAttr(thread, &_Py_ID(name), &name) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2268,7 +2268,7 @@ array_array___reduce_ex___impl(arrayobject *self, PyTypeObject *cls,
|
|||
if (protocol == -1 && PyErr_Occurred())
|
||||
return NULL;
|
||||
|
||||
if (_PyObject_LookupAttr((PyObject *)self, state->str___dict__, &dict) < 0) {
|
||||
if (PyObject_GetOptionalAttr((PyObject *)self, state->str___dict__, &dict) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (dict == NULL) {
|
||||
|
|
|
@ -1146,7 +1146,7 @@ itertools_tee_impl(PyObject *module, PyObject *iterable, Py_ssize_t n)
|
|||
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(result);
|
||||
return NULL;
|
||||
|
|
|
@ -832,7 +832,7 @@ pyexpat_xmlparser_ParseFile_impl(xmlparseobject *self, PyTypeObject *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;
|
||||
}
|
||||
if (readmethod == NULL) {
|
||||
|
|
|
@ -182,7 +182,7 @@ PyObject_GetItem(PyObject *o, PyObject *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;
|
||||
}
|
||||
if (meth && meth != Py_None) {
|
||||
|
@ -2552,7 +2552,7 @@ abstract_get_bases(PyObject *cls)
|
|||
{
|
||||
PyObject *bases;
|
||||
|
||||
(void)_PyObject_LookupAttr(cls, &_Py_ID(__bases__), &bases);
|
||||
(void)PyObject_GetOptionalAttr(cls, &_Py_ID(__bases__), &bases);
|
||||
if (bases != NULL && !PyTuple_Check(bases)) {
|
||||
Py_DECREF(bases);
|
||||
return NULL;
|
||||
|
@ -2636,7 +2636,7 @@ object_isinstance(PyObject *inst, PyObject *cls)
|
|||
if (PyType_Check(cls)) {
|
||||
retval = PyObject_TypeCheck(inst, (PyTypeObject *)cls);
|
||||
if (retval == 0) {
|
||||
retval = _PyObject_LookupAttr(inst, &_Py_ID(__class__), &icls);
|
||||
retval = PyObject_GetOptionalAttr(inst, &_Py_ID(__class__), &icls);
|
||||
if (icls != NULL) {
|
||||
if (icls != (PyObject *)(Py_TYPE(inst)) && PyType_Check(icls)) {
|
||||
retval = PyType_IsSubtype(
|
||||
|
@ -2654,7 +2654,7 @@ object_isinstance(PyObject *inst, PyObject *cls)
|
|||
if (!check_class(cls,
|
||||
"isinstance() arg 2 must be a type, a tuple of types, or a union"))
|
||||
return -1;
|
||||
retval = _PyObject_LookupAttr(inst, &_Py_ID(__class__), &icls);
|
||||
retval = PyObject_GetOptionalAttr(inst, &_Py_ID(__class__), &icls);
|
||||
if (icls != NULL) {
|
||||
retval = abstract_issubclass(icls, cls);
|
||||
Py_DECREF(icls);
|
||||
|
|
|
@ -173,7 +173,7 @@ object_is_not_callable(PyThreadState *tstate, PyObject *callable)
|
|||
goto basic_type_error;
|
||||
}
|
||||
PyObject *attr;
|
||||
int res = _PyObject_LookupAttr(callable, name, &attr);
|
||||
int res = PyObject_GetOptionalAttr(callable, name, &attr);
|
||||
if (res < 0) {
|
||||
_PyErr_Clear(tstate);
|
||||
}
|
||||
|
|
|
@ -275,9 +275,9 @@ method_repr(PyMethodObject *a)
|
|||
PyObject *funcname, *result;
|
||||
const char *defname = "?";
|
||||
|
||||
if (_PyObject_LookupAttr(func, &_Py_ID(__qualname__), &funcname) < 0 ||
|
||||
if (PyObject_GetOptionalAttr(func, &_Py_ID(__qualname__), &funcname) < 0 ||
|
||||
(funcname == NULL &&
|
||||
_PyObject_LookupAttr(func, &_Py_ID(__name__), &funcname) < 0))
|
||||
PyObject_GetOptionalAttr(func, &_Py_ID(__name__), &funcname) < 0))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
@ -479,7 +479,7 @@ instancemethod_repr(PyObject *self)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (_PyObject_LookupAttr(func, &_Py_ID(__name__), &funcname) < 0) {
|
||||
if (PyObject_GetOptionalAttr(func, &_Py_ID(__name__), &funcname) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
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 */
|
||||
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) {
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -2664,7 +2664,7 @@ dict_update_arg(PyObject *self, PyObject *arg)
|
|||
return PyDict_Merge(self, arg, 1);
|
||||
}
|
||||
PyObject *func;
|
||||
if (_PyObject_LookupAttr(arg, &_Py_ID(keys), &func) < 0) {
|
||||
if (PyObject_GetOptionalAttr(arg, &_Py_ID(keys), &func) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (func != NULL) {
|
||||
|
|
|
@ -208,7 +208,7 @@ BaseException_add_note(PyObject *self, PyObject *note)
|
|||
}
|
||||
|
||||
PyObject *notes;
|
||||
if (_PyObject_LookupAttr(self, &_Py_ID(__notes__), ¬es) < 0) {
|
||||
if (PyObject_GetOptionalAttr(self, &_Py_ID(__notes__), ¬es) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (notes == NULL) {
|
||||
|
@ -941,7 +941,7 @@ exceptiongroup_subset(
|
|||
PyException_SetCause(eg, PyException_GetCause(orig));
|
||||
|
||||
PyObject *notes;
|
||||
if (_PyObject_LookupAttr(orig, &_Py_ID(__notes__), ¬es) < 0) {
|
||||
if (PyObject_GetOptionalAttr(orig, &_Py_ID(__notes__), ¬es) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (notes) {
|
||||
|
|
|
@ -176,7 +176,7 @@ PyObject_AsFileDescriptor(PyObject *o)
|
|||
if (PyLong_Check(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;
|
||||
}
|
||||
else if (meth != NULL) {
|
||||
|
|
|
@ -943,7 +943,7 @@ static int
|
|||
functools_copy_attr(PyObject *wrapper, PyObject *wrapped, PyObject *name)
|
||||
{
|
||||
PyObject *value;
|
||||
int res = _PyObject_LookupAttr(wrapped, name, &value);
|
||||
int res = PyObject_GetOptionalAttr(wrapped, name, &value);
|
||||
if (value != NULL) {
|
||||
res = PyObject_SetAttr(wrapper, name, value);
|
||||
Py_DECREF(value);
|
||||
|
|
|
@ -63,12 +63,12 @@ ga_repr_item(_PyUnicodeWriter *writer, PyObject *p)
|
|||
goto done;
|
||||
}
|
||||
|
||||
if (_PyObject_LookupAttr(p, &_Py_ID(__origin__), &tmp) < 0) {
|
||||
if (PyObject_GetOptionalAttr(p, &_Py_ID(__origin__), &tmp) < 0) {
|
||||
goto done;
|
||||
}
|
||||
if (tmp != NULL) {
|
||||
Py_DECREF(tmp);
|
||||
if (_PyObject_LookupAttr(p, &_Py_ID(__args__), &tmp) < 0) {
|
||||
if (PyObject_GetOptionalAttr(p, &_Py_ID(__args__), &tmp) < 0) {
|
||||
goto done;
|
||||
}
|
||||
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;
|
||||
}
|
||||
if (qualname == NULL) {
|
||||
goto use_repr;
|
||||
}
|
||||
if (_PyObject_LookupAttr(p, &_Py_ID(__module__), &module) < 0) {
|
||||
if (PyObject_GetOptionalAttr(p, &_Py_ID(__module__), &module) < 0) {
|
||||
goto done;
|
||||
}
|
||||
if (module == NULL || module == Py_None) {
|
||||
|
@ -257,7 +257,7 @@ _Py_make_parameters(PyObject *args)
|
|||
if (PyType_Check(t)) {
|
||||
continue;
|
||||
}
|
||||
if (_PyObject_LookupAttr(t, &_Py_ID(__typing_subst__), &subst) < 0) {
|
||||
if (PyObject_GetOptionalAttr(t, &_Py_ID(__typing_subst__), &subst) < 0) {
|
||||
Py_DECREF(parameters);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -267,7 +267,7 @@ _Py_make_parameters(PyObject *args)
|
|||
}
|
||||
else {
|
||||
PyObject *subparams;
|
||||
if (_PyObject_LookupAttr(t, &_Py_ID(__parameters__),
|
||||
if (PyObject_GetOptionalAttr(t, &_Py_ID(__parameters__),
|
||||
&subparams) < 0) {
|
||||
Py_DECREF(parameters);
|
||||
return NULL;
|
||||
|
@ -310,7 +310,7 @@ subs_tvars(PyObject *obj, PyObject *params,
|
|||
PyObject **argitems, Py_ssize_t nargs)
|
||||
{
|
||||
PyObject *subparams;
|
||||
if (_PyObject_LookupAttr(obj, &_Py_ID(__parameters__), &subparams) < 0) {
|
||||
if (PyObject_GetOptionalAttr(obj, &_Py_ID(__parameters__), &subparams) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
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
|
||||
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) {
|
||||
res = PyObject_IsTrue(tmp);
|
||||
Py_DECREF(tmp);
|
||||
|
@ -383,7 +383,7 @@ _unpacked_tuple_args(PyObject *arg)
|
|||
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) {
|
||||
Py_DECREF(result);
|
||||
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++) {
|
||||
PyObject *param = PyTuple_GET_ITEM(parameters, i);
|
||||
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);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -503,7 +503,7 @@ _Py_subs_parameters(PyObject *self, PyObject *args, PyObject *parameters, PyObje
|
|||
return NULL;
|
||||
}
|
||||
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(item);
|
||||
return NULL;
|
||||
|
|
|
@ -317,7 +317,7 @@ gen_close_iter(PyObject *yf)
|
|||
}
|
||||
else {
|
||||
PyObject *meth;
|
||||
if (_PyObject_LookupAttr(yf, &_Py_ID(close), &meth) < 0) {
|
||||
if (PyObject_GetOptionalAttr(yf, &_Py_ID(close), &meth) < 0) {
|
||||
PyErr_WriteUnraisable(yf);
|
||||
}
|
||||
if (meth) {
|
||||
|
@ -492,7 +492,7 @@ _gen_throw(PyGenObject *gen, int close_on_genexit,
|
|||
} else {
|
||||
/* `yf` is an iterator or a coroutine-like object. */
|
||||
PyObject *meth;
|
||||
if (_PyObject_LookupAttr(yf, &_Py_ID(throw), &meth) < 0) {
|
||||
if (PyObject_GetOptionalAttr(yf, &_Py_ID(throw), &meth) < 0) {
|
||||
Py_DECREF(yf);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -742,7 +742,7 @@ _PyModuleSpec_IsInitializing(PyObject *spec)
|
|||
{
|
||||
if (spec != NULL) {
|
||||
PyObject *value;
|
||||
int ok = _PyObject_LookupAttr(spec, &_Py_ID(_initializing), &value);
|
||||
int ok = PyObject_GetOptionalAttr(spec, &_Py_ID(_initializing), &value);
|
||||
if (ok == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -2154,7 +2154,7 @@ mutablemapping_update_arg(PyObject *self, PyObject *arg)
|
|||
return res;
|
||||
}
|
||||
PyObject *func;
|
||||
if (_PyObject_LookupAttr(arg, &_Py_ID(keys), &func) < 0) {
|
||||
if (PyObject_GetOptionalAttr(arg, &_Py_ID(keys), &func) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (func != NULL) {
|
||||
|
@ -2186,7 +2186,7 @@ mutablemapping_update_arg(PyObject *self, PyObject *arg)
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
if (_PyObject_LookupAttr(arg, &_Py_ID(items), &func) < 0) {
|
||||
if (PyObject_GetOptionalAttr(arg, &_Py_ID(items), &func) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (func != NULL) {
|
||||
|
|
|
@ -2359,7 +2359,7 @@ static PyObject *
|
|||
class_name(PyObject *cls)
|
||||
{
|
||||
PyObject *name;
|
||||
if (_PyObject_LookupAttr(cls, &_Py_ID(__name__), &name) == 0) {
|
||||
if (PyObject_GetOptionalAttr(cls, &_Py_ID(__name__), &name) == 0) {
|
||||
name = PyObject_Repr(cls);
|
||||
}
|
||||
return name;
|
||||
|
@ -3865,7 +3865,7 @@ type_new_get_bases(type_new_ctx *ctx, PyObject **type)
|
|||
continue;
|
||||
}
|
||||
PyObject *mro_entries;
|
||||
if (_PyObject_LookupAttr(base, &_Py_ID(__mro_entries__),
|
||||
if (PyObject_GetOptionalAttr(base, &_Py_ID(__mro_entries__),
|
||||
&mro_entries) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -5147,7 +5147,7 @@ merge_class_dict(PyObject *dict, PyObject *aclass)
|
|||
assert(aclass);
|
||||
|
||||
/* 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;
|
||||
}
|
||||
if (classdict != NULL) {
|
||||
|
@ -5158,7 +5158,7 @@ merge_class_dict(PyObject *dict, PyObject *aclass)
|
|||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
if (bases != NULL) {
|
||||
|
@ -5984,7 +5984,7 @@ object_getstate_default(PyObject *obj, int required)
|
|||
PyObject *name, *value;
|
||||
|
||||
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);
|
||||
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;
|
||||
}
|
||||
if (reduce != NULL) {
|
||||
|
@ -6500,7 +6500,7 @@ object___dir___impl(PyObject *self)
|
|||
PyObject *itsclass = NULL;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
if (dict == NULL) {
|
||||
|
@ -6520,7 +6520,7 @@ object___dir___impl(PyObject *self)
|
|||
goto error;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
/* 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;
|
||||
int ok;
|
||||
|
||||
if (_PyObject_LookupAttr((PyObject *)(Py_TYPE(right)), name, &b) < 0) {
|
||||
if (PyObject_GetOptionalAttr((PyObject *)(Py_TYPE(right)), name, &b) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (b == NULL) {
|
||||
|
@ -8401,7 +8401,7 @@ method_is_overloaded(PyObject *left, PyObject *right, PyObject *name)
|
|||
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);
|
||||
return -1;
|
||||
}
|
||||
|
@ -10373,7 +10373,7 @@ supercheck(PyTypeObject *type, PyObject *obj)
|
|||
/* Try the slow way */
|
||||
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;
|
||||
}
|
||||
if (class_attr != NULL &&
|
||||
|
|
|
@ -194,13 +194,13 @@ union_repr_item(_PyUnicodeWriter *writer, PyObject *p)
|
|||
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;
|
||||
}
|
||||
|
||||
if (tmp) {
|
||||
Py_DECREF(tmp);
|
||||
if (_PyObject_LookupAttr(p, &_Py_ID(__args__), &tmp) < 0) {
|
||||
if (PyObject_GetOptionalAttr(p, &_Py_ID(__args__), &tmp) < 0) {
|
||||
goto exit;
|
||||
}
|
||||
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;
|
||||
}
|
||||
if (qualname == NULL) {
|
||||
goto use_repr;
|
||||
}
|
||||
if (_PyObject_LookupAttr(p, &_Py_ID(__module__), &module) < 0) {
|
||||
if (PyObject_GetOptionalAttr(p, &_Py_ID(__module__), &module) < 0) {
|
||||
goto exit;
|
||||
}
|
||||
if (module == NULL || module == Py_None) {
|
||||
|
|
|
@ -629,7 +629,7 @@ class Obj2ModVisitor(PickleVisitor):
|
|||
|
||||
def visitField(self, field, name, sum=None, prod=None, depth=0):
|
||||
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("return 1;", depth+1)
|
||||
self.emit("}", depth)
|
||||
|
@ -813,7 +813,7 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
|
|||
Py_ssize_t i, numfields = 0;
|
||||
int res = -1;
|
||||
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;
|
||||
}
|
||||
if (fields) {
|
||||
|
@ -887,7 +887,7 @@ ast_type_reduce(PyObject *self, PyObject *unused)
|
|||
}
|
||||
|
||||
PyObject *dict;
|
||||
if (_PyObject_LookupAttr(self, state->__dict__, &dict) < 0) {
|
||||
if (PyObject_GetOptionalAttr(self, state->__dict__, &dict) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
(void)_PyObject_LookupAttr(warnings_module, attr, &obj);
|
||||
(void)PyObject_GetOptionalAttr(warnings_module, attr, &obj);
|
||||
Py_DECREF(warnings_module);
|
||||
return obj;
|
||||
}
|
||||
|
@ -1069,7 +1069,7 @@ get_source_line(PyInterpreterState *interp, PyObject *module_globals, int lineno
|
|||
Py_INCREF(module_name);
|
||||
|
||||
/* 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);
|
||||
if (!get_source) {
|
||||
Py_DECREF(module_name);
|
||||
|
|
|
@ -34,7 +34,7 @@ update_bases(PyObject *bases, PyObject *const *args, Py_ssize_t nargs)
|
|||
}
|
||||
continue;
|
||||
}
|
||||
if (_PyObject_LookupAttr(base, &_Py_ID(__mro_entries__), &meth) < 0) {
|
||||
if (PyObject_GetOptionalAttr(base, &_Py_ID(__mro_entries__), &meth) < 0) {
|
||||
goto error;
|
||||
}
|
||||
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
|
||||
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;
|
||||
}
|
||||
else if (prep == NULL) {
|
||||
|
@ -1160,7 +1160,7 @@ builtin_getattr_impl(PyObject *module, PyObject *object, PyObject *name,
|
|||
PyObject *result;
|
||||
|
||||
if (default_value != NULL) {
|
||||
if (_PyObject_LookupAttr(object, name, &result) == 0) {
|
||||
if (PyObject_GetOptionalAttr(object, name, &result) == 0) {
|
||||
return Py_NewRef(default_value);
|
||||
}
|
||||
}
|
||||
|
@ -1209,7 +1209,7 @@ builtin_hasattr_impl(PyObject *module, PyObject *obj, PyObject *name)
|
|||
{
|
||||
PyObject *v;
|
||||
|
||||
if (_PyObject_LookupAttr(obj, name, &v) < 0) {
|
||||
if (PyObject_GetOptionalAttr(obj, name, &v) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (v == NULL) {
|
||||
|
@ -2465,7 +2465,7 @@ builtin_vars_impl(PyObject *module, PyObject *object)
|
|||
d = _PyEval_GetFrameLocals();
|
||||
}
|
||||
else {
|
||||
if (_PyObject_LookupAttr(object, &_Py_ID(__dict__), &d) == 0) {
|
||||
if (PyObject_GetOptionalAttr(object, &_Py_ID(__dict__), &d) == 0) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"vars() argument must have __dict__ attribute");
|
||||
}
|
||||
|
|
|
@ -419,7 +419,7 @@ match_class_attr(PyThreadState *tstate, PyObject *subject, PyObject *type,
|
|||
return NULL;
|
||||
}
|
||||
PyObject *attr;
|
||||
(void)_PyObject_LookupAttr(subject, name, &attr);
|
||||
(void)PyObject_GetOptionalAttr(subject, name, &attr);
|
||||
return attr;
|
||||
}
|
||||
|
||||
|
@ -454,7 +454,7 @@ match_class(PyThreadState *tstate, PyObject *subject, PyObject *type,
|
|||
// First, the positional subpatterns:
|
||||
if (nargs) {
|
||||
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;
|
||||
}
|
||||
if (match_args) {
|
||||
|
@ -2414,7 +2414,7 @@ import_from(PyThreadState *tstate, PyObject *v, PyObject *name)
|
|||
PyObject *x;
|
||||
PyObject *fullmodname, *pkgname, *pkgpath, *pkgname_or_unknown, *errmsg;
|
||||
|
||||
if (_PyObject_LookupAttr(v, name, &x) != 0) {
|
||||
if (PyObject_GetOptionalAttr(v, name, &x) != 0) {
|
||||
return x;
|
||||
}
|
||||
/* Issue #17636: in case this failed because of a circular relative
|
||||
|
|
|
@ -516,7 +516,7 @@ PyObject * _PyCodec_LookupTextEncoding(const char *encoding,
|
|||
* attribute.
|
||||
*/
|
||||
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);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -1748,7 +1748,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset,
|
|||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
else if (tmp) {
|
||||
|
|
|
@ -2878,7 +2878,7 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
|
|||
}
|
||||
else {
|
||||
PyObject *path;
|
||||
if (_PyObject_LookupAttr(mod, &_Py_ID(__path__), &path) < 0) {
|
||||
if (PyObject_GetOptionalAttr(mod, &_Py_ID(__path__), &path) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (path) {
|
||||
|
|
|
@ -40,11 +40,11 @@ import_all_from(PyThreadState *tstate, PyObject *locals, PyObject *v)
|
|||
int skip_leading_underscores = 0;
|
||||
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 */
|
||||
}
|
||||
if (all == NULL) {
|
||||
if (_PyObject_LookupAttr(v, &_Py_ID(__dict__), &dict) < 0) {
|
||||
if (PyObject_GetOptionalAttr(v, &_Py_ID(__dict__), &dict) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (dict == NULL) {
|
||||
|
|
|
@ -953,7 +953,7 @@ print_exception_file_and_line(struct exception_print_context *ctx,
|
|||
PyObject *f = ctx->file;
|
||||
|
||||
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) {
|
||||
PyErr_Clear();
|
||||
|
@ -1132,7 +1132,7 @@ print_exception_notes(struct exception_print_context *ctx, PyObject *value)
|
|||
}
|
||||
|
||||
PyObject *notes;
|
||||
int res = _PyObject_LookupAttr(value, &_Py_ID(__notes__), ¬es);
|
||||
int res = PyObject_GetOptionalAttr(value, &_Py_ID(__notes__), ¬es);
|
||||
if (res <= 0) {
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -247,7 +247,7 @@ get_suggestions_for_name_error(PyObject* name, PyFrameObject* frame)
|
|||
}
|
||||
|
||||
PyObject *value;
|
||||
res = _PyObject_LookupAttr(self, name, &value);
|
||||
res = PyObject_GetOptionalAttr(self, name, &value);
|
||||
Py_DECREF(locals);
|
||||
if (res < 0) {
|
||||
goto error;
|
||||
|
|
|
@ -257,7 +257,7 @@ sys_audit_tstate(PyThreadState *ts, const char *event,
|
|||
PyThreadState_EnterTracing(ts);
|
||||
while ((hook = PyIter_Next(hooks)) != NULL) {
|
||||
PyObject *o;
|
||||
int canTrace = _PyObject_LookupAttr(hook, &_Py_ID(__cantrace__), &o);
|
||||
int canTrace = PyObject_GetOptionalAttr(hook, &_Py_ID(__cantrace__), &o);
|
||||
if (o) {
|
||||
canTrace = PyObject_IsTrue(o);
|
||||
Py_DECREF(o);
|
||||
|
@ -657,7 +657,7 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o)
|
|||
if (encoded == NULL)
|
||||
goto error;
|
||||
|
||||
if (_PyObject_LookupAttr(outf, &_Py_ID(buffer), &buffer) < 0) {
|
||||
if (PyObject_GetOptionalAttr(outf, &_Py_ID(buffer), &buffer) < 0) {
|
||||
Py_DECREF(encoded);
|
||||
goto error;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue