|
21 | 21 | import sys |
22 | 22 | from collections.abc import Callable |
23 | 23 | from types import FrameType |
24 | | -from typing import Any, Literal |
| 24 | +from typing import Any, Final, Literal |
| 25 | + |
| 26 | +__all__ = ["SignalService", "SpecialExit"] |
25 | 27 |
|
26 | 28 | type SignalCallback = Callable[[signal.Signals | SpecialExit], Any] |
27 | 29 | type StartStopCall = Callable[[], Any] |
28 | | -type _HANDLER = ( |
29 | | - Callable[[int, FrameType | None], Any] | int | signal.Handlers | None |
30 | | -) |
31 | | -type SignalTuple = tuple[ |
32 | | - Literal["SIGINT", "SIGTERM", "SIGBREAK", "SIGHUP"], ... |
33 | | -] |
| 30 | +type _HTC = Callable[[int, FrameType | None], Any] |
| 31 | +type _HANDLER = _HTC | int | signal.Handlers | None |
34 | 32 |
|
35 | | -__all__ = ["SignalService", "SpecialExit"] |
| 33 | +type HandleableSignals = Literal["SIGINT", "SIGTERM", "SIGBREAK", "SIGHUP"] |
| 34 | +type SignalTuple = tuple[HandleableSignals, ...] |
36 | 35 |
|
37 | 36 |
|
38 | | -default_handled = "SIGINT", "SIGTERM", "SIGBREAK" |
| 37 | +type _DEF = tuple[Literal["SIGINT"], Literal["SIGTERM"], Literal["SIGBREAK"]] |
| 38 | +default_handled: Final[_DEF] = "SIGINT", "SIGTERM", "SIGBREAK" |
39 | 39 |
|
40 | 40 |
|
41 | 41 | class SpecialExit(enum.IntEnum): |
@@ -137,7 +137,6 @@ def run(self) -> None: |
137 | 137 | join() |
138 | 138 |
|
139 | 139 | finally: |
140 | | - for sig, original in zip( |
141 | | - self._signals, original_handlers, strict=False |
142 | | - ): |
| 140 | + it = zip(self._signals, original_handlers, strict=False) |
| 141 | + for sig, original in it: |
143 | 142 | signal.signal(sig, original) |
0 commit comments