Skip to content

Commit b554e94

Browse files
committed
Ensure default_handled has an export-safe type
1 parent c02bbe9 commit b554e94

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/async_utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
__author__ = "Michael Hall"
1010
__license__ = "Apache-2.0"
1111
__copyright__ = "Copyright 2020-Present Michael Hall"
12-
__version__ = "2024.12.15"
12+
__version__ = "2024.12.16"
1313

1414
import os
1515
import sys

src/async_utils/sig_service.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@
2121
import sys
2222
from collections.abc import Callable
2323
from types import FrameType
24-
from typing import Any, Literal
24+
from typing import Any, Final, Literal
25+
26+
__all__ = ["SignalService", "SpecialExit"]
2527

2628
type SignalCallback = Callable[[signal.Signals | SpecialExit], Any]
2729
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
3432

35-
__all__ = ["SignalService", "SpecialExit"]
33+
type HandleableSignals = Literal["SIGINT", "SIGTERM", "SIGBREAK", "SIGHUP"]
34+
type SignalTuple = tuple[HandleableSignals, ...]
3635

3736

38-
default_handled = "SIGINT", "SIGTERM", "SIGBREAK"
37+
type _DEF = tuple[Literal["SIGINT"], Literal["SIGTERM"], Literal["SIGBREAK"]]
38+
default_handled: Final[_DEF] = "SIGINT", "SIGTERM", "SIGBREAK"
3939

4040

4141
class SpecialExit(enum.IntEnum):
@@ -137,7 +137,6 @@ def run(self) -> None:
137137
join()
138138

139139
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:
143142
signal.signal(sig, original)

0 commit comments

Comments
 (0)