From 6a4346587cf06f7603572796daf4851bd98a1415 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Fri, 17 Mar 2023 15:46:27 -0400 Subject: [PATCH] Fix the type annotations --- src/allmydata/test/test_iputil.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/allmydata/test/test_iputil.py b/src/allmydata/test/test_iputil.py index c060fcc04..26274830f 100644 --- a/src/allmydata/test/test_iputil.py +++ b/src/allmydata/test/test_iputil.py @@ -11,7 +11,6 @@ import gc from functools import wraps from typing import TypeVar, Callable -from typing_extensions import TypeAlias from testtools.matchers import ( MatchesAll, IsInstance, @@ -33,12 +32,10 @@ from .common import ( SyncTestCase, ) -T = TypeVar("T") +T = TypeVar("T", contravariant=True) +U = TypeVar("U", covariant=True) -TestFunction: TypeAlias = Callable[[], T] -Decorator: TypeAlias = Callable[[TestFunction[T]], TestFunction[T]] - -def retry(stop: Callable[[], bool]) -> Decorator[T]: +def retry(stop: Callable[[], bool]) -> Callable[[Callable[[T], U]], Callable[[T], U]]: """ Call a function until the predicate says to stop or the function stops raising an exception. @@ -49,9 +46,9 @@ def retry(stop: Callable[[], bool]) -> Decorator[T]: :return: A decorator function. """ - def decorate(f: TestFunction[T]) -> TestFunction[T]: + def decorate(f: Callable[[T], U]) -> Callable[[T], U]: @wraps(f) - def decorator(self) -> T: + def decorator(self: T) -> U: while True: try: return f(self)