typing: Add more tests for TypeVar (#104571)

During the PEP 695 implementation at one point I made
TypeVar.__name__ return garbage, and all of test_typing passed.
So I decided to add a few more tests. In the process I discovered
a minor incompatibility from the C implementation of TypeVar:
empty constraints were returned as None instead of an empty tuple.
This commit is contained in:
Jelle Zijlstra 2023-05-17 06:08:21 -07:00 committed by GitHub
parent 97db2f3e07
commit 26931944dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 8 deletions

View file

@ -271,7 +271,7 @@ typevar_constraints(typevarobject *self, void *Py_UNUSED(ignored))
return Py_NewRef(self->constraints);
}
if (self->evaluate_constraints == NULL) {
Py_RETURN_NONE;
return PyTuple_New(0);
}
PyObject *constraints = PyObject_CallNoArgs(self->evaluate_constraints);
self->constraints = Py_XNewRef(constraints);