jasily/lang/proxy.py
def readonly(obj, *, error_on_set = False):
    '''
    return a readonly proxy for the `obj`.

    all modify on the proxy will not apply on origin object.
    '''
    base_cls = type(obj)

    class ReadonlyProxy(base_cls):
        def __getattribute__(self, name):
            return getattr(obj, name)

        def __setattr__(self, name, value):
            if error_on_set:
                raise AttributeError('cannot set readonly object.')

    update_wrapper(ReadonlyProxy, base_cls, updated = ())
    return ReadonlyProxy()
def readonly(obj, *, error_on_set = False):
    '''
    return a readonly proxy for the `obj`.

    all modify on the proxy will not apply on origin object.
    '''
    base_cls = type(obj)

    class ReadonlyProxy(base_cls):
        def __getattribute__(self, name):
            return getattr(obj, name)

        def __setattr__(self, name, value):
            if error_on_set:
                raise AttributeError('cannot set readonly object.')

    update_wrapper(ReadonlyProxy, base_cls, updated = ())
    return ReadonlyProxy()
return a readonly proxy for the `obj`.

    all modify on the proxy will not apply on origin object.