mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-44653: Support typing types in parameter substitution in the union type. (GH-27247)
This commit is contained in:
parent
96c4cbd96c
commit
2e3744d50b
3 changed files with 43 additions and 13 deletions
|
@ -446,23 +446,22 @@ union_getitem(PyObject *self, PyObject *item)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
// Check arguments are unionable.
|
||||
PyObject *res;
|
||||
Py_ssize_t nargs = PyTuple_GET_SIZE(newargs);
|
||||
for (Py_ssize_t iarg = 0; iarg < nargs; iarg++) {
|
||||
PyObject *arg = PyTuple_GET_ITEM(newargs, iarg);
|
||||
int is_arg_unionable = is_unionable(arg);
|
||||
if (is_arg_unionable <= 0) {
|
||||
Py_DECREF(newargs);
|
||||
if (is_arg_unionable == 0) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"Each union argument must be a type, got %.100R", arg);
|
||||
if (nargs == 0) {
|
||||
res = make_union(newargs);
|
||||
}
|
||||
else {
|
||||
res = PyTuple_GET_ITEM(newargs, 0);
|
||||
Py_INCREF(res);
|
||||
for (Py_ssize_t iarg = 1; iarg < nargs; iarg++) {
|
||||
PyObject *arg = PyTuple_GET_ITEM(newargs, iarg);
|
||||
Py_SETREF(res, PyNumber_Or(res, arg));
|
||||
if (res == NULL) {
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
PyObject *res = make_union(newargs);
|
||||
|
||||
Py_DECREF(newargs);
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue