[issue25599] asyncio.iscoroutinefunction returns unexpected results when presented with unittest.mock.Mock

2015-11-11 Thread Theron Luhn

Theron Luhn added the comment:

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 "", line 1, in 
  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).

--

___
Python tracker 
<http://bugs.python.org/issue25599>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25599] asyncio.iscoroutinefunction returns unexpected results when presented with unittest.mock.Mock

2015-11-10 Thread Theron Luhn

New submission from Theron Luhn:

>>> asyncio.iscoroutinefunction(unittest.mock.Mock())


This is an unexpected response, both in type (Mock rather than boolean) and 
value (truthy).

inspect.iscoroutinefunction behaves as expected.

Workaround:

>>> m = unittest.mock.Mock()
>>> m._is_coroutine = False
>>> asyncio.iscoroutinefunction(m)
False

--
components: asyncio
messages: 254457
nosy: Theron Luhn, gvanrossum, haypo, yselivanov
priority: normal
severity: normal
status: open
title: asyncio.iscoroutinefunction returns unexpected results when presented 
with unittest.mock.Mock
type: behavior
versions: Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6

___
Python tracker 
<http://bugs.python.org/issue25599>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com