Duplicate all those functions and give them explicit names (e.g filter_sync, filter_async). Problem: I don't like the idea of duplicating all those operators
Implement some other kind of detection, for instance check if the result is awaitable. Problem: it becomes impossible to use awaitables as elements of a stream.
Perform a detection to issue a warning if a sync function returns an awaitable, mentioning the use of async_ to fix the warning. Problem: does not fully address the initial issue.
Here are the list of the combinators using
asyncio.iscoroutinefunction
to automatically detect whether the provided callback should be awaited or not:stream.accumulate
stream.map
stream.starmap
stream.call
stream.action
stream.filter
stream.until
stream.dropwhile
stream.takewhile
The problem with this detection is that it is hard to avoid false negatives.
However there are two counter-arguments to that:
functools.partial
has been fixed in python 3.8:I can see a few solutions here:
filter_sync
,filter_async
). Problem: I don't like the idea of duplicating all those operatorsasync_
to fix the warning. Problem: does not fully address the initial issue.Are there other alternative?