Skip to content

Instantly share code, notes, and snippets.

@luke14free
Created October 20, 2019 15:55
Show Gist options
  • Save luke14free/12f09882b5f43408b8836e43b7db1cac to your computer and use it in GitHub Desktop.
Save luke14free/12f09882b5f43408b8836e43b7db1cac to your computer and use it in GitHub Desktop.
FROZEN_ERROR = 'frozen objects are read only'
def frozen(iterable):
class Frozen(type(iterable)):
def __setitem__(self, key, value):
raise Exception(FROZEN_ERROR)
def __set__(self, instance, value):
raise Exception(FROZEN_ERROR)
def __delitem__(self, key):
raise Exception(FROZEN_ERROR)
def __delete__(self, instance):
raise Exception(FROZEN_ERROR)
def __delslice__(self, i, j):
raise Exception(FROZEN_ERROR)
def __setattr__(self, key, value):
raise Exception(FROZEN_ERROR)
def __setstate__(self, state):
raise Exception(FROZEN_ERROR)
def __setslice__(self, i, j, sequence):
raise Exception(FROZEN_ERROR)
def __trunc__(self):
raise Exception(FROZEN_ERROR)
def clear(self):
raise Exception(FROZEN_ERROR)
def append(self, *args, **kwargs):
raise Exception(FROZEN_ERROR)
def insert(self, *args, **kwargs):
raise Exception(FROZEN_ERROR)
def pop(self, *args, **kwargs):
raise Exception(FROZEN_ERROR)
def update(self, *args, **kwargs):
raise Exception(FROZEN_ERROR)
return Frozen(iterable)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment