From 8d99ddc542825e4e893b92546fe0856bb283b701 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Thu, 15 Jun 2023 17:14:08 -0400 Subject: [PATCH] Pacify mypy --- src/allmydata/test/cli/test_invite.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/allmydata/test/cli/test_invite.py b/src/allmydata/test/cli/test_invite.py index 31992a54d..1302e5970 100644 --- a/src/allmydata/test/cli/test_invite.py +++ b/src/allmydata/test/cli/test_invite.py @@ -8,7 +8,7 @@ import json import os from functools import partial 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.trial import unittest @@ -60,7 +60,7 @@ def make_simple_peer( server: MemoryWormholeServer, helper: TestingHelper, messages: Sequence[JSONable], -) -> Callable[[], Awaitable[IWormhole]]: +) -> Callable[[], Coroutine[defer.Deferred[IWormhole], Any, IWormhole]]: """ Make a wormhole peer that just sends the given messages. @@ -102,18 +102,24 @@ A = TypeVar("A") B = TypeVar("B") def concurrently( - client: Callable[[], Awaitable[A]], - server: Callable[[], Awaitable[B]], -) -> defer.Deferred[tuple[A, B]]: + client: Callable[[], Union[ + Coroutine[defer.Deferred[A], Any, A], + 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 tuple of both their results. """ - return defer.gatherResults([ + result = defer.gatherResults([ defer.Deferred.fromCoroutine(client()), defer.Deferred.fromCoroutine(server()), - ]) - + ]).addCallback(tuple) # type: ignore + return cast(defer.Deferred[Tuple[A, B]], result) class Join(GridTestMixin, CLITestMixin, unittest.TestCase):