import inspect


def outer2_args(skip_self=True):
    """Get outer outer func args.

    Get the arguments of the function, which is an external function for the
    function inside which this function is called.

    Args:
    skip_self (bool):
        True: skip the argument named `self`
        False: doesn't skip the argument named `self`

    Example:
        >>> from telegrambotapiwrapper.frames import outer2_args
        >>> def func(a, b, c):
        ...     def foo(d, e, f):
        ...         args = outer2_args()
        ...         print(args)
        ...     foo(123, 234, 456)
        ... func(567, 678, 789)
        {'a': 567, 'b': 678, 'c': 789}

    """
    currframe = inspect.currentframe()
    outerouterframe = inspect.getouterframes(currframe, 1)
    args, _, _, values = inspect.getargvalues(outerouterframe[2][0])

    if skip_self:  # pylint: disable=R1705
        return {
            key: value
            for key, value in values.items()
            if (key in args) and (key != 'self')
        }
    else:
        return {key: value for key, value in values.items() if key in args}