def final(arg):
    if inspect.isclass(arg):
        if not isinstance(arg, ObjectMetaclass):
            raise ValueError("@final can only be applied to a class "
                             "that is a subclass of Object")
    elif not is_method(arg):
        raise TypeError("@final can only be applied to classes or methods")
    method = arg.method if isinstance(arg, _WrappedMethod) else arg
    method.__final__ = True
    return arg