Skip to content

Commit 50d2d0c

Browse files
committed
Preserve the type (list/tuple) of nested arguments
1 parent 51399e3 commit 50d2d0c

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

Objects/genericaliasobject.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -476,15 +476,22 @@ _Py_subs_parameters(PyObject *self, PyObject *args, PyObject *parameters, PyObje
476476
Py_XDECREF(tuple_args);
477477
return NULL;
478478
}
479-
PyObject *subargs_list = PySequence_List(subargs);
480-
Py_DECREF(subargs);
481-
if (subargs_list == NULL) {
482-
Py_DECREF(newargs);
483-
Py_DECREF(item);
484-
Py_XDECREF(tuple_args);
485-
return NULL;
479+
if (PyTuple_Check(arg)) {
480+
PyTuple_SET_ITEM(newargs, jarg, subargs);
481+
}
482+
else {
483+
// _Py_subs_parameters returns a tuple. If the original arg was a list,
484+
// convert subargs to a list as well.
485+
PyObject *subargs_list = PySequence_List(subargs);
486+
Py_DECREF(subargs);
487+
if (subargs_list == NULL) {
488+
Py_DECREF(newargs);
489+
Py_DECREF(item);
490+
Py_XDECREF(tuple_args);
491+
return NULL;
492+
}
493+
PyTuple_SET_ITEM(newargs, jarg, subargs_list);
486494
}
487-
PyTuple_SET_ITEM(newargs, jarg, subargs_list);
488495
jarg++;
489496
continue;
490497
}

0 commit comments

Comments
 (0)