Skip to content

Commit

Permalink
Deprecate Conditions and Triggers Saved in handler Callable; Save C…
Browse files Browse the repository at this point in the history
…ondition in `signal.extra` Instead (#2608)
  • Loading branch information
ChihweiLHBird committed Dec 15, 2022
1 parent b276b91 commit 71d3d87
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions sanic/signals.py
Expand Up @@ -154,9 +154,7 @@ async def _dispatch(
try:
for signal in signals:
params.pop("__trigger__", None)
requirements = getattr(
signal.handler, "__requirements__", None
)
requirements = signal.extra.requirements
if (
(condition is None and signal.ctx.exclusive is False)
or (condition is None and not requirements)
Expand Down Expand Up @@ -219,8 +217,13 @@ def add( # type: ignore
if not trigger:
event = ".".join([*parts[:2], "<__trigger__>"])

handler.__requirements__ = condition # type: ignore
handler.__trigger__ = trigger # type: ignore
try:
# Attaching __requirements__ and __trigger__ to the handler
# is deprecated and will be removed in v23.6.
handler.__requirements__ = condition # type: ignore
handler.__trigger__ = trigger # type: ignore
except AttributeError:
pass

signal = super().add(
event,
Expand All @@ -232,6 +235,7 @@ def add( # type: ignore
signal.ctx.exclusive = exclusive
signal.ctx.trigger = trigger
signal.ctx.definition = event_definition
signal.extra.requirements = condition

return cast(Signal, signal)

Expand Down

0 comments on commit 71d3d87

Please sign in to comment.