bpo-41991: Remove _PyObject_HasAttrId (GH-22629)
It can silence arbitrary exceptions.
diff --git a/Objects/object.c b/Objects/object.c
index 9889503..7bc3e48 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -855,17 +855,6 @@
}
int
-_PyObject_HasAttrId(PyObject *v, _Py_Identifier *name)
-{
- int result;
- PyObject *oname = _PyUnicode_FromId(name); /* borrowed */
- if (!oname)
- return -1;
- result = PyObject_HasAttr(v, oname);
- return result;
-}
-
-int
_PyObject_SetAttrId(PyObject *v, _Py_Identifier *name, PyObject *w)
{
int result;
diff --git a/Objects/unionobject.c b/Objects/unionobject.c
index 8cfb2a6..89fdaf4 100644
--- a/Objects/unionobject.c
+++ b/Objects/unionobject.c
@@ -311,21 +311,22 @@
_Py_IDENTIFIER(__args__);
PyObject *qualname = NULL;
PyObject *module = NULL;
+ PyObject *tmp;
PyObject *r = NULL;
int err;
- int has_origin = _PyObject_HasAttrId(p, &PyId___origin__);
- if (has_origin < 0) {
+ if (_PyObject_LookupAttrId(p, &PyId___origin__, &tmp) < 0) {
goto exit;
}
- if (has_origin) {
- int has_args = _PyObject_HasAttrId(p, &PyId___args__);
- if (has_args < 0) {
+ if (tmp) {
+ Py_DECREF(tmp);
+ if (_PyObject_LookupAttrId(p, &PyId___args__, &tmp) < 0) {
goto exit;
}
- if (has_args) {
+ if (tmp) {
// It looks like a GenericAlias
+ Py_DECREF(tmp);
goto use_repr;
}
}