How to get function name as string in Python

The following variant also works reliably for member functions:

def func_name(func):
    """
    Get the name of a function.
    """
    if hasattr(func, '__qualname__'):
        return func.__qualname__
    elif hasattr(func, '__name__'):
        return func.__name__
    else:
        return repr(func)