aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Objects/genericaliasobject.c
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-02-12 07:53:52 +0300
committershadchin <shadchin@yandex-team.com>2024-02-12 08:07:36 +0300
commitce1b7ca3171f9158180640c6a02a74b4afffedea (patch)
treee47c1e8391b1b0128262c1e9b1e6ed4c8fff2348 /contrib/tools/python3/src/Objects/genericaliasobject.c
parent57350d96f030db90f220ce50ee591d5c5d403df7 (diff)
downloadydb-ce1b7ca3171f9158180640c6a02a74b4afffedea.tar.gz
Update Python from 3.11.8 to 3.12.2
Diffstat (limited to 'contrib/tools/python3/src/Objects/genericaliasobject.c')
-rw-r--r--contrib/tools/python3/src/Objects/genericaliasobject.c62
1 files changed, 45 insertions, 17 deletions
diff --git a/contrib/tools/python3/src/Objects/genericaliasobject.c b/contrib/tools/python3/src/Objects/genericaliasobject.c
index 139bab7e6c..117b4e8dfb 100644
--- a/contrib/tools/python3/src/Objects/genericaliasobject.c
+++ b/contrib/tools/python3/src/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;
}
}
@@ -183,8 +219,7 @@ static int
tuple_add(PyObject *self, Py_ssize_t len, PyObject *item)
{
if (tuple_index(self, len, item) < 0) {
- Py_INCREF(item);
- PyTuple_SET_ITEM(self, len, item);
+ PyTuple_SET_ITEM(self, len, Py_NewRef(item));
return 1;
}
return 0;
@@ -201,8 +236,7 @@ tuple_extend(PyObject **dst, Py_ssize_t dstindex,
assert(dstindex + count <= PyTuple_GET_SIZE(*dst));
for (Py_ssize_t i = 0; i < count; ++i) {
PyObject *item = src[i];
- Py_INCREF(item);
- PyTuple_SET_ITEM(*dst, dstindex + i, item);
+ PyTuple_SET_ITEM(*dst, dstindex + i, Py_NewRef(item));
}
return dstindex + count;
}
@@ -304,8 +338,7 @@ subs_tvars(PyObject *obj, PyObject *params,
continue;
}
}
- Py_INCREF(arg);
- PyTuple_SET_ITEM(subargs, j, arg);
+ PyTuple_SET_ITEM(subargs, j, Py_NewRef(arg));
j++;
}
assert(j == PyTuple_GET_SIZE(subargs));
@@ -347,8 +380,7 @@ _unpacked_tuple_args(PyObject *arg)
((gaobject *)arg)->origin == (PyObject *)&PyTuple_Type)
{
result = ((gaobject *)arg)->args;
- Py_INCREF(result);
- return result;
+ return Py_NewRef(result);
}
if (_PyObject_LookupAttr(arg, &_Py_ID(__typing_unpacked_tuple_args__), &result) > 0) {
@@ -459,8 +491,7 @@ _Py_subs_parameters(PyObject *self, PyObject *args, PyObject *parameters, PyObje
for (Py_ssize_t iarg = 0, jarg = 0; iarg < nargs; iarg++) {
PyObject *arg = PyTuple_GET_ITEM(args, iarg);
if (PyType_Check(arg)) {
- Py_INCREF(arg);
- PyTuple_SET_ITEM(newargs, jarg, arg);
+ PyTuple_SET_ITEM(newargs, jarg, Py_NewRef(arg));
jarg++;
continue;
}
@@ -767,8 +798,7 @@ ga_parameters(PyObject *self, void *unused)
return NULL;
}
}
- Py_INCREF(alias->parameters);
- return alias->parameters;
+ return Py_NewRef(alias->parameters);
}
static PyObject *
@@ -776,8 +806,7 @@ ga_unpacked_tuple_args(PyObject *self, void *unused)
{
gaobject *alias = (gaobject *)self;
if (alias->starred && alias->origin == (PyObject *)&PyTuple_Type) {
- Py_INCREF(alias->args);
- return alias->args;
+ return Py_NewRef(alias->args);
}
Py_RETURN_NONE;
}
@@ -803,8 +832,7 @@ setup_ga(gaobject *alias, PyObject *origin, PyObject *args) {
Py_INCREF(args);
}
- Py_INCREF(origin);
- alias->origin = origin;
+ alias->origin = Py_NewRef(origin);
alias->args = args;
alias->parameters = NULL;
alias->weakreflist = NULL;