import inspect


def iscoroutinefunction(func):
    """Checks if a function is a coroutine-function, like:

     * ``async def f(): ...`` (since Python 3.5)
     * ``@asyncio.coroutine def f(): ...`` (since Python3)

    .. note:: Compatibility helper

        Avoids to import :mod:`asyncio` module directly (since Python3),
        which in turns initializes the :mod:`logging` module as side-effect.

    :param func:  Function to check.
    :return: True, if function is a coroutine function.
             False, otherwise.
    """
    # -- NOTE: inspect.iscoroutinefunction() is available since Python 3.5
    #    Checks also if @asyncio.coroutine decorator is not used.
    # pylint: disable=no-member
    return (getattr(func, "_is_coroutine", False) or
            (hasattr(inspect, "iscoroutinefunction") and
             inspect.iscoroutinefunction(func)))