Improve type annotations.

This commit is contained in:
Itamar Turner-Trauring 2023-03-24 10:18:15 -04:00
parent 0da059b644
commit 6659350ff3

View File

@ -14,6 +14,7 @@ from typing import (
TypeVar,
Optional,
)
from typing_extensions import Awaitable, ParamSpec
from foolscap.api import eventually
from eliot.twisted import (
@ -226,7 +227,11 @@ def until(
break
def async_to_deferred(f):
P = ParamSpec("P")
R = TypeVar("R")
def async_to_deferred(f: Callable[P, Awaitable[R]]) -> Callable[P, Deferred[R]]:
"""
Wrap an async function to return a Deferred instead.
@ -234,8 +239,8 @@ def async_to_deferred(f):
"""
@wraps(f)
def not_async(*args, **kwargs):
return defer.Deferred.fromCoroutine(f(*args, **kwargs))
def not_async(*args: P.args, **kwargs: P.kwargs) -> Deferred[R]:
return defer.Deferred.fromCoroutine(f(*args, **kwargs)) # type: ignore
return not_async