-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-95601: restore support for awaitable objects that are not futures in asyncio.wait
#95708
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
Closed
graingert
wants to merge
25
commits into
python:main
from
graingert:forbid-non-futures-in-asyncio-wait
Closed
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
88580c9
gh-95601: forbid non-futures in asyncio.wait
graingert 1363c9b
📜🤖 Added by blurb_it.
blurb-it[bot] 543c4f2
Merge branch 'main' into forbid-non-futures-in-asyncio-wait
graingert 6661052
clarify awaitable-not-future
graingert 5b740df
update asyncio.wait deprecation notice
graingert 5b974c5
Update Doc/library/asyncio-task.rst
graingert c4a7237
Merge branch 'main' into forbid-non-futures-in-asyncio-wait
graingert d4dac27
Merge branch 'main' into forbid-non-futures-in-asyncio-wait
graingert cb00279
Apply suggestions from code review
graingert 38fb812
Update Misc/NEWS.d/next/Library/2022-08-05-11-16-33.gh-issue-95601.hJ…
graingert 5383116
Update Lib/test/test_asyncio/test_tasks.py
graingert b6ea455
upgrade WaitTests to an IsolatedAsyncioTestCase
graingert 980a3b9
Update Lib/test/test_asyncio/test_tasks.py
graingert d8354db
Update Lib/test/test_asyncio/test_tasks.py
graingert 5f1d061
Update Lib/test/test_asyncio/test_tasks.py
graingert 9181e25
Merge branch 'main' into forbid-non-futures-in-asyncio-wait
graingert f973c52
test that asyncio.wait gives the right type error for non-awaitable n…
graingert 0430145
Merge branch 'main' into forbid-non-futures-in-asyncio-wait
graingert 9189603
Merge branch 'main' into forbid-non-futures-in-asyncio-wait
graingert 9c325b4
don't deprecate Awaitables in wait yet
graingert da9f2a2
Merge branch 'main' into forbid-non-futures-in-asyncio-wait
graingert 7e35d9c
remove deprecation docs
graingert a5c5f4a
remove deprecation assertions from tests for asyncio.wait
graingert 17cbfc9
Update Misc/NEWS.d/next/Library/2022-08-05-11-16-33.gh-issue-95601.hJ…
graingert 69b2a0d
Merge branch 'main' into forbid-non-futures-in-asyncio-wait
graingert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -408,19 +408,30 @@ async def wait(fs, *, timeout=None, return_when=ALL_COMPLETED): | |
when the timeout occurs are returned in the second set. | ||
""" | ||
if futures.isfuture(fs) or coroutines.iscoroutine(fs): | ||
raise TypeError(f"expect a list of futures, not {type(fs).__name__}") | ||
if not fs: | ||
raise ValueError('Set of Tasks/Futures is empty.') | ||
raise TypeError(f"expected an iterable of futures, not {type(fs).__name__}") | ||
if return_when not in (FIRST_COMPLETED, FIRST_EXCEPTION, ALL_COMPLETED): | ||
raise ValueError(f'Invalid return_when value: {return_when}') | ||
|
||
fs = set(fs) | ||
loop = events.get_running_loop() | ||
new_fs = set() | ||
|
||
for f in fs: | ||
if coroutines.iscoroutine(f): | ||
raise TypeError("Passing coroutines is forbidden, use tasks explicitly.") | ||
if not futures.isfuture(f): | ||
try: | ||
new_fs.add(ensure_future(f, loop=loop)) | ||
except TypeError: | ||
raise TypeError( | ||
f"An asyncio.Future was expected, got {f!r}" | ||
) from None | ||
else: | ||
new_fs.add(f) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is getting added to the set with no checks whatsoever. It needs to check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed! |
||
|
||
if any(coroutines.iscoroutine(f) for f in fs): | ||
raise TypeError("Passing coroutines is forbidden, use tasks explicitly.") | ||
if not new_fs: | ||
raise ValueError('Iterable of Tasks/Futures is empty.') | ||
|
||
loop = events.get_running_loop() | ||
return await _wait(fs, timeout, return_when, loop) | ||
return await _wait(new_fs, timeout, return_when, loop) | ||
|
||
|
||
def _release_waiter(waiter, *args): | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Library/2022-08-05-11-16-33.gh-issue-95601.hJvI9y.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Restore the support for the explicit passing of awaitable objects that are not :class:`asyncio.Future` to :func:`asyncio.wait` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will happened with implicitly created futures added to
new_fs
? Would it emit a warning?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the warning at @tiran 's request, with a plan to add it in a follow up PR.
I'm happy to put it back in this PR if you'd prefer