Skip to content

Commit 88813c3

Browse files
sobolevnGlyphack
authored andcommitted
pythongh-110864: TypeVar constructor: Partially revert pythongh-110784, constraints cannot be NULL (python#110922)
1 parent b8fbc33 commit 88813c3

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

Objects/typevarobject.c

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -363,26 +363,20 @@ typevar_new_impl(PyTypeObject *type, PyObject *name, PyObject *constraints,
363363
}
364364
}
365365

366-
if (constraints != NULL) {
367-
if (!PyTuple_CheckExact(constraints)) {
368-
PyErr_SetString(PyExc_TypeError,
369-
"constraints must be a tuple");
370-
return NULL;
371-
}
372-
Py_ssize_t n_constraints = PyTuple_GET_SIZE(constraints);
373-
if (n_constraints == 1) {
374-
PyErr_SetString(PyExc_TypeError,
375-
"A single constraint is not allowed");
376-
Py_XDECREF(bound);
377-
return NULL;
378-
} else if (n_constraints == 0) {
379-
constraints = NULL;
380-
} else if (bound != NULL) {
381-
PyErr_SetString(PyExc_TypeError,
382-
"Constraints cannot be combined with bound=...");
383-
Py_XDECREF(bound);
384-
return NULL;
385-
}
366+
assert(PyTuple_CheckExact(constraints));
367+
Py_ssize_t n_constraints = PyTuple_GET_SIZE(constraints);
368+
if (n_constraints == 1) {
369+
PyErr_SetString(PyExc_TypeError,
370+
"A single constraint is not allowed");
371+
Py_XDECREF(bound);
372+
return NULL;
373+
} else if (n_constraints == 0) {
374+
constraints = NULL;
375+
} else if (bound != NULL) {
376+
PyErr_SetString(PyExc_TypeError,
377+
"Constraints cannot be combined with bound=...");
378+
Py_XDECREF(bound);
379+
return NULL;
386380
}
387381
PyObject *module = caller();
388382
if (module == NULL) {

0 commit comments

Comments
 (0)