When I was looking into https://bugs.python.org/issue40679, I couldn't come up with a test case for the following block, so I added a print statement:
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4179,6 +4179,7 @@ _PyEval_EvalCode(PyThreadState *tstate,
Py_ssize_t j;
if (keyword == NULL || !PyUnicode_Check(keyword)) {
+ printf("THIS CODE WAS RUN!\n");
_PyErr_Format(tstate, PyExc_TypeError,
"%U() keywords must be strings",
qualname);
I ran the entire test suite and got no such "THIS CODE WAS RUN!". It looks like this is a double-check of the (worse -- no function name) error message produced by the changes at https://github.com/python/cpython/commit/0567786d26348aa7eaf0ab1b5d038fdabe409d92. For example:
py -3.7 -c "f = lambda x: None; f(**{1:1})"
...
TypeError: <lambda>() keywords must be strings
py -3.8 -c "f = lambda x: None; f(**{1:1})"
...
TypeError: <lambda>() keywords must be strings
py -3.9 -c "f = lambda x: None; f(**{1:1})"
...
TypeError: keywords must be strings
So:
* Can this check be eliminated since it's unreachable from Python?
* Otherwise, is there some reason a C caller would need this check? And could it be replaced by and assert?
* If it shouldn't change, then is there a good way to add test coverage?
|