Sitelet https://web.archive.org/web/20250608100352/https://github.com/python/cpython/issues/98935
Skip to content

What is formal definition of "Future-like"? (_asyncio_future_blocking) #98935

Closed
@dlech

Description

@dlech

Documentation

https://docs.python.org/3/library/asyncio-future.html#asyncio.isfuture

The link above describes:

a Future-like object with a _asyncio_future_blocking attribute.

However, it doesn't say exactly what constitutes "Future-like".

Since asyncio.Task and asyncio.Future both fit this test, I'm assuming it is the set (or a subset?) of the methods shared by both of these classes.

method Future Task
result ✅ ✅
set_result ✅
set_exception ✅
done ✅ ✅
cancelled ✅ ✅
add_done_callback ✅ ✅
remove_done_callback ✅ ✅
cancel ✅ ✅
exception ✅ ✅
get_loop ✅
get_stack ✅
get_name ✅
set_name ✅
get_stack ✅
uncancel ✅
cancelling ✅

Asking because I have a custom awaitable object that was being passed to asyncio.wait() that worked in the past but broke in Python 3.11 because is is missing a add_done_callback() method.

So...

  1. Can we get a formal definition in the docs?
  2. Taking it one step farther, should there be a typing.Protocol for "Future-like"?

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dirpendingThe issue will be closed if no feedback is providedtopic-asyncio

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions