def _call_as_function_or_method(f, event):
    """
    The idea here is that when using decorators in a class, the functions passed are not bound so we have to determine
    later if the functions we have (those saved as callbacks) for particular events need to be passed 'self'.

    Usually functions registered as callbacks should accept one and only one argument but an App subclass is viewed as
    a special case as it can provide a simple and pythonic way to implement the logic behind an application.

    This works for an App subclass method or a standalone decorated function. Will attempt to call function with event
    alone then try with self and event. This might not be a great idea if the function is unbound and normally takes
    two arguments... but people shouldn't be decorating functions that consume more than a single parameter anyway!

    Decorating methods of a class subclassing something other than App should produce AttributeError eventually which
    is hopefully understandable.
    """
    try:
        r = f(event)
        _log('given function {} is outside an App subclass definition'.format(repr(f)))
        return r
    except __HOLE__ as e:  # possibly try it with self if TypeError makes sense
        if e.message.endswith('takes exactly 2 arguments (1 given)'):
            r = f(getattr(App, '*app_instance'), event)
            _log('given function {} is probably inside a class (which should be an App subclass)'.format(repr(f)))
            return r
        raise e
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
dataset/ETHPy150Open beville/ComicStreamer/libs/rumps/rumps.py/_call_as_function_or_method