Pacify mypy

This commit is contained in:
Itamar Turner-Trauring 2023-06-15 17:14:08 -04:00
parent bf5213cb01
commit 8d99ddc542

View File

@ -8,7 +8,7 @@ import json
import os import os
from functools import partial from functools import partial
from os.path import join from os.path import join
from typing import Awaitable, Callable, Optional, Sequence, TypeVar, Union from typing import Callable, Optional, Sequence, TypeVar, Union, Coroutine, Any, Tuple, cast, Generator
from twisted.internet import defer from twisted.internet import defer
from twisted.trial import unittest from twisted.trial import unittest
@ -60,7 +60,7 @@ def make_simple_peer(
server: MemoryWormholeServer, server: MemoryWormholeServer,
helper: TestingHelper, helper: TestingHelper,
messages: Sequence[JSONable], messages: Sequence[JSONable],
) -> Callable[[], Awaitable[IWormhole]]: ) -> Callable[[], Coroutine[defer.Deferred[IWormhole], Any, IWormhole]]:
""" """
Make a wormhole peer that just sends the given messages. Make a wormhole peer that just sends the given messages.
@ -102,18 +102,24 @@ A = TypeVar("A")
B = TypeVar("B") B = TypeVar("B")
def concurrently( def concurrently(
client: Callable[[], Awaitable[A]], client: Callable[[], Union[
server: Callable[[], Awaitable[B]], Coroutine[defer.Deferred[A], Any, A],
) -> defer.Deferred[tuple[A, B]]: Generator[defer.Deferred[A], Any, A],
]],
server: Callable[[], Union[
Coroutine[defer.Deferred[B], Any, B],
Generator[defer.Deferred[B], Any, B],
]],
) -> defer.Deferred[Tuple[A, B]]:
""" """
Run two asynchronous functions concurrently and asynchronously return a Run two asynchronous functions concurrently and asynchronously return a
tuple of both their results. tuple of both their results.
""" """
return defer.gatherResults([ result = defer.gatherResults([
defer.Deferred.fromCoroutine(client()), defer.Deferred.fromCoroutine(client()),
defer.Deferred.fromCoroutine(server()), defer.Deferred.fromCoroutine(server()),
]) ]).addCallback(tuple) # type: ignore
return cast(defer.Deferred[Tuple[A, B]], result)
class Join(GridTestMixin, CLITestMixin, unittest.TestCase): class Join(GridTestMixin, CLITestMixin, unittest.TestCase):