Skip to content

Commit

Permalink
pythongh-110784: Partially revert pythongh-110784, constraints cann…
Browse files Browse the repository at this point in the history
…ot be `NULL`
  • Loading branch information
sobolevn committed Oct 16, 2023
1 parent c2192a2 commit b5f4f5c
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions Objects/typevarobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,26 +364,24 @@ typevar_new_impl(PyTypeObject *type, PyObject *name, PyObject *constraints,
}
}

if (constraints != NULL) {
if (!PyTuple_CheckExact(constraints)) {
PyErr_SetString(PyExc_TypeError,
"constraints must be a tuple");
return NULL;
}
Py_ssize_t n_constraints = PyTuple_GET_SIZE(constraints);
if (n_constraints == 1) {
PyErr_SetString(PyExc_TypeError,
"A single constraint is not allowed");
Py_XDECREF(bound);
return NULL;
} else if (n_constraints == 0) {
constraints = NULL;
} else if (bound != NULL) {
PyErr_SetString(PyExc_TypeError,
"Constraints cannot be combined with bound=...");
Py_XDECREF(bound);
return NULL;
}
if (!PyTuple_CheckExact(constraints)) {
PyErr_SetString(PyExc_TypeError,
"Constraints must be a tuple");
return NULL;
}
Py_ssize_t n_constraints = PyTuple_GET_SIZE(constraints);
if (n_constraints == 1) {
PyErr_SetString(PyExc_TypeError,
"A single constraint is not allowed");
Py_XDECREF(bound);
return NULL;
} else if (n_constraints == 0) {
constraints = NULL;
} else if (bound != NULL) {
PyErr_SetString(PyExc_TypeError,
"Constraints cannot be combined with bound=...");
Py_XDECREF(bound);
return NULL;
}
PyObject *module = caller();
if (module == NULL) {
Expand Down

0 comments on commit b5f4f5c

Please sign in to comment.