mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
Merge 3.5 (issue #28703)
This commit is contained in:
commit
27182bb232
3 changed files with 18 additions and 2 deletions
|
@ -33,12 +33,16 @@ _DEBUG = (not sys.flags.ignore_environment and
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_types_coroutine = types.coroutine
|
_types_coroutine = types.coroutine
|
||||||
|
_types_CoroutineType = types.CoroutineType
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
# Python 3.4
|
||||||
_types_coroutine = None
|
_types_coroutine = None
|
||||||
|
_types_CoroutineType = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_inspect_iscoroutinefunction = inspect.iscoroutinefunction
|
_inspect_iscoroutinefunction = inspect.iscoroutinefunction
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
# Python 3.4
|
||||||
_inspect_iscoroutinefunction = lambda func: False
|
_inspect_iscoroutinefunction = lambda func: False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -238,19 +242,27 @@ def coroutine(func):
|
||||||
w.__qualname__ = getattr(func, '__qualname__', None)
|
w.__qualname__ = getattr(func, '__qualname__', None)
|
||||||
return w
|
return w
|
||||||
|
|
||||||
wrapper._is_coroutine = True # For iscoroutinefunction().
|
wrapper._is_coroutine = _is_coroutine # For iscoroutinefunction().
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
# A marker for iscoroutinefunction.
|
||||||
|
_is_coroutine = object()
|
||||||
|
|
||||||
|
|
||||||
def iscoroutinefunction(func):
|
def iscoroutinefunction(func):
|
||||||
"""Return True if func is a decorated coroutine function."""
|
"""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))
|
_inspect_iscoroutinefunction(func))
|
||||||
|
|
||||||
|
|
||||||
_COROUTINE_TYPES = (types.GeneratorType, CoroWrapper)
|
_COROUTINE_TYPES = (types.GeneratorType, CoroWrapper)
|
||||||
if _CoroutineABC is not None:
|
if _CoroutineABC is not None:
|
||||||
_COROUTINE_TYPES += (_CoroutineABC,)
|
_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):
|
def iscoroutine(obj):
|
||||||
|
|
|
@ -1390,6 +1390,8 @@ class BaseTaskTests:
|
||||||
yield
|
yield
|
||||||
self.assertTrue(asyncio.iscoroutinefunction(fn2))
|
self.assertTrue(asyncio.iscoroutinefunction(fn2))
|
||||||
|
|
||||||
|
self.assertFalse(asyncio.iscoroutinefunction(mock.Mock()))
|
||||||
|
|
||||||
def test_yield_vs_yield_from(self):
|
def test_yield_vs_yield_from(self):
|
||||||
fut = self.new_future(self.loop)
|
fut = self.new_future(self.loop)
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,8 @@ Library
|
||||||
|
|
||||||
- Issue #28653: Fix a refleak in functools.lru_cache.
|
- Issue #28653: Fix a refleak in functools.lru_cache.
|
||||||
|
|
||||||
|
- Issue #28703: Fix asyncio.iscoroutinefunction to handle Mock objects.
|
||||||
|
|
||||||
Documentation
|
Documentation
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue