Skip to content

Add support for asyncio.Future #146

@charlax

Description

@charlax

In its current state, doubles's and_return_future only returns concurrent.futures.Future or tornado.concurrent.Future.

def _get_future():
    try:
        from concurrent.futures import Future
    except ImportError:
        try:
            from tornado.concurrent import Future
        except ImportError:
            raise ImportError(
                'Error Importing Future, Could not find concurrent.futures or tornado.concurrent',
            )
    return Future()

To make it work with asyncio, I had to manually patch _get_future:

from asyncio import Future
from typing import Any

import doubles


def fix_doubles_future() -> None:
    def _get_future() -> Future[Any]:
        return Future()

    doubles.allowance._get_future = _get_future


fix_doubles_future()

There should be a way to configure this globally or on a per-call basis.

Btw, I'd be happy to implement the fix but it seems this repository is not maintained anymore: #145

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions