8000 bpo-41559: Convert lists to tuples in genericalias to prepare for PEP 612 by Fidget-Spinner · Pull Request #24056 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-41559: Convert lists to tuples in genericalias to prepare for PEP 612 #24056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Prev Previous commit
Next Next commit
clean up code a little
  • Loading branch information
Fidget-Spinner committed Feb 4, 2021
commit 0389d960f267f7dbc9d62a3fcb33f859767f7100
51 changes: 27 additions & 24 deletions Objects/genericaliasobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,37 +244,40 @@ tupleify_lists(PyObject *args) {
}
for (Py_ssize_t i = 0; i < len; ++i) {
PyObject *arg = PyTuple_GET_ITEM(result, i);
int is_list = PyList_CheckExact(arg);
int is_tuple = PyTuple_CheckExact(arg);
if (is_list || is_tuple) {
// In case there are lists nested inside tuples.
PyObject *new_arg = is_list ? PyList_AsTuple(arg) : arg;
if (arg == NULL) {
goto error;
}
PyObject *new_arg = NULL;
if (PyList_CheckExact(arg)) {
new_arg = PyList_AsTuple(arg);
if (new_arg == NULL) {
goto error;
}
if (is_list) {
// Discard old arg since AsTuple gives a new reference.
Py_DECREF(arg);
}
if (Py_EnterRecursiveCall(" while converting lists to tuples in "
"GenericAlias' __args__")) {
goto error;
}
PyObject *new_arg_tupled = tupleify_lists(new_arg);
Py_LeaveRecursiveCall();
Py_DECREF(new_arg);
if (new_arg_tupled == NULL) {
goto error;
}
PyTuple_SET_ITEM(result, i, new_arg_tupled);
Py_DECREF(arg);
}
else if (PyTuple_CheckExact(arg)) {
new_arg = arg;
}
else {
continue;

error:
Py_DECREF(result);
return NULL;
}
if (Py_EnterRecursiveCall(" while converting lists to tuples in "
"GenericAlias' __args__")) {
goto error;
}
PyObject *new_arg_tupled = tupleify_lists(new_arg);
Py_DECREF(new_arg);
Py_LeaveRecursiveCall();
if (new_arg_tupled == NULL) {
goto error;
}
PyTuple_SET_ITEM(result, i, new_arg_tupled);
}
return result;

error:
Py_DECREF(result);
return NULL;
}

static PyObject *
Expand Down
0