Clarify/fix type hints throughout EventManager.py

This commit is contained in:
jesopo 2018-12-02 10:04:05 +00:00
parent 08bd31f150
commit 10f84f970d

View file

@ -47,11 +47,11 @@ class EventHook(object):
self.log = log
self.name = name
self.parent = parent
self._children = {}
self._hooks = []
self._children = {} # type: typing.Dict[str, EventHook]
self._hooks = [] # type: typing.List[EventCallback]
self._replayed = False
self._stored_events = []
self._context_hooks = {}
self._stored_events = [] # type: typing.List[typing.Dict]
self._context_hooks = {} # type: typing.Dict[str, typing.List[EventCallback]]
def _make_event(self, kwargs: dict) -> Event:
return Event(self._get_path(), **kwargs)
@ -84,9 +84,10 @@ class EventHook(object):
if context == None:
self._hooks.append(callback)
else:
context_str = typing.cast(str, context)
if not context in self._context_hooks:
self._context_hooks[context] = []
self._context_hooks[context].append(callback)
self._context_hooks[context_str] = []
self._context_hooks[context_str].append(callback)
if replay and not self._replayed:
for kwargs in self._stored_events:
@ -94,7 +95,7 @@ class EventHook(object):
self._replayed = True
return callback
def unhook(self, callback: "EventHook"):
def unhook(self, callback: "EventCallback"):
if callback in self._hooks:
self._hooks.remove(callback)