Skip to content
Permalink
Browse files
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!).
  • Loading branch information
The-Compiler committed Jul 4, 2017
1 parent 2c3981e commit e259293
Showing 1 changed file with 4 additions and 1 deletion.
@@ -412,7 +412,10 @@ def get_obj(self, name, *, mutable=True):
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))

0 comments on commit e259293

Please sign in to comment.