summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-07-12 05:57:10 (GMT)
committerGitHub <noreply@github.com>2023-07-12 05:57:10 (GMT)
commitbe1b968dc1e63c3c68e161ddc5a05eb064833440 (patch)
tree8689ba9f656854b83bf24b82de4fc471437a51ab /Modules
parente8ab0096a583184fe24dfbc39eff70d270c8e6f4 (diff)
downloadcpython-be1b968dc1e63c3c68e161ddc5a05eb064833440.zip
cpython-be1b968dc1e63c3c68e161ddc5a05eb064833440.tar.gz
cpython-be1b968dc1e63c3c68e161ddc5a05eb064833440.tar.bz2
gh-106521: Remove _PyObject_LookupAttr() function (GH-106642)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_abc.c4
-rw-r--r--Modules/_asynciomodule.c4
-rw-r--r--Modules/_csv.c2
-rw-r--r--Modules/_ctypes/_ctypes.c22
-rw-r--r--Modules/_ctypes/callproc.c2
-rw-r--r--Modules/_ctypes/stgdict.c6
-rw-r--r--Modules/_datetimemodule.c2
-rw-r--r--Modules/_elementtree.c2
-rw-r--r--Modules/_io/bufferedio.c4
-rw-r--r--Modules/_io/fileio.c2
-rw-r--r--Modules/_io/iobase.c8
-rw-r--r--Modules/_io/textio.c12
-rw-r--r--Modules/_pickle.c38
-rw-r--r--Modules/_sqlite/microprotocols.c4
-rw-r--r--Modules/_threadmodule.c2
-rw-r--r--Modules/arraymodule.c2
-rw-r--r--Modules/itertoolsmodule.c2
-rw-r--r--Modules/pyexpat.c2
18 files changed, 60 insertions, 60 deletions
diff --git a/Modules/_abc.c b/Modules/_abc.c
index 93c0a93..8a3aa9c 100644
--- a/Modules/_abc.c
+++ b/Modules/_abc.c
@@ -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;
diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c
index 3b05502..ef9f7f8 100644
--- a/Modules/_asynciomodule.c
+++ b/Modules/_asynciomodule.c
@@ -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) {
diff --git a/Modules/_csv.c b/Modules/_csv.c
index 5b501af..c36d980 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -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);
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index a9d8a2b..7624c15 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -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;
diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c
index d2fe525..b3831ae 100644
--- a/Modules/_ctypes/callproc.c
+++ b/Modules/_ctypes/callproc.c
@@ -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?
diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c
index b1b2bac..3348ebd 100644
--- a/Modules/_ctypes/stgdict.c
+++ b/Modules/_ctypes/stgdict.c
@@ -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) {
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index db2d339..b8cb0c01 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -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) {
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index 3e742e0..a8d68d6 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -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.",
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
index e58e879..bfc3d25 100644
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -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) {
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 1a5b613..39709fd 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -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) {
diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c
index 729a708..e2e8ef4 100644
--- a/Modules/_io/iobase.c
+++ b/Modules/_io/iobase.c
@@ -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;
}
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index f704875..a5cf9fc 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -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;
}
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index 5ecf7ca..ea44b49 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -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;
}
diff --git a/Modules/_sqlite/microprotocols.c b/Modules/_sqlite/microprotocols.c
index 148220d..92f0148 100644
--- a/Modules/_sqlite/microprotocols.c
+++ b/Modules/_sqlite/microprotocols.c
@@ -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) {
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index f570b4e..8239330 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -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;
}
}
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index f43a234..0000a8d 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -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) {
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 13ff253..f5f7bf3 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -1146,7 +1146,7 @@ itertools_tee_impl(PyObject *module, PyObject *iterable, Py_ssize_t n)
return NULL;
}
- if (_PyObject_LookupAttr(it, &_Py_ID(__copy__), &copyfunc) < 0) {
+ if (PyObject_GetOptionalAttr(it, &_Py_ID(__copy__), &copyfunc) < 0) {
Py_DECREF(it);
Py_DECREF(result);
return NULL;
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index 2891535..5721ed4 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -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) {