summaryrefslogtreecommitdiffstats
path: root/Objects/genericaliasobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/genericaliasobject.c')
-rw-r--r--Objects/genericaliasobject.c35
1 files changed, 14 insertions, 21 deletions
diff --git a/Objects/genericaliasobject.c b/Objects/genericaliasobject.c
index ca17244..bf13ed3 100644
--- a/Objects/genericaliasobject.c
+++ b/Objects/genericaliasobject.c
@@ -55,8 +55,7 @@ ga_repr_item(_PyUnicodeWriter *writer, PyObject *p)
PyObject *qualname = NULL;
PyObject *module = NULL;
PyObject *r = NULL;
- PyObject *tmp;
- int err;
+ int rc;
if (p == Py_Ellipsis) {
// The Ellipsis object
@@ -64,19 +63,14 @@ ga_repr_item(_PyUnicodeWriter *writer, PyObject *p)
goto done;
}
- if (PyObject_GetOptionalAttr(p, &_Py_ID(__origin__), &tmp) < 0) {
- goto done;
+ if ((rc = PyObject_HasAttrWithError(p, &_Py_ID(__origin__))) > 0 &&
+ (rc = PyObject_HasAttrWithError(p, &_Py_ID(__args__))) > 0)
+ {
+ // It looks like a GenericAlias
+ goto use_repr;
}
- if (tmp != NULL) {
- Py_DECREF(tmp);
- if (PyObject_GetOptionalAttr(p, &_Py_ID(__args__), &tmp) < 0) {
- goto done;
- }
- if (tmp != NULL) {
- Py_DECREF(tmp);
- // It looks like a GenericAlias
- goto use_repr;
- }
+ if (rc < 0) {
+ goto done;
}
if (PyObject_GetOptionalAttr(p, &_Py_ID(__qualname__), &qualname) < 0) {
@@ -113,13 +107,13 @@ done:
Py_XDECREF(module);
if (r == NULL) {
// error if any of the above PyObject_Repr/PyUnicode_From* fail
- err = -1;
+ rc = -1;
}
else {
- err = _PyUnicodeWriter_WriteStr(writer, r);
+ rc = _PyUnicodeWriter_WriteStr(writer, r);
Py_DECREF(r);
}
- return err;
+ return rc;
}
static int
@@ -253,18 +247,17 @@ _Py_make_parameters(PyObject *args)
Py_ssize_t iparam = 0;
for (Py_ssize_t iarg = 0; iarg < nargs; iarg++) {
PyObject *t = PyTuple_GET_ITEM(args, iarg);
- PyObject *subst;
// We don't want __parameters__ descriptor of a bare Python class.
if (PyType_Check(t)) {
continue;
}
- if (PyObject_GetOptionalAttr(t, &_Py_ID(__typing_subst__), &subst) < 0) {
+ int rc = PyObject_HasAttrWithError(t, &_Py_ID(__typing_subst__));
+ if (rc < 0) {
Py_DECREF(parameters);
return NULL;
}
- if (subst) {
+ if (rc) {
iparam += tuple_add(parameters, iparam, t);
- Py_DECREF(subst);
}
else {
PyObject *subparams;