import inspect


def get_class_that_defined_method(method):
    """
    Returns the class that defined the method
    Got implementation from stackoverflow
    http://stackoverflow.com/a/25959545/3903832
    """
    # for bound methods
    if inspect.ismethod(method):
        for cls in inspect.getmro(method.__self__.__class__):
            if cls.__dict__.get(method.__name__) is method:
                return cls.__name__
        method = method.__func__  # fallback to __qualname__ parsing

    # for unbound methods
    if inspect.isfunction(method):
        cls = getattr(inspect.getmodule(method),
                      method.__qualname__.split('.<locals>', 1)[0].rsplit('.', 1)[0])
        if isinstance(cls, type):
            return cls.__name__