(func)
return wrapper
Decorator to mark coroutines.

    If the coroutine is not yielded from before it is destroyed,
    an error message is logged.
Decorator to mark coroutines.
Decorator to mark coroutines .
def coroutine(func):
    """Decorator to mark coroutines.

    If the coroutine is not yielded from before it is destroyed,
    an error message is logged.
    """
    warnings.warn('"@coroutine" decorator is deprecated since Python 3.8, use "async def" instead',
                  DeprecationWarning,
                  stacklevel=2)
    if inspect.iscoroutinefunction(func):
        # In Python 3.5 that's all we need to do for coroutines
        # defined with "async def".
        return func

    if inspect.isgeneratorfunction(func):
        coro = func
    else:
        @functools.wraps(func)
        def coro(*args, **kw):
            res = func(*args, **kw)
            if (base_futures.isfuture(res) or inspect.isgenerator(res) or
                    isinstance(res, CoroWrapper)):
                res = yield from res
            else:
                # If 'res' is an awaitable, run it.
                try:
                    await_meth = res.__await__
                except AttributeError:
                    pass
                else:
                    if isinstance(res, collections.abc.Awaitable):
                        res = yield from await_meth()
            return res

    coro = types.coroutine(coro)
    if not _DEBUG:
        wrapper = coro
    else:
        @functools.wraps(func)
        def wrapper(*args, **kwds):
            w = CoroWrapper(coro(*args, **kwds), func=func)
            if w._source_traceback:
                del w._source_traceback[-1]
            # Python < 3.5 does not implement __qualname__
            # on generator objects, so we set it manually.
            # We use getattr as some callables (such as
            # functools.partial may lack __qualname__).
            w.__name__ = getattr(func, '__name__', None)
            w.__qualname__ = getattr(func, '__qualname__', None)
            return w

    wrapper._is_coroutine = _is_coroutine  # For iscoroutinefunction().
    return wrapper
def coroutine ( func ) : warnings . warn ( '"@coroutine" decorator is deprecated since Python 3.8, use "async def" instead' , DeprecationWarning , stacklevel = 2 ) if inspect . iscoroutinefunction ( func ) : # In Python 3.5 that's all we need to do for coroutines # defined with "async def". return func if inspect . isgeneratorfunction ( func ) : coro = func else : @ functools . wraps ( func ) def coro ( * args , * * kw ) : res = func ( * args , * * kw ) if ( base_futures . isfuture ( res ) or inspect . isgenerator ( res ) or isinstance ( res , CoroWrapper ) ) : res = yield from res else : # If 'res' is an awaitable, run it. try : await_meth = res . __await__ except AttributeError : pass else : if isinstance ( res , collections . abc . Awaitable ) : res = yield from await_meth ( ) return res coro = types . coroutine ( coro ) if not _DEBUG : wrapper = coro else : @ functools . wraps ( func ) def wrapper ( * args , * * kwds ) : w = CoroWrapper ( coro ( * args , * * kwds ) , func = func ) if w . _source_traceback : del w . _source_traceback [ - 1 ] # Python < 3.5 does not implement __qualname__ # on generator objects, so we set it manually. # We use getattr as some callables (such as # functools.partial may lack __qualname__). w . __name__ = getattr ( func , '__name__' , None ) w . __qualname__ = getattr ( func , '__qualname__' , None ) return w wrapper . _is_coroutine = _is_coroutine # For iscoroutinefunction(). return wrapper