Skip to content

support for Awaitable objects in asyncio.wait removed in 3.11 #95601

Closed as not planned

Description

@graingert

on python3.10 -W error this passes:

class ExampleAwaitable:
    def __await__(self):
        async def _():
            return await asyncio.sleep(0)

        return _().__await__()


import asyncio

print(f"{asyncio.iscoroutine(ExampleAwaitable())=}")

async def amain():
    await asyncio.wait([ExampleAwaitable()])
    print("waited!")

asyncio.run(amain())

and in 3.11 this fails:

asyncio.iscoroutine(ExampleAwaitable())=False
Traceback (most recent call last):
  File "/home/graingert/projects/foo.py", line 17, in <module>
    asyncio.run(amain())
  File "/usr/lib/python3.11/asyncio/runners.py", line 187, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 120, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 650, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/graingert/projects/foo.py", line 14, in amain
    await asyncio.wait([ExampleAwaitable()])
  File "/usr/lib/python3.11/asyncio/tasks.py", line 427, in wait
    return await _wait(fs, timeout, return_when, loop)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/tasks.py", line 531, in _wait
    f.add_done_callback(_on_completion)
    ^^^^^^^^^^^^^^^^^^^
AttributeError: 'ExampleAwaitable' object has no attribute 'add_done_callback'

this broke distributed and we missed the DeprecationWarning because ensure_future accepts a wider variety of objects than just futures tasks and coroutines

dask/distributed#6785

the removal happened here 903f0a0

Activity

  1. graingert commented on Aug 3, 2022

    @graingert
    ContributorAuthor

    I think using something like this might help?

    def _insist_future(f, loop):
        f2 = ensure_future(f, loop=loop)
        if f2 is not f:
            warnings.warn("passing non-futures is deprecated")
        return f2
        fs = set(fs)
        loop = events.get_running_loop()
        if any(coroutines.iscoroutine(f) for f in fs):
            raise TypeError("Passing coroutines is forbidden, use tasks explicitly.")
        fs = {_insist_future(f, loop=loop) for f in fs}
        return await _wait(fs, timeout, return_when, loop)
  2. changed the title [-]support for Awaitable objects in `asyncio.wait_for` removed in 3.11[/-] [+]support for Awaitable objects in `asyncio.wait` removed in 3.11[/+] on Aug 3, 2022
  3. added a commit that references this issue on Aug 5, 2022
  4. graingert commented on Aug 9, 2022

    @graingert
    ContributorAuthor

    This was intended to be deprecated in 3.10 so I'm tentatively adding the 3.10 label

  5. gvanrossum commented on Aug 27, 2022

    @gvanrossum
    Member

    So what is the bug exactly? Was the deprecation schedule not followed properly? Or do you just disagree with the deprecation and subsequent removal? In that case, tough luck. The release manager isn't going to allow the removal to be reversed.

  6. graingert commented on Sep 12, 2022

    @graingert
    ContributorAuthor

    So what is the bug exactly? Was the deprecation schedule not followed properly? Or do you just disagree with the deprecation and subsequent removal? In that case, tough luck. The release manager isn't going to allow the removal to be reversed.

    The deprecation schedule was not followed properly. The removal didn't match the deprecation, and support for iterables was removed. There's more discussion on the PR

  7. gvanrossum commented on Oct 27, 2022

    @gvanrossum
    Member

    Now that the PR is closed, can you come up with a better description? It should describe a desired course of action.

  8. added 3 commits that reference this issue on Nov 3, 2022
  9. added 2 commits that reference this issue on Nov 17, 2022
  10. sileht commented on Nov 23, 2022

    @sileht
    Contributor

    I upgrade some projects to 3.11 and got the same issue.

    We usually fix python deprecation warning the day python released a version, but we missed that one.

    The real root cause issue, I guess, is that the deprecation warning of python < 3.11 was not working for this kind of object:

    class ExampleAwaitable:
        def __await__(self):
              yield from asyncio.sleep(0)
    
  11. added 2 commits that reference this issue on Nov 24, 2022
  12. added a commit that references this issue on Dec 14, 2022
  13. kumaraditya303 commented on Apr 16, 2023

    @kumaraditya303
    Contributor

    @graingert are you going to follow up on this? If not I am inclined to just close it, 3.11 is far ahead in release cycle now anyways.

  14. kumaraditya303 commented on Apr 23, 2023

    @kumaraditya303
    Contributor

    Closing because of no response to my and Guido's comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.10 (EOL)end of life3.11only security fixes3.12only security fixestopic-asynciotype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions