Skip to content

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

Merged
pablogsal merged 2 commits intopython:mainfrom
pablogsal:bpo-44963
Sep 7, 2021
Merged

bpo-44963: Implement send() and throw() methods for anext_awaitable objects#27955
pablogsal merged 2 commits intopython:mainfrom
pablogsal:bpo-44963

Conversation

@pablogsal
Copy link
Copy Markdown
Member

@pablogsal pablogsal commented Aug 25, 2021

@pablogsal
Copy link
Copy Markdown
Member Author

This does not cover the aclose() case.

@pablogsal
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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

@1st1
Copy link
Copy Markdown
Member

1st1 commented Sep 7, 2021

@pablogsal I think this is a go for merging.

@1st1
Copy link
Copy Markdown
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
Copy Markdown
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 <yury@edgedb.com>
(cherry picked from commit 533e725)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
@bedevere-bot
Copy link
Copy Markdown

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
Copy Markdown
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 <yury@edgedb.com>
(cherry picked from commit 533e725)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
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