[New-bugs-announce] [issue40706] Unreachable code in _PyEval_EvalCode

Dennis Sweeney report at bugs.python.org
Thu May 21 02:08:42 EDT 2020


New submission from Dennis Sweeney <sweeney.dennis650 at gmail.com>:

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?

----------
components: Interpreter Core
messages: 369498
nosy: Dennis Sweeney
priority: normal
severity: normal
status: open
title: Unreachable code in _PyEval_EvalCode
type: behavior
versions: Python 3.10, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40706>
_______________________________________


More information about the New-bugs-announce mailing list