mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 18:03:31 +01:00
This commit fixes Python errors and warnings reported by static type checking with mypy. Signed-off-by: Jan Lindemann <jan@janware.com>
35 lines
978 B
Python
35 lines
978 B
Python
from abc import ABC, abstractmethod
|
|
from typing import Dict, Callable
|
|
|
|
_handled_signals: Dict[int, Callable] = {}
|
|
|
|
def _signal_handler(signal, frame):
|
|
if not signal in _handled_signals.keys():
|
|
return
|
|
for h in _handled_signals[signal]:
|
|
h.func(signal, *h.args)
|
|
|
|
class Signals:
|
|
|
|
class Handler:
|
|
def __init__(self, func, args):
|
|
self.func = func
|
|
self.args = args
|
|
|
|
def __init(self):
|
|
pass
|
|
|
|
@classmethod
|
|
@abstractmethod
|
|
def _add_handler(self, signal, handler):
|
|
raise Exception("_add_handler() is not reimplemented")
|
|
|
|
@classmethod
|
|
def add_handler(cls, signals, handler, *args):
|
|
for signal in signals:
|
|
h = Signals.Handler(handler, args)
|
|
if not signal in _handled_signals.keys():
|
|
_handled_signals[signal] = [h]
|
|
cls._add_signal_handler(signal, _signal_handler)
|
|
else:
|
|
_handled_signals[signal].add(h)
|