Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coroutine function detection procudes false negatives #53

Open
vxgmichel opened this issue Dec 18, 2019 · 0 comments
Open

Coroutine function detection procudes false negatives #53

vxgmichel opened this issue Dec 18, 2019 · 0 comments

Comments

@vxgmichel
Copy link
Owner

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:
    assert asyncio.iscoroutinefunction(partial(asyncio.sleep, 3))
  • aiostream provides an async_ helper to force the argument to be treated as a coroutine function:
    ys = stream.map(xs, async_(lambda x: asyncio.sleep(x / 1000))

I can see a few solutions here:

  • 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.

Are there other alternative?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant