-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding an ImmutableConfigValue class #95
Conversation
@jsiirola Please let me know what you think of this implementation. The idea is that you just set the |
What about this: class ImmutableConfigValue(ConfigValue):
def set_value(self, value):
raise RuntimeError(str(self) + ' is currently immutable.')
class MarkImmutable(object):
def __init__(self, *args):
self._locked = []
try:
for arg in args:
if type(arg) is not ConfigValue:
raise ValueError()
arg.__class__ = ImmutableConfigValue
self._locked.append(arg)
except:
self.release_lock()
def release_lock(self):
for arg in self._locked:
arg.__class__ = ConfigValue
self._locked = [] ...this would allow you to lock configurations that you didn't actually create. With a little more work, we could make it so that the locks are either exclusive (or support nested). |
@jsiirola Good suggestion. |
Codecov Report
@@ Coverage Diff @@
## master #95 +/- ##
==========================================
+ Coverage 63.13% 63.21% +0.08%
==========================================
Files 87 87
Lines 8788 8818 +30
==========================================
+ Hits 5548 5574 +26
- Misses 3240 3244 +4
Continue to review full report at Codecov.
|
Changes proposed in this PR:
This PR adds a class derived from ConfigValue which can be made temporarily immutable by setting the
_mutable
attribute toFalse
.Legal Acknowledgement
By contributing to this software project, I agree to the following terms and conditions for my contribution: