Skip to content

Commit 0ee728b

Browse files
llucaxshsms
andauthored
Update src/frequenz/channels/_receiver.py
Co-authored-by: Sahas Subramanian <[email protected]> Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 402338c commit 0ee728b

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/frequenz/channels/_receiver.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,14 @@ def filter(
316316
"""
317317
... # pylint: disable=unnecessary-ellipsis
318318

319-
# We need to use Any here because otherwise _Filter would have to deal with two
320-
# different signatures. We can create two filter classes, one for regular functions
321-
# and one for type guards, but then there is no way to tell at runtime which
322-
# function is a type guard and which isn't to instantiate the correct class.
323-
# Using Any here has no impact though, as thanks to the overloads, only the
324-
# overloaded types will be accepted.
325319
def filter(
326-
self, filter_function: Callable[[ReceiverMessageT_co], Any], /
327-
) -> Receiver[Any]:
320+
self,
321+
filter_function: (
322+
Callable[[ReceiverMessageT_co], bool]
323+
| Callable[[ReceiverMessageT_co], TypeGuard[FilteredMessageT_co]]
324+
),
325+
/,
326+
) -> Receiver[ReceiverMessageT_co] | Receiver[FilteredMessageT_co]:
328327
"""Apply a filter function on the messages on a receiver.
329328
330329
Note:

0 commit comments

Comments
 (0)