Clarify/fix type hints throughout EventManager.py
This commit is contained in:
parent
08bd31f150
commit
10f84f970d
1 changed files with 8 additions and 7 deletions
|
@ -47,11 +47,11 @@ class EventHook(object):
|
||||||
self.log = log
|
self.log = log
|
||||||
self.name = name
|
self.name = name
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self._children = {}
|
self._children = {} # type: typing.Dict[str, EventHook]
|
||||||
self._hooks = []
|
self._hooks = [] # type: typing.List[EventCallback]
|
||||||
self._replayed = False
|
self._replayed = False
|
||||||
self._stored_events = []
|
self._stored_events = [] # type: typing.List[typing.Dict]
|
||||||
self._context_hooks = {}
|
self._context_hooks = {} # type: typing.Dict[str, typing.List[EventCallback]]
|
||||||
|
|
||||||
def _make_event(self, kwargs: dict) -> Event:
|
def _make_event(self, kwargs: dict) -> Event:
|
||||||
return Event(self._get_path(), **kwargs)
|
return Event(self._get_path(), **kwargs)
|
||||||
|
@ -84,9 +84,10 @@ class EventHook(object):
|
||||||
if context == None:
|
if context == None:
|
||||||
self._hooks.append(callback)
|
self._hooks.append(callback)
|
||||||
else:
|
else:
|
||||||
|
context_str = typing.cast(str, context)
|
||||||
if not context in self._context_hooks:
|
if not context in self._context_hooks:
|
||||||
self._context_hooks[context] = []
|
self._context_hooks[context_str] = []
|
||||||
self._context_hooks[context].append(callback)
|
self._context_hooks[context_str].append(callback)
|
||||||
|
|
||||||
if replay and not self._replayed:
|
if replay and not self._replayed:
|
||||||
for kwargs in self._stored_events:
|
for kwargs in self._stored_events:
|
||||||
|
@ -94,7 +95,7 @@ class EventHook(object):
|
||||||
self._replayed = True
|
self._replayed = True
|
||||||
return callback
|
return callback
|
||||||
|
|
||||||
def unhook(self, callback: "EventHook"):
|
def unhook(self, callback: "EventCallback"):
|
||||||
if callback in self._hooks:
|
if callback in self._hooks:
|
||||||
self._hooks.remove(callback)
|
self._hooks.remove(callback)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue