From 6104cbd5589ed9dba00b973c2ed0cb085314611c Mon Sep 17 00:00:00 2001 From: David Vogt Date: Wed, 29 Sep 2021 19:06:54 +0200 Subject: [PATCH] feat(events): allow the `sender` to be used in filter_events The `sender` attribute in signal handlers is special, as it will always be sent, and is thus not part of the `kwargs`. However it still makes sense to allow access to the sender in the `filter_events()` predicates --- caluma/caluma_core/events.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/caluma/caluma_core/events.py b/caluma/caluma_core/events.py index c4f962708..4be6e7d19 100644 --- a/caluma/caluma_core/events.py +++ b/caluma/caluma_core/events.py @@ -49,7 +49,10 @@ def filter_events(predicate): def decorate(func): @wraps(func) def wrapper(sender, *args, **kwargs): - predicate_args = {arg: kwargs[arg] for arg in predicate_arg_names} + # add sender to kwargs as well, so predicates can work on it + kwargs_lookup = kwargs.copy() + kwargs_lookup["sender"] = sender + predicate_args = {arg: kwargs_lookup[arg] for arg in predicate_arg_names} if predicate(**predicate_args): return func(sender, *args, **kwargs)