-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sending non-None values makes generator raise StopIteration on next access #90167
Comments
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)) |
I got more debug symbols: python.js:235 Uncaught RuntimeError: null function or function signature mismatch 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:
The text was updated successfully, but these errors were encountered: