From 0ee728baacd6bb0c209ea5b8daed6ddba3348587 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Fri, 15 Nov 2024 09:15:23 +0100 Subject: [PATCH] Update src/frequenz/channels/_receiver.py Co-authored-by: Sahas Subramanian Signed-off-by: Leandro Lucarella --- src/frequenz/channels/_receiver.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/frequenz/channels/_receiver.py b/src/frequenz/channels/_receiver.py index c1991204..53862a45 100644 --- a/src/frequenz/channels/_receiver.py +++ b/src/frequenz/channels/_receiver.py @@ -316,15 +316,14 @@ def filter( """ ... # pylint: disable=unnecessary-ellipsis - # We need to use Any here because otherwise _Filter would have to deal with two - # different signatures. We can create two filter classes, one for regular functions - # and one for type guards, but then there is no way to tell at runtime which - # function is a type guard and which isn't to instantiate the correct class. - # Using Any here has no impact though, as thanks to the overloads, only the - # overloaded types will be accepted. def filter( - self, filter_function: Callable[[ReceiverMessageT_co], Any], / - ) -> Receiver[Any]: + self, + filter_function: ( + Callable[[ReceiverMessageT_co], bool] + | Callable[[ReceiverMessageT_co], TypeGuard[FilteredMessageT_co]] + ), + /, + ) -> Receiver[ReceiverMessageT_co] | Receiver[FilteredMessageT_co]: """Apply a filter function on the messages on a receiver. Note: