from typing import Optional
import inspect


def calling_module(skip=2) -> Optional[str]:
    """
    Returns the name of the module which called your function/method.
    
    :param int skip: Skip this many frames.
                 0 = module containing calling_function()
                 1 = module which called calling_function()
                 2 = module which called the function that called calling_function() (default)
                 and so on...
    :return str|None mod_name: Either a string containing the module name, or ``None`` if you've skipped too many frames.
                               If called from the main python script, then ``'__main__'`` will be returned instead of a
                               proper module path.
    """
    stk = inspect.stack()
    if len(stk) <= skip:
        return None
    mod = inspect.getmodule(stk[skip][0])
    if mod is None:
        return '__main__'
    return mod.__name__