Coverage for gpaw/utilities/debug.py: 12%
8 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-14 00:18 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-14 00:18 +0000
1def frozen(cls):
2 """Make sure attributes do not appear out of nowhere.
4 From:
6 https://stackoverflow.com/questions/3603502/
7 prevent-creating-new-attributes-outside-init
8 """
9 def frozensetattr(self, key, value):
10 import inspect
11 if not hasattr(self, key) and inspect.stack()[1][3] != '__init__':
12 raise AttributeError('Class {} is frozen. Cannot set {}'
13 .format(cls.__name__, key))
14 else:
15 self.__dict__[key] = value
17 cls.__setattr__ = frozensetattr
18 return cls