Skip to content

Commit 8583f7a

Browse files
committed
improve sched.scheduler.enterabs/sched.scheduler.enter type annotations
fixes
1 parent 3b54e36 commit 8583f7a

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

stdlib/sched.pyi

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
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
55

66
__all__ = ["scheduler"]
77

8+
_KwargValue = TypeVar("_KwargValue")
9+
_R = TypeVar("_R")
10+
_Args = TypeVarTuple("_Args")
11+
12+
class _MyCallable(Generic[Unpack[_Args], _KwargValue, _R]):
13+
def __call__(self, args: tuple[Unpack[_Args]], kwargs: Mapping[str, _KwargValue]) -> _R: ...
14+
815
_ActionCallback: TypeAlias = Callable[..., Any]
916

1017
if sys.version_info >= (3, 10):
@@ -33,11 +40,41 @@ class scheduler:
3340
delayfunc: Callable[[float], object]
3441

3542
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
3653
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], _KwargValue, object],
58+
argument: tuple[Unpack[_Args]] = ...,
59+
kwargs: Mapping[str, _KwargValue] = ...,
60+
) -> Event: ...
61+
@overload
62+
def enter(
63+
self,
64+
delay: float,
65+
priority: Any,
66+
action: Callable[[], object],
67+
argument: tuple[()] = ...,
68+
kwargs: Mapping[Never, Never] = ...,
3869
) -> Event: ...
70+
@overload
3971
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], _KwargValue, object],
76+
argument: tuple[Unpack[_Args]] = ...,
77+
kwargs: Mapping[str, _KwargValue] = ...,
4178
) -> Event: ...
4279
def run(self, blocking: bool = True) -> float | None: ...
4380
def cancel(self, event: Event) -> None: ...

0 commit comments

Comments
 (0)