summaryrefslogtreecommitdiffstats
path: root/Objects
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 /Objects
parente8ab0096a583184fe24dfbc39eff70d270c8e6f4 (diff)
downloadcpython-be1b968dc1e63c3c68e161ddc5a05eb064833440.zip
cpython-be1b968dc1e63c3c68e161ddc5a05eb064833440.tar.gz
cpython-be1b968dc1e63c3c68e161ddc5a05eb064833440.tar.bz2
gh-106521: Remove _PyObject_LookupAttr() function (GH-106642)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/abstract.c8
-rw-r--r--Objects/call.c2
-rw-r--r--Objects/classobject.c6
-rw-r--r--Objects/descrobject.c2
-rw-r--r--Objects/dictobject.c2
-rw-r--r--Objects/exceptions.c4
-rw-r--r--Objects/fileobject.c2
-rw-r--r--Objects/funcobject.c2
-rw-r--r--Objects/genericaliasobject.c22
-rw-r--r--Objects/genobject.c4
-rw-r--r--Objects/moduleobject.c2
-rw-r--r--Objects/odictobject.c4
-rw-r--r--Objects/typeobject.c22
-rw-r--r--Objects/unionobject.c8
14 files changed, 45 insertions, 45 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index e595bc9..b4edcec 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -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);
diff --git a/Objects/call.c b/Objects/call.c
index 5045c0d..396552d 100644
--- a/Objects/call.c
+++ b/Objects/call.c
@@ -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);
}
diff --git a/Objects/classobject.c b/Objects/classobject.c
index 71c4a4e..548b867 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -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)) {
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index a814902..810bd19 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -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;
}
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 194081d..013c218 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -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) {
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 85cf2cc..42c5317 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -208,7 +208,7 @@ BaseException_add_note(PyObject *self, PyObject *note)
}
PyObject *notes;
- if (_PyObject_LookupAttr(self, &_Py_ID(__notes__), &notes) < 0) {
+ if (PyObject_GetOptionalAttr(self, &_Py_ID(__notes__), &notes) < 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__), &notes) < 0) {
+ if (PyObject_GetOptionalAttr(orig, &_Py_ID(__notes__), &notes) < 0) {
goto error;
}
if (notes) {
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index 6d980a1..751fb69 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -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) {
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index a8a9ee2..0c69bf4 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -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);
diff --git a/Objects/genericaliasobject.c b/Objects/genericaliasobject.c
index 117b4e8..0c478f3 100644
--- a/Objects/genericaliasobject.c
+++ b/Objects/genericaliasobject.c
@@ -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;
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 6f0f02c..103e8b8 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -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;
}
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index 3e500b5..4071b5a 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -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;
}
diff --git a/Objects/odictobject.c b/Objects/odictobject.c
index 39b0f68..e76d2de 100644
--- a/Objects/odictobject.c
+++ b/Objects/odictobject.c
@@ -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) {
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 5430924..b1f9f12 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -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 &&
diff --git a/Objects/unionobject.c b/Objects/unionobject.c
index f509a16..269f469 100644
--- a/Objects/unionobject.c
+++ b/Objects/unionobject.c
@@ -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) {