Skip to content

Commit 210f37a

Browse files
committed
typing: fix functools.partial call
Since mypy v1.11, uses of functools.partial are checked. Implementing protocol, since I didnt find other way to handle a generic `sig_handler` reference to callables of type `SignalHandlers`.
1 parent 4533934 commit 210f37a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

yaspin/core.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
Generator,
2929
Iterator,
3030
Optional,
31+
Protocol,
3132
Sequence,
3233
Type,
3334
TypeVar,
3435
Union,
3536
cast,
37+
runtime_checkable,
3638
)
3739

3840
from termcolor import ATTRIBUTES, COLORS, HIGHLIGHTS, colored
@@ -64,6 +66,11 @@ class Spinner:
6466
default_spinner = Spinner("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏", 80)
6567

6668

69+
@runtime_checkable
70+
class SignalHandlerProtocol(Protocol):
71+
def __call__(self, signum: int, frame: Any, spinner: Yaspin) -> None: ...
72+
73+
6774
def default_handler(signum: int, frame: Any, spinner: Yaspin) -> None: # pylint: disable=unused-argument
6875
"""Signal handler, used to gracefully shut down the ``spinner`` instance
6976
when specified signal is received by the process running the ``spinner``.
@@ -506,7 +513,7 @@ def _register_signal_handlers(self) -> None:
506513

507514
# ``signal.SIG_DFL`` and ``signal.SIG_IGN`` are also valid
508515
# signal handlers and are not callables.
509-
if callable(sig_handler):
516+
if callable(sig_handler) and isinstance(sig_handler, SignalHandlerProtocol):
510517
# ``signal.signal`` accepts handler function which is
511518
# called with two arguments: signal number and the
512519
# interrupted stack frame. ``functools.partial`` solves

0 commit comments

Comments
 (0)