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

This commit is contained in:
Zhiwei 2022-12-15 04:32:07 -06:00 committed by GitHub
parent b276b91c21
commit 71d3d87bcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -154,9 +154,7 @@ class SignalRouter(BaseRouter):
try: try:
for signal in signals: for signal in signals:
params.pop("__trigger__", None) params.pop("__trigger__", None)
requirements = getattr( requirements = signal.extra.requirements
signal.handler, "__requirements__", None
)
if ( if (
(condition is None and signal.ctx.exclusive is False) (condition is None and signal.ctx.exclusive is False)
or (condition is None and not requirements) or (condition is None and not requirements)
@ -219,8 +217,13 @@ class SignalRouter(BaseRouter):
if not trigger: if not trigger:
event = ".".join([*parts[:2], "<__trigger__>"]) event = ".".join([*parts[:2], "<__trigger__>"])
try:
# Attaching __requirements__ and __trigger__ to the handler
# is deprecated and will be removed in v23.6.
handler.__requirements__ = condition # type: ignore handler.__requirements__ = condition # type: ignore
handler.__trigger__ = trigger # type: ignore handler.__trigger__ = trigger # type: ignore
except AttributeError:
pass
signal = super().add( signal = super().add(
event, event,
@ -232,6 +235,7 @@ class SignalRouter(BaseRouter):
signal.ctx.exclusive = exclusive signal.ctx.exclusive = exclusive
signal.ctx.trigger = trigger signal.ctx.trigger = trigger
signal.ctx.definition = event_definition signal.ctx.definition = event_definition
signal.extra.requirements = condition
return cast(Signal, signal) return cast(Signal, signal)