Skip to content
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

Add cr_await calculated property to coroutine object #68638

Closed
bennoleslie mannequin opened this issue Jun 14, 2015 · 18 comments
Closed

Add cr_await calculated property to coroutine object #68638

bennoleslie mannequin opened this issue Jun 14, 2015 · 18 comments
Assignees
Labels
interpreter-core Interpreter core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@bennoleslie
Copy link
Mannequin

bennoleslie mannequin commented Jun 14, 2015

BPO 24450
Nosy @ncoghlan, @scoder, @larryhastings, @ethanfurman, @vadmium, @1st1
Dependencies
  • bpo-24400: Awaitable ABC incompatible with functools.singledispatch
  • Files
  • gi_yieldfrom.v0.patch: Initial potential implementation of the gi_yieldfrom property
  • gi_yieldfrom.v1.patch: Update patch with better testing coverage and documentation
  • cr_await.patch
  • Note: 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:

    assignee = 'https://github.com/1st1'
    closed_at = <Date 2015-07-03.04:25:26.587>
    created_at = <Date 2015-06-14.10:29:47.577>
    labels = ['interpreter-core', 'type-feature']
    title = 'Add cr_await calculated property to coroutine object'
    updated_at = <Date 2015-07-03.04:42:15.615>
    user = 'https://bugs.python.org/bennoleslie'

    bugs.python.org fields:

    activity = <Date 2015-07-03.04:42:15.615>
    actor = 'python-dev'
    assignee = 'yselivanov'
    closed = True
    closed_date = <Date 2015-07-03.04:25:26.587>
    closer = 'yselivanov'
    components = ['Interpreter Core']
    creation = <Date 2015-06-14.10:29:47.577>
    creator = 'bennoleslie'
    dependencies = ['24400']
    files = ['39706', '39725', '39776']
    hgrepos = []
    issue_num = 24450
    keywords = ['patch']
    message_count = 18.0
    messages = ['245338', '245340', '245341', '245441', '245447', '245461', '245491', '245496', '245658', '245664', '245732', '245765', '245767', '246113', '246124', '246125', '246128', '246131']
    nosy_count = 9.0
    nosy_names = ['ncoghlan', 'scoder', 'larry', 'fwierzbicki', 'ethan.furman', 'python-dev', 'martin.panter', 'yselivanov', 'bennoleslie']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue24450'
    versions = ['Python 3.5', 'Python 3.6']

    @bennoleslie
    Copy link
    Mannequin Author

    bennoleslie mannequin commented Jun 14, 2015

    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).

    @bennoleslie bennoleslie mannequin added interpreter-core Interpreter core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Jun 14, 2015
    @bennoleslie
    Copy link
    Mannequin Author

    bennoleslie mannequin commented Jun 14, 2015

    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.

    @vadmium
    Copy link
    Member

    vadmium commented Jun 14, 2015

    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.

    @1st1
    Copy link
    Member

    1st1 commented Jun 17, 2015

    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.

    @1st1 1st1 self-assigned this Jun 17, 2015
    @arigo
    Copy link
    Mannequin

    arigo mannequin commented Jun 17, 2015

    No problem from PyPy.

    @bennoleslie
    Copy link
    Mannequin Author

    bennoleslie mannequin commented Jun 18, 2015

    I've tried to address all the issues raised in the review of the first patch.

    @ncoghlan
    Copy link
    Contributor

    ncoghlan commented Jun 19, 2015

    Marking this as dependent on bpo-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.

    @scoder
    Copy link
    Contributor

    scoder commented Jun 19, 2015

    No problem for Cython either.

    The change in bpo-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?

    @1st1
    Copy link
    Member

    1st1 commented Jun 22, 2015

    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.

    @1st1 1st1 changed the title Add gi_yieldfrom calculated property to generator object Add cr_await calculated property to coroutine object Jun 22, 2015
    @ncoghlan
    Copy link
    Contributor

    ncoghlan commented Jun 23, 2015

    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.

    @vadmium
    Copy link
    Member

    vadmium commented Jun 24, 2015

    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.

    @1st1
    Copy link
    Member

    1st1 commented Jun 24, 2015

    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?

    @fwierzbicki
    Copy link
    Mannequin

    fwierzbicki mannequin commented Jun 24, 2015

    This shouldn't be a problem for Jython.

    @larryhastings
    Copy link
    Contributor

    larryhastings commented Jul 3, 2015

    I'll accept it for 3.5. Can it go in for beta 3, tagged in 48 hours?

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jul 3, 2015

    New changeset 84eb9a020011 by Yury Selivanov in branch '3.5':
    Issue bpo-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 bpo-24450)
    https://hg.python.org/cpython/rev/f4058528ab8c

    @1st1
    Copy link
    Member

    1st1 commented Jul 3, 2015

    Benno, thanks for coming up with the idea and for the patches. Larry, thanks for approving this for 3.5!

    @1st1 1st1 closed this as completed Jul 3, 2015
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jul 3, 2015

    New changeset 9bae275e99b3 by Yury Selivanov in branch '3.5':
    Issue bpo-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 bpo-24450)
    https://hg.python.org/cpython/rev/4d3bd9b82a62

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jul 3, 2015

    New changeset 34460219c0e0 by Yury Selivanov in branch '3.4':
    Issue bpo-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 bpo-24450)
    https://hg.python.org/cpython/rev/3555f7b5eac6

    New changeset 5e9f794fd776 by Yury Selivanov in branch 'default':
    Merge 3.5 (Issue bpo-24450)
    https://hg.python.org/cpython/rev/5e9f794fd776

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core Interpreter core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants