mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
gh-106521: Remove _PyObject_LookupAttr() function (GH-106642)
This commit is contained in:
parent
e8ab0096a5
commit
be1b968dc1
45 changed files with 351 additions and 352 deletions
444
Python/Python-ast.c
generated
444
Python/Python-ast.c
generated
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…
Add table
Add a link
Reference in a new issue