Skip to content

Document how the msg parameter for asyncio.futures.Future.cancel is used #148091

Closed

Description

@jonathandung

Documentation

Currently, in the user-facing asyncio docs for Futures, it is mentioned that the signature of cancel changed to cancel(msg=None) in python 3.9.

However, the msg parameter has never been explained:

   .. method:: cancel(msg=None)

      Cancel the Future and schedule callbacks.

      If the Future is already *done* or *cancelled*, return ``False``.
      Otherwise, change the Future's state to *cancelled*,
      schedule the callbacks, and return ``True``.

      .. versionchanged:: 3.9
         Added the *msg* parameter.

From its name, users may incorrectly assume it stands for 'message' and thus must be a string, whereas to my understanding, it is but the argument passed to the instance of asyncio.exceptions.CancelledError thrown to waiters of the future, and can be of any type.

See the .rst source of the relevant documentation segment and the asyncio source.

Linked PRs

Activity

  1. added
    docs
    on Apr 4, 2026
  2. jonathandung commented on Apr 8, 2026

    @jonathandung
    ContributorAuthor

    Sure.

  3. added a commit that references this issue on Apr 9, 2026
  4. moved this from Todo to Done in asyncioon Apr 9, 2026
  5. added 2 commits that reference this issue on Apr 9, 2026
  6. added 2 commits that reference this issue on Apr 9, 2026
  7. added a commit that references this issue on Apr 25, 2026
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

    docstopic-asyncio

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions