Always copy config objects

If we mutate the value we get from the config, we want to make sure the value in
the config always stays the same (especially when it's the default!).
This commit is contained in:
Florian Bruhin 2017-07-03 12:02:52 +02:00
parent 2c3981e57e
commit e259293f83

View File

@ -412,7 +412,10 @@ class Config(QObject):
If mutable=True is set, watch the returned object for mutations.
"""
opt = self.get_opt(name)
obj = self._values.get(name, opt.default)
# We always return a copy of the value stored internally, so the
# internal value can never be changed by mutating the object returned.
obj = copy.deepcopy(self._values.get(name, opt.default))
# Then we watch the returned object for changes.
if isinstance(obj, (dict, list)):
if mutable:
self._mutables.append((name, copy.deepcopy(obj), obj))