Skip to content

Commit

Permalink
gh-110864: TypeVar constructor: Partially revert gh-110784, `constrai…
Browse files Browse the repository at this point in the history
…nts` cannot be `NULL` (#110922)
  • Loading branch information
sobolevn authored Oct 16, 2023
1 parent 02d26c4 commit 6a4528d
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions Objects/typevarobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,26 +363,20 @@ 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;
}
assert(PyTuple_CheckExact(constraints));
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 6a4528d

Please sign in to comment.