This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Unreachable code in _PyEval_EvalCode
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.10, Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Dennis Sweeney, chris.jerdonek
Priority: normal Keywords:

Created on 2020-05-21 06:08 by Dennis Sweeney, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg369498 - (view) Author: Dennis Sweeney (Dennis Sweeney) * (Python committer) Date: 2020-05-21 06:08
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?
History
Date User Action Args
2022-04-11 14:59:31adminsetgithub: 84883
2020-05-21 06:19:36chris.jerdoneksetnosy: + chris.jerdonek
2020-05-21 06:08:42Dennis Sweeneycreate