# Buggy code
def getter_with_load_details(name: str, type: Union[str, Type]) -> Callable:
    """
    :note: confirm that the type annotation `get_foo = getter_with_load_details("_foo", type=int)  # type: Callable[..., int]` is correct one
    :note: this cannot be a decorator, since mypy fails to recognize the types

    This functions is bad one, but I think

        get_foo = getter_with_load_details("_foo", type=int)  # type: Callable[..., int]

    is better than

        def get_foo(self, session: Optional[requests.Session] = None) -> int:
            if self._foo is None:
                self._load_details(session=session)
                assert self._foo is not None
            return self._foo

    Of course the latter is better when it is used only once, but the former is better when the pattern is repeated.
    """

    @functools.wraps(lambda self: getattr(self, name))
    def wrapper(self, session: Optional[requests.Session] = None):
        if getattr(self, name) is None:
            assert session is None or isinstance(session, requests.Session)
            self._load_details(session=session)
        return getattr(self, name)

    # add documents
    assert type is not None
    py_class = lambda s: ":py:class:`{}`".format(s)
    if isinstance(type, str):
        if type.count("[") == 0:
            rst = py_class(type)
        elif type.count("[") == 1:
            a, b = remove_suffix(type, "]").split("[")
            rst = "{} [ {} ]".format(py_class(a), py_class(b))
        else:
            assert False
    elif type in (int, float, str, bytes, datetime.datetime, datetime.timedelta):
        rst = py_class(type.__name__)
    else:
        assert False
    wrapper.__doc__ = ":return: {}".format(rst)

    return wrapper


# Traceback (TypeError)
Traceback (most recent call last):
File "/home/ryo/workspace/github/chainer-wind-env/bin/oj", line 6, in <module>
exec(compile(open(__file__).read(), __file__, 'exec'))
File "/home/ryo/workspace/github/online-judge-tools/oj", line 4, in <module>
import onlinejudge._implementation.main
File "/home/ryo/workspace/github/online-judge-tools/onlinejudge/__init__.py", line 3, in <module>
import onlinejudge.service
File "/home/ryo/workspace/github/online-judge-tools/onlinejudge/service/__init__.py", line 2, in <module>
import onlinejudge.service.anarchygolf
File "/home/ryo/workspace/github/online-judge-tools/onlinejudge/service/anarchygolf.py", line 14, in <module>
import onlinejudge._implementation.testcase_zipper
File "/home/ryo/workspace/github/online-judge-tools/onlinejudge/_implementation/testcase_zipper.py", line 9, in <module>
import onlinejudge._implementation.format_utils
File "/home/ryo/workspace/github/online-judge-tools/onlinejudge/_implementation/format_utils.py", line 11, in <module>
import onlinejudge._implementation.utils as utils
File "/home/ryo/workspace/github/online-judge-tools/onlinejudge/_implementation/utils.py", line 215, in <module>
def getter_with_load_details(name: str, type: Union[str, Type]) -> Callable:
File "/usr/lib/python3.5/typing.py", line 552, in __getitem__
dict(self.__dict__), parameters, _root=True)
File "/usr/lib/python3.5/typing.py", line 512, in __new__
for t2 in all_params - {t1} if not isinstance(t2, TypeVar)):
File "/usr/lib/python3.5/typing.py", line 512, in <genexpr>
for t2 in all_params - {t1} if not isinstance(t2, TypeVar)):
File "/usr/lib/python3.5/typing.py", line 1077, in __subclasscheck__
if super().__subclasscheck__(cls):
File "/home/ryo/workspace/github/chainer-wind-env/lib/python3.5/abc.py", line 225, in __subclasscheck__
for scls in cls.__subclasses__():
TypeError: descriptor '__subclasses__' of 'type' object needs an argument

# Fixed code
def getter_with_load_details(name: str, type: Union[str, type]) -> Callable:
    """
    :note: confirm that the type annotation `get_foo = getter_with_load_details("_foo", type=int)  # type: Callable[..., int]` is correct one
    :note: this cannot be a decorator, since mypy fails to recognize the types

    This functions is bad one, but I think

        get_foo = getter_with_load_details("_foo", type=int)  # type: Callable[..., int]

    is better than

        def get_foo(self, session: Optional[requests.Session] = None) -> int:
            if self._foo is None:
                self._load_details(session=session)
                assert self._foo is not None
            return self._foo

    Of course the latter is better when it is used only once, but the former is better when the pattern is repeated.
    """

    @functools.wraps(lambda self: getattr(self, name))
    def wrapper(self, session: Optional[requests.Session] = None):
        if getattr(self, name) is None:
            assert session is None or isinstance(session, requests.Session)
            self._load_details(session=session)
        return getattr(self, name)

    # add documents
    assert type is not None
    py_class = lambda s: ":py:class:`{}`".format(s)
    if isinstance(type, str):
        if type.count("[") == 0:
            rst = py_class(type)
        elif type.count("[") == 1:
            a, b = remove_suffix(type, "]").split("[")
            rst = "{} [ {} ]".format(py_class(a), py_class(b))
        else:
            assert False
    elif type in (int, float, str, bytes, datetime.datetime, datetime.timedelta):
        rst = py_class(type.__name__)
    else:
        assert False
    wrapper.__doc__ = ":return: {}".format(rst)

    return wrapper