Created
December 19, 2019 21:54
-
-
Save freemo/c31eb7f28c10db18bc2dcfce0dd75864 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ImmutableMeta(ElementMeta): | |
def __new__(cls, name, bases, namespace, **kwargs): | |
def my_setattr(self, name, value): | |
if hasattr(self, "_immutable") and self._immutable and not name.startswith("__"): | |
raise AttributeError("this class was set immutable can not set %s, %s" % (name, self)) | |
return object.__setattr__(self, name, value) | |
namespace["__setattr__"] = my_setattr | |
def my_freeze(self): | |
self._immutable = True | |
namespace["freeze"] = my_freeze | |
self = super().__new__(cls, name, bases, namespace) | |
return self |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment