[3.12] gh-105486: Change the repr of ParamSpec list of args in GenericAlias (GH-105488) (#106297)

gh-105486: Change the `repr` of `ParamSpec` list of args in `GenericAlias` (GH-105488)
(cherry picked from commit eb7d6e7ad8)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
Miss Islington (bot) 2023-06-30 17:32:44 -07:00 committed by GitHub
parent 0616c83f57
commit c4298d5c64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 1 deletions

View file

@ -121,6 +121,36 @@ done:
return err;
}
static int
ga_repr_items_list(_PyUnicodeWriter *writer, PyObject *p)
{
assert(PyList_CheckExact(p));
Py_ssize_t len = PyList_GET_SIZE(p);
if (_PyUnicodeWriter_WriteASCIIString(writer, "[", 1) < 0) {
return -1;
}
for (Py_ssize_t i = 0; i < len; i++) {
if (i > 0) {
if (_PyUnicodeWriter_WriteASCIIString(writer, ", ", 2) < 0) {
return -1;
}
}
PyObject *item = PyList_GET_ITEM(p, i);
if (ga_repr_item(writer, item) < 0) {
return -1;
}
}
if (_PyUnicodeWriter_WriteASCIIString(writer, "]", 1) < 0) {
return -1;
}
return 0;
}
static PyObject *
ga_repr(PyObject *self)
{
@ -148,7 +178,13 @@ ga_repr(PyObject *self)
}
}
PyObject *p = PyTuple_GET_ITEM(alias->args, i);
if (ga_repr_item(&writer, p) < 0) {
if (PyList_CheckExact(p)) {
// Looks like we are working with ParamSpec's list of type args:
if (ga_repr_items_list(&writer, p) < 0) {
goto error;
}
}
else if (ga_repr_item(&writer, p) < 0) {
goto error;
}
}