Event autoregister (#2140)

* Add event autoregistration

* Setup tests

* Cleanup IDE added imports

* Remove unused imports
This commit is contained in:
Adam Hopkins
2021-06-01 10:44:07 +03:00
committed by GitHub
parent 16875b1f41
commit 0c3a8392f2
4 changed files with 82 additions and 24 deletions

View File

@@ -1,4 +1,4 @@
from typing import Any, Callable, Dict, Set
from typing import Any, Callable, Dict, Optional, Set
from sanic.models.futures import FutureSignal
from sanic.models.handler_types import SignalHandler
@@ -60,10 +60,16 @@ class SignalMixin:
def add_signal(
self,
handler,
handler: Optional[Callable[..., Any]],
event: str,
condition: Dict[str, Any] = None,
):
if not handler:
async def noop():
...
handler = noop
self.signal(event=event, condition=condition)(handler)
return handler