|
32 | 32 | TypeVar,
|
33 | 33 | )
|
34 | 34 |
|
| 35 | +from typing_extensions import ParamSpec |
| 36 | + |
35 | 37 | import duet.impl as impl
|
36 | 38 | from duet.aitertools import aenumerate, aiter, AnyIterable, AsyncCollector
|
37 | 39 | from duet.futuretools import AwaitableFuture
|
38 | 40 |
|
| 41 | +P = ParamSpec("P") |
39 | 42 | T = TypeVar("T")
|
40 | 43 | U = TypeVar("U")
|
41 | 44 |
|
42 | 45 |
|
43 |
| -def run(func: Callable[..., Awaitable[T]], *args, **kwds) -> T: |
| 46 | +def run(func: Callable[P, Awaitable[T]], *args: P.args, **kwds: P.kwargs) -> T: |
44 | 47 | """Run an async function to completion.
|
45 | 48 |
|
46 | 49 | Args:
|
@@ -72,7 +75,7 @@ def run(func: Callable[..., Awaitable[T]], *args, **kwds) -> T:
|
72 | 75 | scheduler.cleanup_signals()
|
73 | 76 |
|
74 | 77 |
|
75 |
| -def sync(f: Callable[..., Awaitable[T]]) -> Callable[..., T]: |
| 78 | +def sync(f: Callable[P, Awaitable[T]]) -> Callable[P, T]: |
76 | 79 | """Decorator that adds a sync version of async function or method."""
|
77 | 80 | if isinstance(f, classmethod):
|
78 | 81 | raise TypeError(f"duet.sync cannot be applied to classmethod {f.__func__}")
|
@@ -113,7 +116,7 @@ def wrapped(self, *args, **kw):
|
113 | 116 | def wrapped(*args, **kw):
|
114 | 117 | return run(f, *args, **kw)
|
115 | 118 |
|
116 |
| - return wrapped |
| 119 | + return wrapped # type: ignore[return-value] |
117 | 120 |
|
118 | 121 |
|
119 | 122 | def awaitable(value):
|
@@ -375,12 +378,14 @@ def __init__(
|
375 | 378 | def cancel(self) -> None:
|
376 | 379 | self._main_task.interrupt(self._main_task, CancelledError())
|
377 | 380 |
|
378 |
| - def spawn(self, func: Callable[..., Awaitable[Any]], *args, **kwds) -> None: |
| 381 | + def spawn(self, func: Callable[P, Awaitable[Any]], *args: P.args, **kwds: P.kwargs) -> None: |
379 | 382 | """Starts a background task that will run the given function."""
|
380 | 383 | task = self._scheduler.spawn(self._run(func, *args, **kwds), main_task=self._main_task)
|
381 | 384 | self._tasks.add(task)
|
382 | 385 |
|
383 |
| - async def _run(self, func: Callable[..., Awaitable[Any]], *args, **kwds) -> None: |
| 386 | + async def _run( |
| 387 | + self, func: Callable[P, Awaitable[Any]], *args: P.args, **kwds: P.kwargs |
| 388 | + ) -> None: |
384 | 389 | task = impl.current_task()
|
385 | 390 | try:
|
386 | 391 | await func(*args, **kwds)
|
@@ -513,7 +518,7 @@ def scope(self) -> Scope:
|
513 | 518 | def limiter(self) -> Limiter:
|
514 | 519 | pass
|
515 | 520 |
|
516 |
| - def spawn(self, func: Callable[..., Awaitable[Any]], *args, **kwds) -> None: |
| 521 | + def spawn(self, func: Callable[P, Awaitable[Any]], *args: P.args, **kwds: P.kwargs) -> None: |
517 | 522 | """Starts a background task that will run the given function."""
|
518 | 523 | self.scope.spawn(func, *args, **kwds)
|
519 | 524 |
|
|
0 commit comments