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

GH-117536: GH-117894: fix athrow().throw(...) unawaited warning #117851

Merged
merged 15 commits into from
Apr 24, 2024

Conversation

@graingert graingert force-pushed the fix-athrow-throw-unawaited branch from ccf9830 to da89a69 Compare April 13, 2024 15:41
@graingert graingert force-pushed the fix-athrow-throw-unawaited branch from 797e0d5 to f1ac5d3 Compare April 13, 2024 15:56
@graingert graingert changed the title fix athrow().throw(...) unawaited warning GHT-117536: fix athrow().throw(...) unawaited warning Apr 13, 2024
@graingert graingert closed this Apr 13, 2024
@graingert graingert reopened this Apr 13, 2024
@graingert graingert changed the title GHT-117536: fix athrow().throw(...) unawaited warning GH-117536: fix athrow().throw(...) unawaited warning Apr 13, 2024
@graingert graingert marked this pull request as ready for review April 13, 2024 17:00
@graingert graingert requested a review from markshannon as a code owner April 13, 2024 17:00
@graingert graingert requested a review from vstinner April 13, 2024 20:41
@graingert
Copy link
Contributor Author

This also fixes a bug where an athrow()/aclose() can be reused across StopIteration calls, so needs backporting to 3.12

@graingert
Copy link
Contributor Author

graingert commented Apr 14, 2024

Here's the repro:

>>> class MyExc(Exception): pass
...
>>> import itertools
>>> async def gen():
...     for i in itertools.count():
...         try:
...             yield i
...         except MyExc:
...             pass
...
>>> agen = gen()
>>> agen.asend(None).send(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StopIteration: 0
>>> athrow = agen.athrow(MyExc)
>>> athrow.throw(MyExc)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StopIteration: 1
>>> athrow.throw(MyExc)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StopIteration: 2
>>> athrow.throw(MyExc)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StopIteration: 3
>>> athrow.throw(MyExc)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StopIteration: 4
>>>

@graingert graingert changed the title GH-117536: fix athrow().throw(...) unawaited warning GH-117536: GH-117894: fix athrow().throw(...) unawaited warning Apr 15, 2024
@graingert graingert requested a review from vstinner April 15, 2024 17:51
Copy link
Contributor

@agronholm agronholm left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link
Member

@encukou encukou left a comment

Choose a reason for hiding this comment

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

I'm not an expert in this area, but I cannot find anything wrong with the patch. An unhandled exception marking the awaitable closed (awaited) makes sense.

@graingert
Copy link
Contributor Author

graingert commented Apr 23, 2024

@encukou can I also get a review on #117882 ? Unfixed it also results in an unawaited coroutine warning when the athrow object handles the exception

Or should I combine these PRs into one?

@encukou
Copy link
Member

encukou commented Apr 24, 2024

Let's merge this to fix the blocker issue. On #117882 I'll try to deepen my understanding of this code, so I can give a better review.

@encukou encukou merged commit 7d369d4 into python:main Apr 24, 2024
40 checks passed
@graingert graingert deleted the fix-athrow-throw-unawaited branch April 24, 2024 12:25
@graingert
Copy link
Contributor Author

This needs backporting to 3.12

@graingert graingert added the needs backport to 3.12 only security fixes label Apr 24, 2024
@miss-islington-app
Copy link

Thanks @graingert for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry, @graingert and @encukou, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 7d369d471cf2b067c4d795d70b75201c48b46f5b 3.12

@bedevere-app
Copy link

bedevere-app bot commented Apr 24, 2024

GH-118226 is a backport of this pull request to the 3.12 branch.

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.

4 participants