Skip to content

Indicate that asyncio.timeout[at] should be preferred over asyncio.Timeout #142044

@picnixz

Description

@picnixz

asyncio.Timeout is exported by asyncio.__all__ and thus available when doing from asyncio import *. It is documented as the return type of asyncio.timeout[at]. In #141401, it was suggested to rename that class to avoid possible typos when writing asyncio.timeout However, I pointed several issues with that approach:

  • We cannot change a public API without a deprecation period.
  • Making it deprecated is painful. We need to support Timeout being used in type annotations, so the warning should be emitted at construction time. However we do not want that warning to be emitted when using asyncio.timeout[at]. Alternatively we could have two different classes or make other hacks, but AFAICT, this would rather seem like an ugly hack that I would like to avoid.

IMOM, the best course of action is:

  • Improve the docs to indicate that the class exists, the interface exists, but that it should not be instantiated directly. It can however be used in type annotations or users could decide to subclass the class to provide an improved interface for their own needs.
  • Add a rule to linters so that any usage of async with asyncio.Timeout(...) is flagged and that the user likely wanted async with asyncio.timeout instead. It's not our call to make but changing the docs first would give more weight to that decision on their side.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Todo

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions