mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
gh-108511: Add C API functions which do not silently ignore errors (GH-109025)
Add the following functions: * PyObject_HasAttrWithError() * PyObject_HasAttrStringWithError() * PyMapping_HasKeyWithError() * PyMapping_HasKeyStringWithError()
This commit is contained in:
parent
e57ecf6bbc
commit
add16f1a5e
28 changed files with 330 additions and 111 deletions
|
|
@ -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 @@ ga_repr_item(_PyUnicodeWriter *writer, PyObject *p)
|
|||
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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue