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: Add cr_await calculated property to coroutine object
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: 24400 Superseder:
Assigned To: yselivanov Nosy List: bennoleslie, ethan.furman, fwierzbicki, larry, martin.panter, ncoghlan, python-dev, scoder, yselivanov
Priority: normal Keywords: patch

Created on 2015-06-14 10:29 by bennoleslie, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
gi_yieldfrom.v0.patch bennoleslie, 2015-06-14 10:48 Initial potential implementation of the gi_yieldfrom property review
gi_yieldfrom.v1.patch bennoleslie, 2015-06-18 11:15 Update patch with better testing coverage and documentation review
cr_await.patch yselivanov, 2015-06-22 22:26 review
Messages (18)
msg245338 - (view) Author: Benno Leslie (bennoleslie) * Date: 2015-06-14 10:29
When a co-routine has delegated computation to another co-routine via "yield from", it is useful to be able to access the delegated-to co-routine.

This proposed enhancement would add a new calculated property to the generator object called "gi_yieldfrom", which returns the delegated-to co-routine (or None).
msg245340 - (view) Author: Benno Leslie (bennoleslie) * Date: 2015-06-14 10:48
Attached is my first attempt at implementing this feature.

It includes to implementation, updates to documentation, and added test cases.

I'm not a regular contributor so look forward to any feedback on improving the patch.
msg245341 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-06-14 11:43
I left some comments on Reitveld.

Does this also apply to the new “async def” native coroutines? If not, I think it should be made to.
msg245441 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-06-17 16:50
I think we need some feedback from PyPy & Jython guys on this.  I'm not sure that they can expose 'yieldfrom' slot without some performance penalties.
msg245447 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2015-06-17 20:39
No problem from PyPy.
msg245461 - (view) Author: Benno Leslie (bennoleslie) * Date: 2015-06-18 11:15
I've tried to address all the issues raised in the review of the first patch.
msg245491 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2015-06-19 05:17
Marking this as dependent on issue 24400, as that refactors the PEP 492 implementation to make coroutines their own type (albeit one that shares a memory layout and some attribute names with generators at the C layer).

I'd suggest cr_await as the calculated property for coroutines that corresponds to gi_yieldfrom for generators.
msg245496 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2015-06-19 09:15
No problem for Cython either.

The change in issue 24400 that makes coroutines real Awaitables also removes surprises for a "cr_await" return value being a coroutine and previously *not* an Awaitable.

The contract for "gi_yieldfrom" is only that the returned value is an Iterator, IIUC?
msg245658 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-06-22 22:26
Please find attached a new patch that exposes 'cr_await' attribute on coroutine objects.  I don't think we can merge 'gi_yieldfrom' in 3.5, but 'cr_await' should probably be fine.
msg245664 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2015-06-23 04:12
Guido indicated on python-dev that he considered it reasonable to view adding gi_yieldfrom as part of the PEP 492 implementation: https://mail.python.org/pipermail/python-dev/2015-June/140498.html

That perspective makes sense to me as well, since it preserves the functional equivalence of native coroutines (cr_await) and generator based coroutines (gi_yieldfrom) from a state introspection perspective.

I've added Larry to the nosy list here to give him the option of veto'ing as release manager, but I think we want both in order to get full debuggability benefits.
msg245732 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-06-24 12:04
For Benno’s original gi_yieldfrom property, I guess the asyncio.coroutines.CoroWrapper class would need updating. The GeneratorWrapper class for @types.coroutine probably should be updated too, since it already supports other internal generator properties.
msg245765 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-06-24 17:06
Larry, what's your opinion on this?

cr_await is a new thing (trivial on the C level) on a new type, it shouldn't break anything.  gi_yieldfrom is identical to cr_await.  Can we add this to 3.5?
msg245767 - (view) Author: Frank Wierzbicki (fwierzbicki) * (Python committer) Date: 2015-06-24 18:20
This shouldn't be a problem for Jython.
msg246113 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2015-07-03 00:53
I'll accept it for 3.5.  Can it go in for beta 3, tagged in 48 hours?
msg246124 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-07-03 04:24
New changeset 84eb9a020011 by Yury Selivanov in branch '3.5':
Issue #24450: Add gi_yieldfrom to generators; cr_await to coroutines.
https://hg.python.org/cpython/rev/84eb9a020011

New changeset f4058528ab8c by Yury Selivanov in branch 'default':
Merge 3.5 (Issue #24450)
https://hg.python.org/cpython/rev/f4058528ab8c
msg246125 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-07-03 04:25
Benno, thanks for coming up with the idea and for the patches. Larry, thanks for approving this for 3.5!
msg246128 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-07-03 04:35
New changeset 9bae275e99b3 by Yury Selivanov in branch '3.5':
Issue #24450: Proxy cr_await and gi_yieldfrom in @types.coroutine
https://hg.python.org/cpython/rev/9bae275e99b3

New changeset 4d3bd9b82a62 by Yury Selivanov in branch 'default':
Merge 3.5 (Issue #24450)
https://hg.python.org/cpython/rev/4d3bd9b82a62
msg246131 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-07-03 04:42
New changeset 34460219c0e0 by Yury Selivanov in branch '3.4':
Issue #24450: Proxy gi_yieldfrom & cr_await in asyncio.CoroWrapper
https://hg.python.org/cpython/rev/34460219c0e0

New changeset 3555f7b5eac6 by Yury Selivanov in branch '3.5':
Merge 3.4 (Issue #24450)
https://hg.python.org/cpython/rev/3555f7b5eac6

New changeset 5e9f794fd776 by Yury Selivanov in branch 'default':
Merge 3.5 (Issue #24450)
https://hg.python.org/cpython/rev/5e9f794fd776
History
Date User Action Args
2022-04-11 14:58:18adminsetgithub: 68638
2015-07-03 04:42:15python-devsetmessages: + msg246131
2015-07-03 04:35:49python-devsetmessages: + msg246128
2015-07-03 04:25:26yselivanovsetstatus: open -> closed
versions: + Python 3.6
messages: + msg246125

resolution: fixed
stage: patch review -> resolved
2015-07-03 04:24:25python-devsetnosy: + python-dev
messages: + msg246124
2015-07-03 00:53:34larrysetmessages: + msg246113
2015-06-24 18:20:30fwierzbickisetmessages: + msg245767
2015-06-24 17:06:11yselivanovsetmessages: + msg245765
2015-06-24 12:09:50arigosetnosy: - arigo
2015-06-24 12:04:23martin.pantersetmessages: + msg245732
2015-06-23 04:12:29ncoghlansetnosy: + larry
messages: + msg245664
2015-06-22 22:40:05yselivanovsettitle: Add gi_yieldfrom calculated property to generator object -> Add cr_await calculated property to coroutine object
2015-06-22 22:26:14yselivanovsetfiles: + cr_await.patch

messages: + msg245658
2015-06-19 09:15:57scodersetmessages: + msg245496
2015-06-19 09:08:10scodersetnosy: + scoder
2015-06-19 05:17:46ncoghlansetnosy: + ncoghlan
dependencies: + Awaitable ABC incompatible with functools.singledispatch
messages: + msg245491
2015-06-18 11:15:13bennolesliesetfiles: + gi_yieldfrom.v1.patch

messages: + msg245461
2015-06-17 20:47:52yselivanovsetnosy: + fwierzbicki
2015-06-17 20:39:17arigosetmessages: + msg245447
2015-06-17 19:47:24yselivanovsetnosy: + arigo
2015-06-17 17:06:11yselivanovsetassignee: yselivanov
2015-06-17 16:50:03yselivanovsetnosy: + yselivanov
messages: + msg245441
2015-06-15 02:06:48ethan.furmansetnosy: + ethan.furman
2015-06-14 11:43:10martin.pantersetnosy: + martin.panter

messages: + msg245341
stage: patch review
2015-06-14 10:48:39bennolesliesetfiles: + gi_yieldfrom.v0.patch
keywords: + patch
messages: + msg245340
2015-06-14 10:29:47bennolesliecreate