Use power of LazyInitialise to replace CallbackMixin.__init__()

This commit is contained in:
Kristóf Tóth 2018-06-01 14:21:32 +02:00
parent cebacb15e6
commit 6f3db18146
3 changed files with 5 additions and 4 deletions

View File

@ -36,7 +36,6 @@ class HistoryMonitor(CallbackMixin, ObserverMixin, ABC):
See examples below. See examples below.
""" """
def __init__(self, histfile): def __init__(self, histfile):
CallbackMixin.__init__(self)
self.histfile = histfile self.histfile = histfile
self._history = [] self._history = []
self._last_length = len(self._history) self._last_length = len(self._history)

View File

@ -19,7 +19,6 @@ class FSMBase(CallbackMixin):
states, transitions = [], [] states, transitions = [], []
def __init__(self, initial: str = None, accepted_states: List[str] = None): def __init__(self, initial: str = None, accepted_states: List[str] = None):
CallbackMixin.__init__(self)
self.accepted_states = accepted_states or [self.states[-1]] self.accepted_states = accepted_states or [self.states[-1]]
self.machine = Machine(model=self, self.machine = Machine(model=self,
states=self.states, states=self.states,

View File

@ -3,10 +3,13 @@
from functools import partial from functools import partial
from tfw.decorators import LazyInitialise
class CallbackMixin: class CallbackMixin:
def __init__(self): @LazyInitialise
self._callbacks = [] def _callbacks(self):
return []
def subscribe_callback(self, callback, *args, **kwargs): def subscribe_callback(self, callback, *args, **kwargs):
""" """