Closed michaelbynum closed 4 years ago
@jsiirola Please let me know what you think of this implementation. The idea is that you just set the _mutable
flag to False
when you want the config value to be immutable.
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.
Merging #95 into master will increase coverage by
0.08%
. The diff coverage is86.66%
.
@@ 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
Impacted Files | Coverage Δ | |
---|---|---|
pyutilib/misc/config.py | 92.27% <86.66%> (-0.24%) |
:arrow_down: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update ad6043c...9cc57f0. Read the comment docs.
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: