-
-
Notifications
You must be signed in to change notification settings - Fork 34k
bpo-41756: Add PyIter_Send function to allow sending value into generators/coroutines/iterators #22443
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
bpo-41756: Add PyIter_Send function to allow sending value into generators/coroutines/iterators #22443
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Add `PyIter_Send` function to allow sending value into | ||
| generator/coroutine/iterator without raising StopIteration exception to | ||
| signal return. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2213,24 +2213,17 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag) | |
| case TARGET(YIELD_FROM): { | ||
| PyObject *v = POP(); | ||
| PyObject *receiver = TOP(); | ||
| int is_gen_or_coro = PyGen_CheckExact(receiver) || PyCoro_CheckExact(receiver); | ||
| int gen_status; | ||
| if (tstate->c_tracefunc == NULL && is_gen_or_coro) { | ||
| gen_status = PyGen_Send((PyGenObject *)receiver, v, &retval); | ||
| PySendResult gen_status; | ||
| if (tstate->c_tracefunc == NULL) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we fold the tracing into the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would also make ceval a tad smaller which is always a good thing.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think it is feasible.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you elaborate?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a call of the trace function in between calls of We can introduce a private function
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking about exporting the |
||
| gen_status = PyIter_Send(receiver, v, &retval); | ||
| } else { | ||
| if (is_gen_or_coro) { | ||
| retval = _PyGen_Send((PyGenObject *)receiver, v); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| _Py_IDENTIFIER(send); | ||
| if (v == Py_None && PyIter_Check(receiver)) { | ||
| retval = Py_TYPE(receiver)->tp_iternext(receiver); | ||
| } | ||
| else { | ||
| _Py_IDENTIFIER(send); | ||
| if (v == Py_None) { | ||
| retval = Py_TYPE(receiver)->tp_iternext(receiver); | ||
| } | ||
| else { | ||
| retval = _PyObject_CallMethodIdOneArg(receiver, &PyId_send, v); | ||
| } | ||
| retval = _PyObject_CallMethodIdOneArg(receiver, &PyId_send, v); | ||
| } | ||
|
|
||
| if (retval == NULL) { | ||
| if (tstate->c_tracefunc != NULL | ||
| && _PyErr_ExceptionMatches(tstate, PyExc_StopIteration)) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.