mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
[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:
parent
0616c83f57
commit
c4298d5c64
4 changed files with 62 additions and 1 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue