Repository navigation
sending non-None values makes generator raise StopIteration on next access #90167
Description
Activity
Tested with Python 3.10.1 on Linux and Python 3.10.0 on Windows.
The following code prints None in 3.9 and raises StopIteration without any additional information in 3.10:
def f(): yield x = f() try: x.send(0) except TypeError as e: print(e) # can't send non-None value to a just-started generator print(next(x))
- added3.10 (EOL)end of lifeend of lifetype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Dec 7, 2021 #74552 broke Emscripten WASM builds. I'm getting a "null function or function signature mismatch" error from the WASM engine:
RuntimeError: null function or function signature mismatch
at _PyEval_EvalFrameDefault (http://localhost:8000/python.wasm:wasm-function[2383]:0x103a6f)
at gen_send_ex2 (http://localhost:8000/python.wasm:wasm-function[886]:0x4f35d)
at gen_iternext (http://localhost:8000/python.wasm:wasm-function[893]:0x4fb1a)
at builtin_any (http://localhost:8000/python.wasm:wasm-function[3927]:0x198a87)
at cfunction_vectorcall_O (http://localhost:8000/python.wasm:wasm-function[403]:0x201ae)
at PyObject_Vectorcall (http://localhost:8000/python.wasm:wasm-function[2426]:0x109dbe)
at _PyEval_EvalFrameDefault (http://localhost:8000/python.wasm:wasm-function[2383]:0x1062ba)
at _PyEval_Vector (http://localhost:8000/python.wasm:wasm-function[2380]:0xfc366)
at PyEval_EvalCode (http://localhost:8000/python.wasm:wasm-function[2379]:0xfc014)
at _PyConfig_InitPathConfig (http://localhost:8000/python.wasm:wasm-function[6871]:0x2924b0)I'm trying to get more debug information now.
I got more debug symbols:
python.js:235 Uncaught RuntimeError: null function or function signature mismatch
at _PyEval_EvalFrameDefault (ceval.c:4247)
at _PyEval_EvalFrame (pycore_ceval.h:48)
at gen_send_ex2 (genobject.c:219)
at gen_iternext (genobject.c:583)
at builtin_any (bltinmodule.c:384)
at cfunction_vectorcall_O (methodobject.c:516)
at _PyObject_VectorcallTstate.11 (pycore_call.h:89)
at PyObject_Vectorcall (call.c:298)
at _PyEval_EvalFrameDefault (ceval.c:4625)
at _PyEval_EvalFrame.1 (pycore_ceval.h:48)The culprit is
PyObject *next = (*Py_TYPE(iter)->tp_iternext)(iter);
in the TARGET(FOR_ITER) target. An additional NULL check resolves the problem.
index 953876f6226..390400b3246 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -4244,7 +4244,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr PREDICTED(FOR_ITER); /* before: [iter]; after: [iter, iter()] *or* [] */ PyObject *iter = TOP(); - PyObject *next = (*Py_TYPE(iter)->tp_iternext)(iter); + PyObject *(*iternext)(PyObject *) = *Py_TYPE(iter)->tp_iternext; + if (iternext == NULL) { + PyErr_BadInternalCall(); + goto error; + } + PyObject *next = iternext(iter); if (next != NULL) { PUSH(next); PREDICT(STORE_FAST);
False alarm ... the frozen files for getpath.py were out of date. I can no longer reproduce the issue after a hard git clean and rebuild.
GEN_START#30367Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields: