vals[x] = cls(str(x))
del vals
+ def test_constructor(self):
+ T = TypeVar(name="T")
+ self.assertEqual(T.__name__, "T")
+ self.assertEqual(T.__constraints__, ())
+ self.assertIs(T.__bound__, None)
+
def template_replace(templates: list[str], replacements: dict[str, list[str]]) -> list[tuple[str]]:
"""Renders templates with possible combinations of replacements.
}
}
- 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 (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;
+ }
}
PyObject *module = caller();
if (module == NULL) {