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

asyncio.wait(aws) require aws is 'iterable', but doesn't accept generator #99936

Closed
NewUserHa opened this issue Dec 1, 2022 · 5 comments
Closed
Labels
topic-asyncio type-bug An unexpected behavior, bug, or error

Comments

@NewUserHa
Copy link
Contributor

Bug report

"""
if futures.isfuture(fs) or coroutines.iscoroutine(fs):
raise TypeError(f"expect a list of futures, not {type(fs).__name__}")

https://docs.python.org/3/library/asyncio-task.html#waiting-primitives
https://docs.python.org/3/glossary.html#term-iterable
asyncio.wait(aws) require aws is 'iterable' but doesn't accept generator while which is iterable ( has iter and next methods):

await asyncio.wait(asyncfunc(_) for _ in range())
@NewUserHa NewUserHa added the type-bug An unexpected behavior, bug, or error label Dec 1, 2022
@JelleZijlstra
Copy link
Member

This is because generators are in asyncio.coroutines._COROUTINE_TYPES: https://github.com/python/cpython/blob/main/Lib/asyncio/coroutines.py#L28. Therefore, asyncio.coroutines.iscoroutine thinks every generator is a coroutine.

This is presumably a holdover from generator-based coroutines, which no longer exist in recent versions of asyncio. We should consider removing GeneratorType from _COROUTINE_TYPES, but we'll have to think about whether there are any backward compatibility implications.

@NewUserHa
Copy link
Contributor Author

a more thing:
I also see "DeprecationWarning: The explicit passing of coroutine objects to asyncio.wait() is deprecated since Python 3.8, and scheduled for removal in Python 3.11.".
It didn't say anything, but I guess it's asking users to .create_task() outside .wait() for comparing if the task is in the returned done set. But the document of .wait() deleted that comparing part from the example code.
It seems to make a little confuse both in DeprecationWarning and the document because they didn't match.

maybe should update the document to match the warning?

@kumaraditya303
Copy link
Contributor

Duplicate of #78530

@kumaraditya303 kumaraditya303 marked this as a duplicate of #78530 Dec 2, 2022
@kumaraditya303 kumaraditya303 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 2, 2022
Repository owner moved this from Todo to Done in asyncio Dec 2, 2022
@NewUserHa
Copy link
Contributor Author

I have seen #78530 when open issue. However, this issue is more about the document.

@kumaraditya303
Copy link
Contributor

I am thinking of allowing this rather than documenting this. See my comment #78530 (comment) and let's continue the discussion on that issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-asyncio type-bug An unexpected behavior, bug, or error
Projects
Status: Done
Development

No branches or pull requests

3 participants