Skip to content

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

Description

@NewUserHa

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())

Activity

  1. JelleZijlstra commented on Dec 1, 2022

    @JelleZijlstra
    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.

  2. NewUserHa commented on Dec 1, 2022

    @NewUserHa
    ContributorAuthor

    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?

  3. moved this to Todo in asyncioon Dec 2, 2022
  4. kumaraditya303 commented on Dec 2, 2022

    @kumaraditya303
    Contributor

    Duplicate of #78530

  5. Repository owner moved this from Todo to Done in asyncioon Dec 2, 2022
  6. NewUserHa commented on Dec 2, 2022

    @NewUserHa
    ContributorAuthor

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

  7. kumaraditya303 commented on Dec 2, 2022

    @kumaraditya303
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions