diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2021-07-22 21:57:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-22 21:57:06 (GMT) |
commit | 2e3744d50b6e30ea24351e55b4352dcc58fd469e (patch) | |
tree | de5f74f9bb97671319cdd7e6eab89b2975c2c4ff /Objects | |
parent | 96c4cbd96c769e92869c62ba898dd9eb670baa81 (diff) | |
download | cpython-2e3744d50b6e30ea24351e55b4352dcc58fd469e.zip cpython-2e3744d50b6e30ea24351e55b4352dcc58fd469e.tar.gz cpython-2e3744d50b6e30ea24351e55b4352dcc58fd469e.tar.bz2 |
bpo-44653: Support typing types in parameter substitution in the union type. (GH-27247)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/unionobject.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/Objects/unionobject.c b/Objects/unionobject.c index c0c9a24..659346a 100644 --- a/Objects/unionobject.c +++ b/Objects/unionobject.c @@ -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; } |