summaryrefslogtreecommitdiffstats
path: root/Objects/genericaliasobject.c
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2023-07-01 00:04:50 (GMT)
committerGitHub <noreply@github.com>2023-07-01 00:04:50 (GMT)
commiteb7d6e7ad844955f9af88707d296e003c7ce4394 (patch)
tree952b2865e9612414c207b9deb1cc10e0b14e9956 /Objects/genericaliasobject.c
parente212618bafaa4f775502e3442de0affb80205b5e (diff)
downloadcpython-eb7d6e7ad844955f9af88707d296e003c7ce4394.zip
cpython-eb7d6e7ad844955f9af88707d296e003c7ce4394.tar.gz
cpython-eb7d6e7ad844955f9af88707d296e003c7ce4394.tar.bz2
gh-105486: Change the `repr` of `ParamSpec` list of args in `GenericAlias` (#105488)
Diffstat (limited to 'Objects/genericaliasobject.c')
-rw-r--r--Objects/genericaliasobject.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/Objects/genericaliasobject.c b/Objects/genericaliasobject.c
index 888cb16..117b4e8 100644
--- a/Objects/genericaliasobject.c
+++ b/Objects/genericaliasobject.c
@@ -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;
}
}