Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Commit ea776a1

Browse files
committed
Fix iscoroutinefunction() to support mock/proxy obejcts
1 parent eb4c3ff commit ea776a1

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

asyncio/coroutines.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,17 @@ def wrapper(*args, **kwds):
238238
w.__qualname__ = getattr(func, '__qualname__', None)
239239
return w
240240

241-
wrapper._is_coroutine = True # For iscoroutinefunction().
241+
wrapper._is_coroutine = _is_coroutine # For iscoroutinefunction().
242242
return wrapper
243243

244244

245+
# A marker for iscoroutinefunction.
246+
_is_coroutine = object()
247+
248+
245249
def iscoroutinefunction(func):
246250
"""Return True if func is a decorated coroutine function."""
247-
return (getattr(func, '_is_coroutine', False) or
251+
return (getattr(func, '_is_coroutine', None) is _is_coroutine or
248252
_inspect_iscoroutinefunction(func))
249253

250254

tests/test_tasks.py

+2
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,8 @@ def fn2():
13761376
yield
13771377
self.assertTrue(asyncio.iscoroutinefunction(fn2))
13781378

1379+
self.assertFalse(asyncio.iscoroutinefunction(mock.Mock()))
1380+
13791381
def test_yield_vs_yield_from(self):
13801382
fut = asyncio.Future(loop=self.loop)
13811383

0 commit comments

Comments
 (0)