bpo-41991: Remove _PyObject_HasAttrId (GH-22629)

It can silence arbitrary exceptions.
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;
         }
     }