]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-110864: TypeVar constructor: Partially revert gh-110784, `constraints` cannot...
authorNikita Sobolev <mail@sobolevn.me>
Mon, 16 Oct 2023 15:01:04 +0000 (18:01 +0300)
committerGitHub <noreply@github.com>
Mon, 16 Oct 2023 15:01:04 +0000 (15:01 +0000)
Objects/typevarobject.c

index 51424ffb24e2bf7ecb81882b4e6e45820ead582c..7f80c9c61b8abcf4beb7fab517dd4fb14401c319 100644 (file)
@@ -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) {