|
1 | 1 | import sys
|
2 |
| -from collections.abc import Callable |
3 |
| -from typing import Any, ClassVar, NamedTuple, type_check_only |
4 |
| -from typing_extensions import TypeAlias |
| 2 | +from collections.abc import Callable, Mapping |
| 3 | +from typing import Any, ClassVar, Generic, NamedTuple, TypeVar, overload, type_check_only |
| 4 | +from typing_extensions import Never, TypeAlias, TypeVarTuple, Unpack |
5 | 5 |
|
6 | 6 | __all__ = ["scheduler"]
|
7 | 7 |
|
| 8 | +_V = TypeVar("_V") |
| 9 | +_R = TypeVar("_R") |
| 10 | +_Args = TypeVarTuple("_Args") |
| 11 | + |
| 12 | +class _MyCallable(Generic[Unpack[_Args], _V, _R]): |
| 13 | + def __call__(self, args: tuple[Unpack[_Args]], kwargs: Mapping[str, _V]) -> _R: ... |
| 14 | + |
8 | 15 | _ActionCallback: TypeAlias = Callable[..., Any]
|
9 | 16 |
|
10 | 17 | if sys.version_info >= (3, 10):
|
@@ -33,11 +40,41 @@ class scheduler:
|
33 | 40 | delayfunc: Callable[[float], object]
|
34 | 41 |
|
35 | 42 | def __init__(self, timefunc: Callable[[], float] = ..., delayfunc: Callable[[float], object] = ...) -> None: ...
|
| 43 | + @overload |
| 44 | + def enterabs( |
| 45 | + self, |
| 46 | + time: float, |
| 47 | + priority: Any, |
| 48 | + action: Callable[[], object], |
| 49 | + argument: tuple[()] = ..., |
| 50 | + kwargs: Mapping[Never, Never] = ..., |
| 51 | + ) -> Event: ... |
| 52 | + @overload |
36 | 53 | def enterabs(
|
37 |
| - self, time: float, priority: Any, action: _ActionCallback, argument: tuple[Any, ...] = (), kwargs: dict[str, Any] = ... |
| 54 | + self, |
| 55 | + time: float, |
| 56 | + priority: Any, |
| 57 | + action: _MyCallable[Unpack[_Args], _V, _R], |
| 58 | + argument: tuple[Unpack[_Args]] = ..., |
| 59 | + kwargs: Mapping[str, _V] = ..., |
| 60 | + ) -> Event: ... |
| 61 | + @overload |
| 62 | + def enter( |
| 63 | + self, |
| 64 | + time: float, |
| 65 | + priority: Any, |
| 66 | + action: Callable[[], object], |
| 67 | + argument: tuple[()] = ..., |
| 68 | + kwargs: Mapping[Never, Never] = ..., |
38 | 69 | ) -> Event: ...
|
| 70 | + @overload |
39 | 71 | def enter(
|
40 |
| - self, delay: float, priority: Any, action: _ActionCallback, argument: tuple[Any, ...] = (), kwargs: dict[str, Any] = ... |
| 72 | + self, |
| 73 | + delay: float, |
| 74 | + priority: Any, |
| 75 | + action: _MyCallable[Unpack[_Args], _V, _R], |
| 76 | + argument: tuple[Unpack[_Args]] = ..., |
| 77 | + kwargs: Mapping[str, _V] = ..., |
41 | 78 | ) -> Event: ...
|
42 | 79 | def run(self, blocking: bool = True) -> float | None: ...
|
43 | 80 | def cancel(self, event: Event) -> None: ...
|
|
0 commit comments