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: