Skip to content

Commit

Permalink
Update src/frequenz/channels/_receiver.py
Browse files Browse the repository at this point in the history
Co-authored-by: Sahas Subramanian <[email protected]>
Signed-off-by: Leandro Lucarella <[email protected]>
  • Loading branch information
llucax and shsms authored Nov 15, 2024
1 parent 402338c commit 0ee728b
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/frequenz/channels/_receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 0ee728b

Please sign in to comment.