from typing import Any


def proxy_property(attribute: str, proxy: str) -> Any:
    """Create a property that is a proxy to an attribute of an attribute.

    Example:

        class Foo:
            proxy = Something()
            bar = proxy_property("baz", "proxy")

        foo = Foo()

        then foo.bar would be proxied to foo.proxy.baz

    If attribute is "a" and proxy is "b", it proxies to ".a.b".

    If the proxy value is None, then use a local value instead,
    which acts as a temporary storage in the meanwhile.
    """

    #
    # Typing note
    #
    # There is no real way to type properties returned by a function,
    # not to speak about the arbitrary getattr/setattr.
    # This explains the use of Any everywhere
    #

    not_proxied_value: Any = None

    def getter(obj: Any) -> Any:
        dest = getattr(obj, proxy)
        if dest is None:
            return not_proxied_value
        return getattr(dest, attribute)

    def setter(obj: Any, value: Any) -> None:
        dest = getattr(obj, proxy)
        if dest is None:
            nonlocal not_proxied_value
            not_proxied_value = value
        else:
            setattr(dest, attribute, value)

    return property(fget=getter, fset=setter)