Author luhn
Recipients gvanrossum, luhn, vstinner, yselivanov
Date 2015-11-11.16:50:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
For me, the context is a test I was writing that went something like this:

>>> import asyncio
>>> from unittest.mock import Mock
>>> loop = asyncio.get_event_loop()
>>> blocking_func = Mock()
>>> loop.run_in_executor(None, blocking_func)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/", line 497, in run_in_executor
    raise TypeError("coroutines cannot be used with run_in_executor()")
TypeError: coroutines cannot be used with run_in_executor()

I understand that the nature of Mock makes its behaviors ambiguous.  However, there are a few reasons I think asyncio.iscoroutinefunction(Mock()) should be false:

1) inspect.iscoroutinefunction reports false.  asyncio.iscoroutinefunction should be consistent with this.
2) A coroutine function should return a coroutine object.  Mock's default behavior won't return a coroutine object, so it shouldn't be identified as a coroutine function by default.
3) It's tidier to make a non-coroutine function Mock into a coroutine function (asyncio.coroutine(Mock())) than it is to make a coroutine function Mock into a non-coroutine function Mock (mock._is_coroutine is implementation-specific hack).
Date User Action Args
2015-11-11 16:50:39luhnsetrecipients: + luhn, gvanrossum, vstinner, yselivanov
2015-11-11 16:50:39luhnsetmessageid: <>
2015-11-11 16:50:39luhnlinkissue25599 messages
2015-11-11 16:50:39luhncreate