Skip to content

Commit

Permalink
feat(events): allow the sender to be used in filter_events
Browse files Browse the repository at this point in the history
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
  • Loading branch information
winged committed Sep 29, 2021
1 parent 8f39e62 commit 6104cbd
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion caluma/caluma_core/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 6104cbd

Please sign in to comment.