<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def magic_contract(*args, **kwargs):
 """Drop-in replacement for ``pycontracts.contract`` decorator, except that it supports locally-visible types :param args: Arguments to pass to the ``contract`` decorator :param kwargs: Keyword arguments to pass to the ``contract`` decorator :return: The contracted function """

    def inner_decorator(f):
        for name, val in f.__globals__.items():
            if not name.startswith('_') and isinstance(val, type):
                safe_new_contract(name, val)
        return contract(*args, **kwargs)(f)

    return inner_decorator