From b5f4f5c4aacafb3e392335b5d3670e7c7e0bcc36 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 16 Oct 2023 14:47:17 +0300 Subject: [PATCH 1/2] gh-110784: Partially revert gh-110784, `constraints` cannot be `NULL` --- Objects/typevarobject.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/Objects/typevarobject.c b/Objects/typevarobject.c index 8a20b23c6866d7..115a8b84330508 100644 --- a/Objects/typevarobject.c +++ b/Objects/typevarobject.c @@ -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) { From d070c0cf1c6e58d0b4294be914bbec7654b27d90 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 16 Oct 2023 17:32:05 +0300 Subject: [PATCH 2/2] Address review --- Objects/typevarobject.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Objects/typevarobject.c b/Objects/typevarobject.c index 115a8b84330508..af8c7fcafaaedb 100644 --- a/Objects/typevarobject.c +++ b/Objects/typevarobject.c @@ -364,11 +364,7 @@ typevar_new_impl(PyTypeObject *type, PyObject *name, PyObject *constraints, } } - if (!PyTuple_CheckExact(constraints)) { - PyErr_SetString(PyExc_TypeError, - "Constraints must be a tuple"); - return NULL; - } + assert(PyTuple_CheckExact(constraints)); Py_ssize_t n_constraints = PyTuple_GET_SIZE(constraints); if (n_constraints == 1) { PyErr_SetString(PyExc_TypeError,