Message254491
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/base_events.py", 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:39 | luhn | set | recipients:
+ luhn, gvanrossum, vstinner, yselivanov |
2015-11-11 16:50:39 | luhn | set | messageid: <1447260639.53.0.0574192699335.issue25599@psf.upfronthosting.co.za> |
2015-11-11 16:50:39 | luhn | link | issue25599 messages |
2015-11-11 16:50:39 | luhn | create | |
|