summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2023-10-16 15:01:04 (GMT)
committerGitHub <noreply@github.com>2023-10-16 15:01:04 (GMT)
commit6a4528d70c8435d4403e09937068a446f35a78ac (patch)
tree7ca52ef5d49a09c9dc7f46d1a1b5af9680231494
parent02d26c4bef3ad0f9c97e47993a7fa67898842e5c (diff)
downloadcpython-6a4528d70c8435d4403e09937068a446f35a78ac.zip
cpython-6a4528d70c8435d4403e09937068a446f35a78ac.tar.gz
cpython-6a4528d70c8435d4403e09937068a446f35a78ac.tar.bz2
gh-110864: TypeVar constructor: Partially revert gh-110784, `constraints` cannot be `NULL` (#110922)
-rw-r--r--Objects/typevarobject.c34
1 files changed, 14 insertions, 20 deletions
diff --git a/Objects/typevarobject.c b/Objects/typevarobject.c
index 51424ff..7f80c9c 100644
--- a/Objects/typevarobject.c
+++ b/Objects/typevarobject.c
@@ -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) {