Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Conditions and Triggers Saved in handler Callable; Save Condition in signal.extra Instead #2608

Merged
merged 8 commits into from Dec 15, 2022
10 changes: 5 additions & 5 deletions sanic/signals.py
Expand Up @@ -86,6 +86,8 @@ def __init__(self) -> None:
)
self.allow_fail_builtin = True
self.ctx.loop = None
self.triggers: Dict[SignalHandler, str] = dict()
self.conditions: Dict[SignalHandler, Optional[dict]] = dict()
ahopkins marked this conversation as resolved.
Show resolved Hide resolved

def get( # type: ignore
self,
Expand Down Expand Up @@ -154,9 +156,7 @@ async def _dispatch(
try:
for signal in signals:
params.pop("__trigger__", None)
requirements = getattr(
signal.handler, "__requirements__", None
)
requirements = self.conditions.get(signal.handler, None)
if (
(condition is None and signal.ctx.exclusive is False)
or (condition is None and not requirements)
Expand Down Expand Up @@ -219,8 +219,8 @@ def add( # type: ignore
if not trigger:
event = ".".join([*parts[:2], "<__trigger__>"])

handler.__requirements__ = condition # type: ignore
handler.__trigger__ = trigger # type: ignore
self.conditions[handler] = condition
self.triggers[handler] = trigger

signal = super().add(
event,
Expand Down