Skip to content

bpo-44963: Implement send() and throw() methods for anext_awaitable objects #27955

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

Merged
merged 2 commits into from
Sep 7, 2021

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented Aug 25, 2021

@pablogsal
Copy link
Member Author

This does not cover the aclose() case.

@pablogsal
Copy link
Member Author

pablogsal commented Aug 25, 2021

~Actually, I don't know if this is the way we should handle this, because this allows to call send() multiple times to the wrapped generator, which is kinda wrong, as send() here applies to the anextawaitable object 😟 ~

Or maybe we are fine, is late here (someone should check) :(

Seems we are fine:

>>> async def blech():
...     yield 1
...     yield 2
...     yield 3
...
>>> x = blech()
>>> asend_obj = anext(x)
>>> asend_obj.send(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StopIteration: 1
>>> asend_obj.send(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: cannot reuse already awaited __anext__()/asend()
>>> asend_obj = anext(x)
>>> asend_obj.send(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StopIteration: 2
>>> asend_obj.send(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: cannot reuse already awaited __anext__()/asend()

Copy link
Member

@1st1 1st1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Although I'm not sure this is a blocker-level thing.

Copy link
Member

@1st1 1st1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pablogsal I'm still not sure about the semantics here. I need more time.

@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@1st1
Copy link
Member

1st1 commented Sep 7, 2021

@pablogsal I think this is a go for merging.

@1st1
Copy link
Member

1st1 commented Sep 7, 2021

@graingert Thomas, thanks for the thorough review.

@pablogsal pablogsal merged commit 533e725 into python:main Sep 7, 2021
@pablogsal pablogsal deleted the bpo-44963 branch September 7, 2021 10:30
@miss-islington
Copy link
Contributor

Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 7, 2021
…bjects (pythonGH-27955)

Co-authored-by: Yury Selivanov <[email protected]>
(cherry picked from commit 533e725)

Co-authored-by: Pablo Galindo Salgado <[email protected]>
@bedevere-bot
Copy link

GH-28198 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Sep 7, 2021
@pablogsal
Copy link
Member Author

Thanks @1st1 for all the help and thanks @graingert for the reviews and the comments!

miss-islington added a commit that referenced this pull request Sep 7, 2021
…bjects (GH-27955)

Co-authored-by: Yury Selivanov <[email protected]>
(cherry picked from commit 533e725)

Co-authored-by: Pablo Galindo Salgado <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants