FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix iscoroutinefunction() to support mock/proxy obejcts by 1st1 · Pull Request #459 · python/asyncio · GitHub

This repository was archived by the owner on Nov 23, 2017. It is now read-only.
/ asyncio Public archive
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
16 changes: 14 additions & 2 deletions asyncio/coroutines.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@

try:
_types_coroutine = types.coroutine
_types_CoroutineType = types.CoroutineType
except AttributeError:
# Python 3.4
_types_coroutine = None
_types_CoroutineType = None

try:
_inspect_iscoroutinefunction = inspect.iscoroutinefunction
except AttributeError:
# Python 3.4
_inspect_iscoroutinefunction = lambda func: False

try:
Expand Down Expand Up @@ -238,19 +242,27 @@ def wrapper(*args, **kwds):
w.__qualname__ = getattr(func, '__qualname__', None)
return w

wrapper._is_coroutine = True # For iscoroutinefunction().
wrapper._is_coroutine = _is_coroutine # For iscoroutinefunction().
return wrapper


# A marker for iscoroutinefunction.
_is_coroutine = object()


def iscoroutinefunction(func):
"""Return True if func is a decorated coroutine function."""
return (getattr(func, '_is_coroutine', False) or
return (getattr(func, '_is_coroutine', None) is _is_coroutine or
_inspect_iscoroutinefunction(func))


_COROUTINE_TYPES = (types.GeneratorType, CoroWrapper)
if _CoroutineABC is not None:
_COROUTINE_TYPES += (_CoroutineABC,)
if _types_CoroutineType is not None:
# Prioritize native coroutine check to speed-up
# asyncio.iscoroutine.
_COROUTINE_TYPES = (_types_CoroutineType,) + _COROUTINE_TYPES


def iscoroutine(obj):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_tasks.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,8 @@ def fn2():
yield
self.assertTrue(asyncio.iscoroutinefunction(fn2))

self.assertFalse(asyncio.iscoroutinefunction(mock.Mock()))

def test_yield_vs_yield_from(self):
fut = asyncio.Future(loop=self.loop)

Expand Down

Back | FazBrowse Home | New Git URL