def METHOD_NAME(func):
    # type: (Callable) -> Callable
    """
    Decorator which creates a contextmanager that can also be used as a
    decorator, similar to how the built-in contextlib.contextmanager
    function works in Python 3.2+.
    """
    contextmanager_func = contextlib.METHOD_NAME(func)
    @wraps(func)
    class DecoratorContextManager:
        def __init__(self, *args, **kwargs):
            # type: (...) -> None
            self.the_contextmanager = contextmanager_func(*args, **kwargs)
        def __enter__(self):
            # type: () -> None
            self.the_contextmanager.__enter__()
        def __exit__(self, *args, **kwargs):
            # type: (...) -> None
            self.the_contextmanager.__exit__(*args, **kwargs)
        def __call__(self, decorated_func):
            # type: (Callable) -> Callable[...]
            @wraps(decorated_func)
            def when_called(*args, **kwargs):
                # type: (...) -> Any
                with self.the_contextmanager:
                    return_val = decorated_func(*args, **kwargs)
                return return_val
            return when_called
    return DecoratorContextManager