mirror of https://github.com/python/cpython
gh-110864: TypeVar constructor: Partially revert gh-110784, `constraints` cannot be `NULL` (#110922)
This commit is contained in:
parent
02d26c4bef
commit
6a4528d70c
|
@ -363,26 +363,20 @@ typevar_new_impl(PyTypeObject *type, PyObject *name, PyObject *constraints,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (constraints != NULL) {
|
assert(PyTuple_CheckExact(constraints));
|
||||||
if (!PyTuple_CheckExact(constraints)) {
|
Py_ssize_t n_constraints = PyTuple_GET_SIZE(constraints);
|
||||||
PyErr_SetString(PyExc_TypeError,
|
if (n_constraints == 1) {
|
||||||
"constraints must be a tuple");
|
PyErr_SetString(PyExc_TypeError,
|
||||||
return NULL;
|
"A single constraint is not allowed");
|
||||||
}
|
Py_XDECREF(bound);
|
||||||
Py_ssize_t n_constraints = PyTuple_GET_SIZE(constraints);
|
return NULL;
|
||||||
if (n_constraints == 1) {
|
} else if (n_constraints == 0) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
constraints = NULL;
|
||||||
"A single constraint is not allowed");
|
} else if (bound != NULL) {
|
||||||
Py_XDECREF(bound);
|
PyErr_SetString(PyExc_TypeError,
|
||||||
return NULL;
|
"Constraints cannot be combined with bound=...");
|
||||||
} else if (n_constraints == 0) {
|
Py_XDECREF(bound);
|
||||||
constraints = NULL;
|
return NULL;
|
||||||
} else if (bound != NULL) {
|
|
||||||
PyErr_SetString(PyExc_TypeError,
|
|
||||||
"Constraints cannot be combined with bound=...");
|
|
||||||
Py_XDECREF(bound);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
PyObject *module = caller();
|
PyObject *module = caller();
|
||||||
if (module == NULL) {
|
if (module == NULL) {
|
||||||
|
|
Loading…
Reference in New Issue